add custom fast filesearch routines
Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3314
This commit is contained in:
parent
8fa4a2d43a
commit
904307ce5b
3 changed files with 141 additions and 8 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2002-2008 The DOSBox Team
|
||||
* Copyright (C) 2002-2009 The DOSBox Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -16,7 +16,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* $Id: cross.h,v 1.19 2009-02-01 14:11:45 qbix79 Exp $ */
|
||||
/* $Id: cross.h,v 1.20 2009-03-04 19:34:42 c2woody Exp $ */
|
||||
|
||||
#ifndef DOSBOX_CROSS_H
|
||||
#define DOSBOX_CROSS_H
|
||||
|
@ -77,4 +77,30 @@ public:
|
|||
};
|
||||
|
||||
|
||||
#if defined (WIN32)
|
||||
|
||||
#if defined (WIN32) /* Win 32 */
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
typedef struct dir_struct {
|
||||
HANDLE handle;
|
||||
char base_path[MAX_PATH+4];
|
||||
WIN32_FIND_DATA search_data;
|
||||
} dir_information;
|
||||
|
||||
#else
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
typedef DIR dir_information;
|
||||
|
||||
#endif
|
||||
|
||||
dir_information* open_directory(const char* dirname);
|
||||
bool read_directory_first(dir_information* dirp, char* entry_name, bool& is_directory);
|
||||
bool read_directory_next(dir_information* dirp, char* entry_name, bool& is_directory);
|
||||
void close_directory(dir_information* dirp);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* $Id: mouse.cpp,v 1.77 2009-02-19 10:52:53 c2woody Exp $ */
|
||||
/* $Id: mouse.cpp,v 1.78 2009-03-04 19:34:42 c2woody Exp $ */
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
@ -188,7 +188,7 @@ Bitu PS2_Handler(void) {
|
|||
#define X_MICKEY 8
|
||||
#define Y_MICKEY 8
|
||||
|
||||
#define MOUSE_MOVED 1
|
||||
#define MOUSE_HAS_MOVED 1
|
||||
#define MOUSE_LEFT_PRESSED 2
|
||||
#define MOUSE_LEFT_RELEASED 4
|
||||
#define MOUSE_RIGHT_PRESSED 8
|
||||
|
@ -200,7 +200,7 @@ INLINE void Mouse_AddEvent(Bit8u type) {
|
|||
if (mouse.events<QUEUE_SIZE) {
|
||||
if (mouse.events>0) {
|
||||
/* Skip duplicate events */
|
||||
if ((type==MOUSE_MOVED) && (mouse.buttons==0)) return;
|
||||
if ((type==MOUSE_HAS_MOVED) && (mouse.buttons==0)) return;
|
||||
/* Always put the newest element in the front as that the events are
|
||||
* handled backwards (prevents doubleclicks while moving)
|
||||
*/
|
||||
|
@ -467,7 +467,7 @@ void Mouse_CursorMoved(float xrel,float yrel,float x,float y,bool emulate) {
|
|||
if (mouse.y > mouse.max_y) mouse.y = mouse.max_y;
|
||||
if (mouse.y < mouse.min_y) mouse.y = mouse.min_y;
|
||||
}
|
||||
Mouse_AddEvent(MOUSE_MOVED);
|
||||
Mouse_AddEvent(MOUSE_HAS_MOVED);
|
||||
DrawCursor();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2002-2008 The DOSBox Team
|
||||
* Copyright (C) 2002-2009 The DOSBox Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -16,15 +16,18 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* $Id: cross.cpp,v 1.3 2009-02-28 14:28:10 qbix79 Exp $ */
|
||||
/* $Id: cross.cpp,v 1.4 2009-03-04 19:34:42 c2woody Exp $ */
|
||||
|
||||
#include "dosbox.h"
|
||||
#include "cross.h"
|
||||
#include "support.h"
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#ifndef _WIN32_IE
|
||||
#define _WIN32_IE 0x0400
|
||||
#endif
|
||||
#include <shlobj.h>
|
||||
#endif
|
||||
|
||||
|
@ -104,3 +107,107 @@ void Cross::CreateDir(std::string const& in) {
|
|||
mkdir(in.c_str(),0700);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined (WIN32)
|
||||
|
||||
dir_information* open_directory(const char* dirname) {
|
||||
if (dirname == NULL) return NULL;
|
||||
|
||||
size_t len = strlen(dirname);
|
||||
if (len == 0) return NULL;
|
||||
|
||||
static dir_information dir;
|
||||
|
||||
safe_strncpy(dir.base_path,dirname,MAX_PATH);
|
||||
|
||||
if (dirname[len-1]=='\\') strcat(dir.base_path,"*.*");
|
||||
else strcat(dir.base_path,"\\*.*");
|
||||
|
||||
dir.handle = INVALID_HANDLE_VALUE;
|
||||
|
||||
return (access(dirname,0) ? NULL : &dir);
|
||||
}
|
||||
|
||||
bool read_directory_first(dir_information* dirp, char* entry_name, bool& is_directory) {
|
||||
dirp->handle = FindFirstFile(dirp->base_path, &dirp->search_data);
|
||||
if (INVALID_HANDLE_VALUE == dirp->handle) {
|
||||
return false;
|
||||
}
|
||||
|
||||
safe_strncpy(entry_name,dirp->search_data.cFileName,(MAX_PATH<CROSS_LEN)?MAX_PATH:CROSS_LEN);
|
||||
|
||||
if (dirp->search_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) is_directory = true;
|
||||
else is_directory = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool read_directory_next(dir_information* dirp, char* entry_name, bool& is_directory) {
|
||||
int result = FindNextFile(dirp->handle, &dirp->search_data);
|
||||
if (result==0) return false;
|
||||
|
||||
safe_strncpy(entry_name,dirp->search_data.cFileName,(MAX_PATH<CROSS_LEN)?MAX_PATH:CROSS_LEN);
|
||||
|
||||
if (dirp->search_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) is_directory = true;
|
||||
else is_directory = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void close_directory(dir_information* dirp) {
|
||||
if (dirp->handle != INVALID_HANDLE_VALUE) {
|
||||
FindClose(dirp->handle);
|
||||
dirp->handle = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include "dirent.h"
|
||||
//#include "stdio.h"
|
||||
|
||||
typedef DIR dir_information;
|
||||
|
||||
dir_information* open_directory(const char* dirname) {
|
||||
return opendir(dirname);
|
||||
}
|
||||
|
||||
bool read_directory_first(dir_information* dirp, char* entry_name, bool& is_directory) {
|
||||
struct dirent* dentry = readdir(dirp);
|
||||
if (dentry==NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// safe_strncpy(entry_name,dentry->d_name,(FILENAME_MAX<MAX_PATH)?FILENAME_MAX:MAX_PATH); // [include stdio.h], maybe pathconf()
|
||||
safe_strncpy(entry_name,dentry->d_name,CROSS_LEN);
|
||||
|
||||
// probably use d_type here instead of a full stat()
|
||||
struct stat status;
|
||||
if (stat(entry_name,&status)==0) is_directory = (S_ISDIR(status.st_mode)>0);
|
||||
else is_directory = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool read_directory_next(dir_information* dirp, char* entry_name, bool& is_directory) {
|
||||
struct dirent* dentry = readdir(dirp);
|
||||
if (dentry==NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// safe_strncpy(entry_name,dentry->d_name,(FILENAME_MAX<MAX_PATH)?FILENAME_MAX:MAX_PATH); // [include stdio.h], maybe pathconf()
|
||||
safe_strncpy(entry_name,dentry->d_name,CROSS_LEN);
|
||||
|
||||
// probably use d_type here instead of a full stat()
|
||||
struct stat status;
|
||||
if (stat(entry_name,&status)==0) is_directory = (S_ISDIR(status.st_mode)>0);
|
||||
else is_directory = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void close_directory(dir_information* dirp) {
|
||||
closedir(dirp);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue