From 8fa949ca79f7ee8ba45cc9b92ee240dfcef22d06 Mon Sep 17 00:00:00 2001 From: Martin Fuchs Date: Fri, 8 Oct 2004 18:19:53 +0000 Subject: [PATCH] call Unix functions in separate module read_unix.c svn path=/trunk/; revision=11229 --- reactos/subsys/system/winefile/de.rc | 13 ++ reactos/subsys/system/winefile/en.rc | 13 ++ reactos/subsys/system/winefile/read_unix.c | 92 +++++++++++ reactos/subsys/system/winefile/resource.h | 10 ++ reactos/subsys/system/winefile/winefile.c | 172 +++++++++++--------- reactos/subsys/system/winefile/winefile.dsp | 5 + reactos/subsys/system/winefile/winefile.h | 20 +-- 7 files changed, 229 insertions(+), 96 deletions(-) create mode 100644 reactos/subsys/system/winefile/read_unix.c diff --git a/reactos/subsys/system/winefile/de.rc b/reactos/subsys/system/winefile/de.rc index 79b5f8c26a1..dbcb0ab6cf9 100644 --- a/reactos/subsys/system/winefile/de.rc +++ b/reactos/subsys/system/winefile/de.rc @@ -181,3 +181,16 @@ STRINGTABLE IDS_WINE "WINE" IDS_WINE_FILE "Wine File" } + +STRINGTABLE +{ + IDS_COL_NAME "Name" + IDS_COL_SIZE "Größe" + IDS_COL_CDATE "CDatum" + IDS_COL_ADATE "ZDatum" + IDS_COL_MDATE "ÄDatum" + IDS_COL_IDX "Index/Inode" + IDS_COL_LINKS "Links" + IDS_COL_ATTR "Attribute" + IDS_COL_SEC "Sicherheit" +} diff --git a/reactos/subsys/system/winefile/en.rc b/reactos/subsys/system/winefile/en.rc index aeebe4ae398..29f447b7595 100644 --- a/reactos/subsys/system/winefile/en.rc +++ b/reactos/subsys/system/winefile/en.rc @@ -198,3 +198,16 @@ STRINGTABLE IDS_WINE "WINE" IDS_WINE_FILE "Wine File" } + +STRINGTABLE +{ + IDS_COL_NAME "Name" + IDS_COL_SIZE "Size" + IDS_COL_CDATE "CDate" + IDS_COL_ADATE "ADate" + IDS_COL_MDATE "MDate" + IDS_COL_IDX "Index/Inode" + IDS_COL_LINKS "Links" + IDS_COL_ATTR "Attributes" + IDS_COL_SEC "Security" +} diff --git a/reactos/subsys/system/winefile/read_unix.c b/reactos/subsys/system/winefile/read_unix.c new file mode 100644 index 00000000000..18f0eecb1ea --- /dev/null +++ b/reactos/subsys/system/winefile/read_unix.c @@ -0,0 +1,92 @@ +/* + * Winefile + * + * Copyright 2004 Martin Fuchs + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef __WINE__ + +#include +#include +#include +#include +#include +//#include + + +void call_getcwd(char* buffer, size_t len) +{ + getcwd(buffer, len); +} + + +#ifndef _NO_EXTENSIONS + +/* proxy functions to call UNIX readdir() */ + +void* call_opendir(const char* path) +{ + DIR* pdir = opendir(path); + + return pdir; +} + +int call_readdir(void* pdir, char* name, unsigned* inode) +{ + struct dirent* ent = readdir((DIR*)pdir); + + if (!ent) + return 0; + + strcpy(name, ent->d_name); + *inode = ent->d_ino; + + return 1; +} + +void call_closedir(void* pdir) +{ + closedir((DIR*)pdir); +} + + +/* proxy function to call UNIX stat() */ +int call_stat( + const char* path, int* pis_dir, + unsigned long* psize_low, unsigned long* psize_high, + time_t* patime, time_t* pmtime, + unsigned long* plinks +) +{ + struct stat st; + + if (stat(path, &st)) + return 1; + + *pis_dir = S_ISDIR(st.st_mode); + *psize_low = st.st_size & 0xFFFFFFFF; + *psize_high = 0; /*st.st_size >> 32;*/ + *patime = st.st_atime; + *pmtime = st.st_mtime; + + return 0; +} + +#endif /* _NO_EXTENSIONS */ + +#endif /* __WINE__ */ + diff --git a/reactos/subsys/system/winefile/resource.h b/reactos/subsys/system/winefile/resource.h index 1886c3a05d7..3f56695b261 100644 --- a/reactos/subsys/system/winefile/resource.h +++ b/reactos/subsys/system/winefile/resource.h @@ -90,6 +90,16 @@ #define IDS_WINE 1208 #define IDS_WINE_FILE 1209 +#define IDS_COL_NAME 1210 +#define IDS_COL_SIZE 1211 +#define IDS_COL_CDATE 1212 +#define IDS_COL_ADATE 1213 +#define IDS_COL_MDATE 1214 +#define IDS_COL_IDX 1215 +#define IDS_COL_LINKS 1216 +#define IDS_COL_ATTR 1217 +#define IDS_COL_SEC 1218 + /* range for drive bar command ids: 0x9000..0x90FF */ diff --git a/reactos/subsys/system/winefile/winefile.c b/reactos/subsys/system/winefile/winefile.c index c90bf2cd6a2..3e36eb81263 100644 --- a/reactos/subsys/system/winefile/winefile.c +++ b/reactos/subsys/system/winefile/winefile.c @@ -18,32 +18,15 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifdef __WINE__ -#include "config.h" -#include "wine/port.h" -#endif - #include +#include #define NONAMELESSUNION #include "winefile.h" + #include "resource.h" -/* for read_directory_unix() */ -#if !defined(_NO_EXTENSIONS) && defined(__WINE__) -#include -#include -#ifdef HAVE_UNISTD_H -# include -#endif -#include -#endif - -#ifdef UNICODE -extern int swprintf(wchar_t*, const wchar_t*, ...); -#endif - #ifdef _NO_EXTENSIONS #undef _LEFT_FILES #endif @@ -70,11 +53,6 @@ extern int swprintf(wchar_t*, const wchar_t*, ...); #endif -WINEFILE_GLOBALS Globals; - -extern void WineLicense(HWND hwnd); -extern void WineWarranty(HWND hwnd); - enum ENTRY_TYPE { ET_WINDOWS, ET_UNIX, @@ -173,6 +151,29 @@ typedef struct { } ChildWnd; +extern void WineLicense(HWND hwnd); +extern void WineWarranty(HWND hwnd); + + +#ifdef __WINE__ + +/* functions in read_unix.c */ + +extern void call_getcwd(char* buffer, size_t len); +extern void* call_opendir(const char* path); +extern int call_readdir(void* pdir, char* name, unsigned* pinode); +extern void call_closedir(void* pdir); + +extern int call_stat( + const char* path, int* pis_dir, + unsigned long* psize_low, unsigned long* psize_high, + time_t* patime, time_t* pmtime, + unsigned long* plinks +); + +#endif + + static void read_directory(Entry* dir, LPCTSTR path, SORT_ORDER sortOrder, HWND hwnd); static void set_curdir(ChildWnd* child, Entry* entry, HWND hwnd); static void get_path(Entry* dir, PTSTR path); @@ -182,12 +183,20 @@ LRESULT CALLBACK ChildWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam LRESULT CALLBACK TreeWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam); +/* globals */ +WINEFILE_GLOBALS Globals; + + /* some common string constants */ const static TCHAR sEmpty[] = {'\0'}; const static TCHAR sSpace[] = {' ', '\0'}; const static TCHAR sNumFmt[] = {'%','d','\0'}; const static TCHAR sQMarks[] = {'?','?','?','\0'}; +/* window class names */ +const static TCHAR sWINEFILEFRAME[] = {'W','F','S','_','F','r','a','m','e','\0'}; +const static TCHAR sWINEFILETREE[] = {'W','F','S','_','T','r','e','e','\0'}; + #ifdef _MSC_VER /* #define LONGLONGARG _T("I64") */ const static TCHAR sLongHexFmt[] = {'%','I','6','4','X','\0'}; @@ -432,7 +441,7 @@ static BOOL time_to_filetime(const time_t* t, FILETIME* ftime) stime.wYear = tm->tm_year+1900; stime.wMonth = tm->tm_mon+1; - /* stime.wDayOfWeek */ + /* stime.wDayOfWeek */ stime.wDay = tm->tm_mday; stime.wHour = tm->tm_hour; stime.wMinute = tm->tm_min; @@ -441,11 +450,12 @@ static BOOL time_to_filetime(const time_t* t, FILETIME* ftime) return SystemTimeToFileTime(&stime, ftime); } -static void read_directory_unix(Entry* dir, LPCTSTR path) +void read_directory_unix(Entry* dir, LPCTSTR path) { Entry* first_entry = NULL; Entry* last = NULL; Entry* entry; + void* pdir; #ifdef UNICODE char cpath[MAX_PATH]; @@ -455,14 +465,15 @@ static void read_directory_unix(Entry* dir, LPCTSTR path) const char* cpath = path; #endif - DIR* pdir = opendir(cpath); + pdir = call_opendir(cpath); int level = dir->level + 1; if (pdir) { - struct stat st; - struct dirent* ent; char buffer[MAX_PATH], *p, *s; + time_t atime, mtime; + unsigned inode; + int is_dir; for(p=buffer,s=cpath; *s; ) *p++ = *s++; @@ -470,7 +481,7 @@ static void read_directory_unix(Entry* dir, LPCTSTR path) if (p==buffer || p[-1]!='/') *p++ = '/'; - while((ent=readdir(pdir))) { + while(call_readdir(pdir, p, &inode)) { entry = alloc_entry(); if (!first_entry) @@ -482,31 +493,27 @@ static void read_directory_unix(Entry* dir, LPCTSTR path) entry->etype = ET_UNIX; #ifdef UNICODE - MultiByteToWideChar(CP_UNIXCP, 0, ent->d_name, -1, entry->data.cFileName, MAX_PATH); + MultiByteToWideChar(CP_UNIXCP, 0, p, -1, entry->data.cFileName, MAX_PATH); #else - lstrcpy(entry->data.cFileName, ent->d_name); + lstrcpy(entry->data.cFileName, p); #endif - entry->data.dwFileAttributes = ent->d_name[0]=='.'? FILE_ATTRIBUTE_HIDDEN: 0; + entry->data.dwFileAttributes = p[0]=='.'? FILE_ATTRIBUTE_HIDDEN: 0; - strcpy(p, ent->d_name); - - if (!stat(buffer, &st)) { - if (S_ISDIR(st.st_mode)) + if (!call_stat(buffer, &is_dir, + &entry->data.nFileSizeLow, &entry->data.nFileSizeHigh, + &atime, &mtime, &entry->bhfi.nNumberOfLinks)) + { + if (is_dir) entry->data.dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY; - entry->data.nFileSizeLow = st.st_size & 0xFFFFFFFF; - entry->data.nFileSizeHigh = st.st_size >> 32; - memset(&entry->data.ftCreationTime, 0, sizeof(FILETIME)); - time_to_filetime(&st.st_atime, &entry->data.ftLastAccessTime); - time_to_filetime(&st.st_mtime, &entry->data.ftLastWriteTime); + time_to_filetime(&atime, &entry->data.ftLastAccessTime); + time_to_filetime(&mtime, &entry->data.ftLastWriteTime); - entry->bhfi.nFileIndexLow = ent->d_ino; + entry->bhfi.nFileIndexLow = inode; entry->bhfi.nFileIndexHigh = 0; - entry->bhfi.nNumberOfLinks = st.st_nlink; - entry->bhfi_valid = TRUE; } else { entry->data.nFileSizeLow = 0; @@ -525,7 +532,7 @@ static void read_directory_unix(Entry* dir, LPCTSTR path) last->next = NULL; - closedir(pdir); + call_closedir(pdir); } dir->down = first_entry; @@ -1540,7 +1547,7 @@ static HWND create_child_window(ChildWnd* child) MDICREATESTRUCT mcs; int idx; - mcs.szClass = WINEFILETREE; + mcs.szClass = sWINEFILETREE; mcs.szTitle = (LPTSTR)child->path; mcs.hOwner = Globals.hInstance; mcs.x = child->pos.rcNormalPosition.left; @@ -1985,10 +1992,10 @@ LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam #ifdef UNICODE - getcwd(cpath, MAX_PATH); + call_getcwd(cpath, MAX_PATH); MultiByteToWideChar(CP_UNIXCP, 0, cpath, -1, path, MAX_PATH); #else - getcwd(path, MAX_PATH); + call_getcwd(path, MAX_PATH); #endif child = alloc_child_window(path, NULL, hwnd); @@ -2072,21 +2079,8 @@ LRESULT CALLBACK FrameWndProc(HWND hwnd, UINT nmsg, WPARAM wparam, LPARAM lparam } -static const LPTSTR g_pos_names[COLUMNS] = { - TEXT(""), /* symbol */ - TEXT("Name"), - TEXT("Size"), - TEXT("CDate"), -#ifndef _NO_EXTENSIONS - TEXT("ADate"), - TEXT("MDate"), - TEXT("Index/Inode"), - TEXT("Links"), -#endif /* _NO_EXTENSIONS */ - TEXT("Attributes"), -#ifndef _NO_EXTENSIONS - TEXT("Security") -#endif +static TCHAR g_pos_names[20][COLUMNS] = { + {'\0'} /* symbol */ }; static const int g_pos_align[] = { @@ -2546,28 +2540,28 @@ static void output_number(Pane* pane, LPDRAWITEMSTRUCT dis, int col, LPCTSTR str static int is_exe_file(LPCTSTR ext) { - static const LPCTSTR executable_extensions[] = { - TEXT("COM"), - TEXT("EXE"), - TEXT("BAT"), - TEXT("CMD"), + static const TCHAR executable_extensions[][4] = { + {'C','O','M','\0'}, + {'E','X','E','\0'}, + {'B','A','T','\0'}, + {'C','M','D','\0'}, #ifndef _NO_EXTENSIONS - TEXT("CMM"), - TEXT("BTM"), - TEXT("AWK"), + {'C','M','M','\0'}, + {'B','T','M','\0'}, + {'A','W','K','\0'}, #endif /* _NO_EXTENSIONS */ - 0 + {'\0'} }; TCHAR ext_buffer[_MAX_EXT]; - const LPCTSTR* p; + const TCHAR (*p)[4]; LPCTSTR s; LPTSTR d; for(s=ext+1,d=ext_buffer; (*d=tolower(*s)); s++) d++; - for(p=executable_extensions; *p; p++) + for(p=executable_extensions; (*p)[0]; p++) if (!_tcscmp(ext_buffer, *p)) return 1; @@ -3780,6 +3774,7 @@ static void InitInstance(HINSTANCE hinstance) WNDCLASSEX wcFrame; WNDCLASS wcChild; ATOM hChildClass; + int col; INITCOMMONCONTROLSEX icc = { sizeof(INITCOMMONCONTROLSEX), @@ -3805,7 +3800,7 @@ static void InitInstance(HINSTANCE hinstance) wcFrame.hCursor = LoadCursor(0, IDC_ARROW); wcFrame.hbrBackground = 0; wcFrame.lpszMenuName = 0; - wcFrame.lpszClassName = WINEFILEFRAME; + wcFrame.lpszClassName = sWINEFILEFRAME; wcFrame.hIconSm = (HICON)LoadImage(hinstance, MAKEINTRESOURCE(IDI_WINEFILE), IMAGE_ICON, @@ -3827,7 +3822,7 @@ static void InitInstance(HINSTANCE hinstance) wcChild.hCursor = LoadCursor(0, IDC_ARROW); wcChild.hbrBackground = 0; wcChild.lpszMenuName = 0; - wcChild.lpszClassName = WINEFILETREE; + wcChild.lpszClassName = sWINEFILETREE; hChildClass = RegisterClass(&wcChild); @@ -3844,8 +3839,29 @@ static void InitInstance(HINSTANCE hinstance) CoInitialize(NULL); CoGetMalloc(MEMCTX_TASK, &Globals.iMalloc); SHGetDesktopFolder(&Globals.iDesktop); +#ifdef __WINE__ + Globals.cfStrFName = RegisterClipboardFormatA(CFSTR_FILENAME); +#else Globals.cfStrFName = RegisterClipboardFormat(CFSTR_FILENAME); #endif +#endif + + /* load column strings */ + col = 0; + + load_string(g_pos_names[col++], IDS_COL_NAME); + load_string(g_pos_names[col++], IDS_COL_SIZE); + load_string(g_pos_names[col++], IDS_COL_CDATE); +#ifndef _NO_EXTENSIONS + load_string(g_pos_names[col++], IDS_COL_ADATE); + load_string(g_pos_names[col++], IDS_COL_MDATE); + load_string(g_pos_names[col++], IDS_COL_IDX); + load_string(g_pos_names[col++], IDS_COL_LINKS); +#endif + load_string(g_pos_names[col++], IDS_COL_ATTR); +#ifndef _NO_EXTENSIONS + load_string(g_pos_names[col++], IDS_COL_SEC); +#endif } @@ -4085,7 +4101,7 @@ int APIENTRY WinMain(HINSTANCE hinstance, int cmdshow) { #ifdef _NO_EXTENSIONS - if (find_window_class(WINEFILEFRAME)) + if (find_window_class(sWINEFILEFRAME)) return 1; #endif diff --git a/reactos/subsys/system/winefile/winefile.dsp b/reactos/subsys/system/winefile/winefile.dsp index acb60be3e5d..4aa655905eb 100644 --- a/reactos/subsys/system/winefile/winefile.dsp +++ b/reactos/subsys/system/winefile/winefile.dsp @@ -203,6 +203,11 @@ SOURCE=.\license.h # End Source File # Begin Source File +SOURCE=.\read_unix.c +# PROP Exclude_From_Build 1 +# End Source File +# Begin Source File + SOURCE=.\winefile.c # End Source File # Begin Source File diff --git a/reactos/subsys/system/winefile/winefile.h b/reactos/subsys/system/winefile/winefile.h index f6fa8402176..7bd5160709e 100644 --- a/reactos/subsys/system/winefile/winefile.h +++ b/reactos/subsys/system/winefile/winefile.h @@ -42,7 +42,9 @@ #include #include +#ifdef _MSC_VER #include /* for alloca() */ +#endif #ifndef _NO_EXTENSIONS #define _SHELL_FOLDERS @@ -59,11 +61,6 @@ #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000 #endif -#ifndef BTNS_BUTTON -#define BTNS_BUTTON TBSTYLE_BUTTON -#define BTNS_SEP TBSTYLE_SEP -#endif - #ifdef _DEBUG #define ASSERT(x) {if (!(x)) DebugBreak();} @@ -106,11 +103,6 @@ enum IMAGE { #define COLOR_SPLITBAR LTGRAY_BRUSH #endif -#define WINEFILEFRAME _T("WFS_Frame") -#define WINEFILETREE _T("WFS_Tree") -#define WINEFILEDRIVES _T("WFS_Drives") -#define WINEFILEMDICLIENT _T("WFS_MdiClient") - #define FRM_CALC_CLIENT 0xBF83 #define Frame_CalcFrameClient(hwnd, prt) ((BOOL)SNDMSG(hwnd, FRM_CALC_CLIENT, 0, (LPARAM)(PRECT)prt)) @@ -147,11 +139,3 @@ typedef struct UINT cfStrFName; #endif } WINEFILE_GLOBALS; - -extern WINEFILE_GLOBALS Globals; - -#ifdef UNICODE -extern void _wsplitpath(const WCHAR* path, WCHAR* drv, WCHAR* dir, WCHAR* name, WCHAR* ext); -#else -extern void _splitpath(const CHAR* path, CHAR* drv, CHAR* dir, CHAR* name, CHAR* ext); -#endif