// version 1.1 #include #include #include "Clean.h" // error codes: #define NoDirError 0 #define OtherDirError -1 #define DoesntExist -2 #define BadName -3 #define NotEnoughSpace -4 #define AlreadyExists -5 #define NoPermission -6 #define MoveIntoOffspring -7 #define MoveAcrossDisks -8 #define NotYetRemovable -9 HANDLE ghSearch; WIN32_FIND_DATA gWFD; static int pc_error_to_clean_error(int pc_error) { switch(pc_error) { case ERROR_SUCCESS: return NoDirError; case ERROR_FILE_NOT_FOUND: case ERROR_INVALID_DRIVE: case ERROR_PATH_NOT_FOUND: case ERROR_BAD_NET_NAME: return DoesntExist; case ERROR_BAD_PATHNAME: case ERROR_INVALID_NAME: return BadName; case ERROR_DISK_FULL: case ERROR_HANDLE_DISK_FULL: return NotEnoughSpace; case ERROR_ALREADY_EXISTS: case ERROR_FILE_EXISTS: return AlreadyExists; case ERROR_DRIVE_LOCKED: case ERROR_SHARING_VIOLATION: case ERROR_ACCESS_DENIED: case ERROR_WRITE_PROTECT: case ERROR_LOCK_VIOLATION: return NoPermission; case ERROR_DIR_NOT_EMPTY: return NotYetRemovable; default: return OtherDirError; }; } // unhandled: NotADirectory, MoveIntoOffspring int findFirstFileC(CleanString cs_path) { char *cPath; int length,i,clean_err; ghSearch = INVALID_HANDLE_VALUE; length = CleanStringLength(cs_path); if (CleanStringCharacters(cs_path)[length-1]=='\\') length--; cPath = GlobalAlloc(LMEM_FIXED, length+3); // +3 for adding "\\*\0" if (!cPath) return -1; else { // make a C string with "\\*" appended for(i=0; iCleanStringLength(cs)) return STRING_TOO_SMALL; else { CleanStringLength(cs) = neededSize; return OK; }; }; } int setCurrentDirectoryC(CleanString csPath) { int ok; ok = SetCurrentDirectory(CleanStringCharacters(csPath)); return ok ? NoDirError : pc_error_to_clean_error(GetLastError()); } void get_mac_dir_parent_and_name_C() {} int getPlatformIdC(int dummy) { #define WindowsPlatform 1 return WindowsPlatform; } void getMacDiskNameC() {} int get_windows_disk_available_bits_C(int dummy) { return GetLogicalDrives(); } int fmoveC(int overwrite, CleanString from, CleanString to) { int ok, last_error; ok = MoveFile(CleanStringCharacters(from), CleanStringCharacters(to)); if (!ok && overwrite && GetLastError()==ERROR_ALREADY_EXISTS) { if (!DeleteFile(CleanStringCharacters(to))) return AlreadyExists; else ok = MoveFile(CleanStringCharacters(from), CleanStringCharacters(to)); }; if (ok) return NoDirError; else { last_error = GetLastError(); return last_error==ERROR_ACCESS_DENIED ? MoveIntoOffspring : pc_error_to_clean_error(last_error); }; } void macMoveC() {} void macRenameC() {}