From 904307ce5b2e639feede4cb10440d210ce4c91d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Strohh=C3=A4cker?= Date: Wed, 4 Mar 2009 19:34:42 +0000 Subject: [PATCH] add custom fast filesearch routines Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3314 --- include/cross.h | 30 +++++++++++- src/ints/mouse.cpp | 8 ++-- src/misc/cross.cpp | 111 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 141 insertions(+), 8 deletions(-) diff --git a/include/cross.h b/include/cross.h index d92379e4..60473b8e 100644 --- a/include/cross.h +++ b/include/cross.h @@ -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 +#endif + +typedef struct dir_struct { + HANDLE handle; + char base_path[MAX_PATH+4]; + WIN32_FIND_DATA search_data; +} dir_information; + +#else + +#include + +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 diff --git a/src/ints/mouse.cpp b/src/ints/mouse.cpp index 5142143b..2be96182 100644 --- a/src/ints/mouse.cpp +++ b/src/ints/mouse.cpp @@ -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 #include @@ -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.events0) { /* 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(); } diff --git a/src/misc/cross.cpp b/src/misc/cross.cpp index 316e60d3..d45e5b19 100644 --- a/src/misc/cross.cpp +++ b/src/misc/cross.cpp @@ -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 #include #ifdef WIN32 +#ifndef _WIN32_IE #define _WIN32_IE 0x0400 +#endif #include #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_PATHsearch_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_PATHsearch_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_MAXd_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_MAXd_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