void SD_File_Create(void) { ReadBPB(); FormatCard(); FATSystemType(); //MMC/SD卡文件系统类型判断,FAT32_EN==1则为FAT32文件系统 if(FAT32_EN==1) ReadBPB32(); FileCountSearch(); //搜索文件夹及文件数量 DelFile("DATAFILETXT"); //FileCountSearch(); //搜索文件夹及文件数量 if(FAT32_EN==0) { //FAT文件系统下在根目录下创建文件或文件夹,0x10为文件夹,0x20为文件 CreateFile("DATAFILETXT", 0x20); DeBug_Print_Str("create success ..!\r\n"); } else { FAT32CreateFile("DATAFILETXT"); DeBug_Print_Str("create fail ..!\r\n"); } }
bool File::Delete() { if (HandleType!=FILE_HANDLENORMAL || !AllowDelete) return(false); if (hFile!=BAD_HANDLE) Close(); return(DelFile(FileName,FileNameW)); }
int _tmain(int argc, _TCHAR* argv[]) { ::system("pause"); printf("正在卸载PPS...\n"); DelFile(); printf("文件删除成功\n"); DelReg(); printf("注册表清理成功\n"); ::system("pause"); return 0; }
// If NewFile==NULL, we delete created file after user confirmation. // It is useful we we need to overwrite an existing folder or file, // but need user confirmation for that. bool FileCreate(RAROptions *Cmd,File *NewFile,wchar *Name,size_t MaxNameSize, bool *UserReject,int64 FileSize,RarTime *FileTime,bool WriteOnly) { if (UserReject!=NULL) *UserReject=false; #ifdef _WIN_ALL bool ShortNameChanged=false; #endif while (FileExist(Name)) { #ifdef _WIN_ALL if (!ShortNameChanged) { // Avoid the infinite loop if UpdateExistingShortName returns // the same name. ShortNameChanged=true; // Maybe our long name matches the short name of existing file. // Let's check if we can change the short name. if (UpdateExistingShortName(Name)) continue; } // Allow short name check again. It is necessary, because rename and // autorename below can change the name, so we need to check it again. ShortNameChanged=false; #endif UIASKREP_RESULT Choice=uiAskReplaceEx(Cmd,Name,MaxNameSize,FileSize,FileTime,(NewFile==NULL ? UIASKREP_F_NORENAME:0)); if (Choice==UIASKREP_R_REPLACE) break; if (Choice==UIASKREP_R_SKIP) { if (UserReject!=NULL) *UserReject=true; return false; } if (Choice==UIASKREP_R_CANCEL) ErrHandler.Exit(RARX_USERBREAK); } uint FileMode=WriteOnly ? FMF_WRITE|FMF_SHAREREAD:FMF_UPDATE|FMF_SHAREREAD; if (NewFile!=NULL && NewFile->Create(Name,FileMode)) return true; CreatePath(Name,true); return NewFile!=NULL ? NewFile->Create(Name,FileMode):DelFile(Name); }
static bool UnixSymlink(const char *Target,const wchar *LinkName) { CreatePath(LinkName,true); DelFile(LinkName); char LinkNameA[NM]; WideToChar(LinkName,LinkNameA,ASIZE(LinkNameA)); if (symlink(Target,LinkNameA)==-1) // Error. { if (errno==EEXIST) Log(NULL,St(MSymLinkExists),LinkName); else { Log(NULL,St(MErrCreateLnkS),LinkName); ErrHandler.SetErrorCode(RARX_WARNING); } return false; } // We do not set time of created symlink, because utime changes // time of link target and lutimes is not available on all Linux // systems at the moment of writing this code. return true; }
//------------------------------------------------------------ //描述:递归删除非空目录 bool CCommonFunc::DelDir(wchar_t* strDir) { int b = 0; HANDLE hDir = ::CreateFileW(strDir, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); if (INVALID_HANDLE_VALUE == hDir) { return true; } else { WIN32_FIND_DATA FindFileData; HANDLE hFind; wchar_t strSearchPath[256]; SafeWStringPrintf(strSearchPath, _countof(strSearchPath), L"%s*.*", strDir); hFind = ::FindFirstFileW(strSearchPath, (LPWIN32_FIND_DATAW)&FindFileData); do { if (hFind != INVALID_HANDLE_VALUE) { if ((FindFileData.dwFileAttributes &FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) { if (wcscmp(FindFileData.cFileName, L".") == 0 || wcscmp(FindFileData.cFileName, L"..") == 0) { if (FindNextFile(hFind, &FindFileData)) continue; else break; } WIN32_FIND_DATA SubFindFileData; HANDLE hSubFind; wchar_t strSubSearchPath[256]; SafeWStringPrintf(strSubSearchPath, _countof(strSubSearchPath), L"%s%s\\*.*", strDir, FindFileData.cFileName); hSubFind = ::FindFirstFileW(strSubSearchPath, (LPWIN32_FIND_DATAW)&SubFindFileData); SafeWStringPrintf(strSubSearchPath, _countof(strSubSearchPath), L"%s%s\\", strDir, FindFileData.cFileName); //if (hSubFind == INVALID_HANDLE_VALUE) //{ // //::RemoveDirectory(strSubSearchPath); //} //else DelDir(strSubSearchPath); ::FindClose(hSubFind); } else { SafeWStringPrintf(strSearchPath, _countof(strSearchPath), L"%s%s", strDir, FindFileData.cFileName); DelFile(strSearchPath); } } else { break; } } while (FindNextFile(hFind, &FindFileData)); ::FindClose(hFind); ::CloseHandle(hDir); SafeWStringPrintf(strSearchPath, _countof(strSearchPath), L"%s", strDir); ::RemoveDirectory(strSearchPath); b = ::GetLastError(); } return true; }
bool DelFile(const char *Name) { return(DelFile(Name,NULL)); }
bool File::Delete() { return DelFile(FileName); }
bool FileCreate(RAROptions *Cmd,File *NewFile,char *Name,wchar *NameW, OVERWRITE_MODE Mode,bool *UserReject,int64 FileSize, uint FileTime,bool WriteOnly) { if (UserReject!=NULL) *UserReject=false; #if defined(_WIN_ALL) && !defined(_WIN_CE) bool ShortNameChanged=false; #endif while (FileExist(Name,NameW)) { #if defined(_WIN_ALL) && !defined(_WIN_CE) if (!ShortNameChanged) { // Avoid the infinite loop if UpdateExistingShortName returns // the same name. ShortNameChanged=true; // Maybe our long name matches the short name of existing file. // Let's check if we can change the short name. wchar WideName[NM]; GetWideName(Name,NameW,WideName,ASIZE(WideName)); if (UpdateExistingShortName(WideName)) { if (Name!=NULL && *Name!=0) WideToChar(WideName,Name); if (NameW!=NULL && *NameW!=0) wcscpy(NameW,WideName); continue; } } // Allow short name check again. It is necessary, because rename and // autorename below can change the name, so we need to check it again. ShortNameChanged=false; #endif if (Mode==OVERWRITE_NONE) { if (UserReject!=NULL) *UserReject=true; return(false); } // Must be before Cmd->AllYes check or -y switch would override -or. if (Mode==OVERWRITE_AUTORENAME) { if (!GetAutoRenamedName(Name,NameW)) Mode=OVERWRITE_DEFAULT; continue; } #ifdef SILENT Mode=OVERWRITE_ALL; #endif // This check must be after OVERWRITE_AUTORENAME processing or -y switch // would override -or. if (Cmd->AllYes || Mode==OVERWRITE_ALL) break; if (Mode==OVERWRITE_DEFAULT || Mode==OVERWRITE_FORCE_ASK) { char NewName[NM]; wchar NewNameW[NM]; *NewNameW=0; eprintf(St(MFileExists),Name); int Choice=Ask(St(MYesNoAllRenQ)); if (Choice==1) break; if (Choice==2) { if (UserReject!=NULL) *UserReject=true; return(false); } if (Choice==3) { Cmd->Overwrite=OVERWRITE_ALL; break; } if (Choice==4) { if (UserReject!=NULL) *UserReject=true; Cmd->Overwrite=OVERWRITE_NONE; return(false); } if (Choice==5) { #ifndef GUI mprintf(St(MAskNewName)); #ifdef _WIN_ALL File SrcFile; SrcFile.SetHandleType(FILE_HANDLESTD); int Size=SrcFile.Read(NewName,sizeof(NewName)-1); NewName[Size]=0; OemToCharA(NewName,NewName); #else if (fgets(NewName,sizeof(NewName),stdin)==NULL) { // Process fgets failure as if user answered 'No'. if (UserReject!=NULL) *UserReject=true; return(false); } #endif RemoveLF(NewName); #endif if (PointToName(NewName)==NewName) strcpy(PointToName(Name),NewName); else strcpy(Name,NewName); if (NameW!=NULL) { if (PointToName(NewNameW)==NewNameW) wcscpy(PointToName(NameW),NewNameW); else wcscpy(NameW,NewNameW); } continue; } if (Choice==6) ErrHandler.Exit(RARX_USERBREAK); } } uint FileMode=WriteOnly ? FMF_WRITE|FMF_SHAREREAD:FMF_UPDATE|FMF_SHAREREAD; if (NewFile!=NULL && NewFile->Create(Name,NameW,FileMode)) return(true); PrepareToDelete(Name,NameW); CreatePath(Name,NameW,true); return(NewFile!=NULL ? NewFile->Create(Name,NameW,FileMode):DelFile(Name,NameW)); }
main() { static char text[MAXSEARCH]; /* Pointer to buffer for search text */ static char date_time[19]; /* Receive file date and time */ int err, mode, handle, len; /* Codes, file handle, bytes read */ int row, col, ch; /* Cursor coordinates, kb character */ int i, j, attr; /* Index variables, file attribute */ int disp_attr; /* Display attribute */ char *spec, *ptr, *buffer; /* File spec, char match, read buffer */ long dsize, disk_use; /* Disk size and usage */ struct DISKSTAT disk; /* Structure for disk size params */ static char copy_msg[] = { "Files can be copied or moved in 2 different modes:\n" \ " 0 - overwrite target file if it exists\n" \ " 1 - abort if target file exists\n\n" \ "Mode 1 is supported only with DOS versions 3.0 or higher.\n" }; static char move_msg[] = { "Quick Move uses DOS function 56h (Rename File) to effectively " \ "move a file from\none directory to another directory on the " \ "same drive. It copies the entry\nfrom the source directory to " \ "the target directory, but does not physically\ncopy the file.\n\n" \ "Source and target specifications must be given in full, " \ "including filenames,\neven if the names are the same." }; static char grep_msg[] = { "The Find Text option uses the StrFindChar and StrCompare procedures " \ "to locate\na text string within specified files, like Unix's " \ "\"grep\" command. Find Text\nis limited to case-sensitive searches " \ "within the current directory.\n\nEnter the desired search string " \ "without quotation marks. When specifying the\nfilename, use " \ "wildcard characters to expand the search to a group of files --\n" \ "for example, \"*.*\" searches all files within the current " \ "directory, \"*.bat\"\nlimits the search to batch files, and so forth." }; static char attr_msg[] = { "\t\t\t1 normal \n" \ "\t\t\t2 read-only \n" \ "\t\t\t3 hidden \n" \ "\t\t\t4 system \n" \ "\t\t\t volume \n" \ "\t\t\t subdirectory\n" \ "\t\t\t5 archive \n" }; GetVidConfig(); ReadCharAttr( &disp_attr ); clear_scrn( disp_attr, 0, 24 ); SetCurPos( 8, 0 ); puts( "Welcome to the FILEDEMO program.\n\n\nThis program is meant " \ "to encourage experimentation while demonstrating how to\naccess " \ "DOS from assembly-language procedures. As a safety precaution, " \ "however,\nwe suggest you DO NOT experiment with files that " \ "cannot easily be replaced." ); press(); do { /* Display current drive and directory */ clear_scrn( disp_attr, 0, 24 ); SetCurPos( 0, 0 ); printf( "Current Directory: %c:\\", (char)(GetCurDrive() + 'A') ); GetCurDir( source ); puts( source ); /* Display DOS version */ SetCurPos( 1, 0 ); printf( "DOS Version: %2.1f", ( (float) GetVer() ) / 100 ); /* Display disk statistics for current drive */ SetCurPos( 0, 58 ); GetDiskSize( 0, &disk ); dsize = (long)disk.bytes * disk.sects * disk.total; disk_use = (long)(disk.total - disk.avail) * disk.bytes * disk.sects; printf( "Disk Size: %6lu K", dsize / 1024 ); SetCurPos( 1, 58 ); printf( "Disk Use: %6lu K", disk_use / 1024 ); /* Display menu and poll for keystroke */ clear_scrn( disp_attr, 2, 23 ); SetCurPos( 5, 0 ); puts( " \t *** FILE " \ "Demonstration Program ***" ); SetCurPos( 7, 0 ); puts( " \tA List Directory \t\tH Get/Set File Attribute" ); puts( " \tB Copy File \t\tI Get File Date and Time" ); puts( " \tC Move File \t\tJ Rename File" ); puts( " \tD Make Subdirectory \t\tK Delete File" ); puts( " \tE Remove Subdirectory \t\tL Create Unique File" ); puts( " \tF Change Default Drive \t\tM Quick Move" ); puts( " \tG Change Directory \t\tN Find Text" ); printf( "\n\n\tSelect an option, or press ESC to quit: " ); ch = getch(); switch( (ch = toupper( ch )) ) { /* List first 60 files in specified directory */ case 'A': err = list_dir( get_spec( 1 ), disp_attr ); if( !err ) press(); break; /* Copy or Move File according to requested mode: * 0 = overwrite target * 1 = abort if target exists * If Move requested, delete source file after copy. */ case 'B': case 'C': clear_scrn( disp_attr, 2, 17 ); SetCurPos( 9, 0 ); puts( copy_msg ); mode = -1; while( (mode < 0) || (mode > 1) ) { SetCurPos( 16, 0 ); printf( "Enter copy mode: " ); mode = (int)(getche() - '0'); } spec = get_spec( 2 ); /* Get source */ strcpy( source, spec ); /* Save in buffer */ spec = get_spec( 3 ); /* Get target */ err = CopyFile( mode, source, spec ); if( (ch == 'C') && !err ) err = DelFile( source ); break; /* Make Directory */ case 'D': err = MakeDir( get_spec( 1 ) ); break; /* Remove Directory */ case 'E': err = RemoveDir( get_spec( 1 ) ); break; /* Change Default Drive */ case 'F': SetCurPos( 18, 0 ); printf( "Enter new drive letter: " ); ch = getch(); ch = toupper( ch ); ChangeDrive( ch ); err = 0; break; /* Change Directory */ case 'G': err = ChangeDir( get_spec( 1 ) ); break; /* Get and Set File Attributes */ case 'H': strcpy( source, get_spec( 3 ) ); if( (err = GetAttribute( source )) != -1 ) { attr = err; if( !attr ) attr_msg[6] = '*'; else attr_msg[6] = ' '; for( j = 1, i = 27; j <= 32; j <<= 1, i+= 21 ) { attr_msg[i] = ' '; if( attr & j ) attr_msg[i] = '*'; } err = 0; clear_scrn( disp_attr, 2, 17 ); SetCurPos( 7, 0 ); puts( attr_msg ); printf( "\n\nToggle attribute bits by selecting 1-5, " \ "or any other key to exit: " ); mode = (int)( getch() - '0' ); if( (mode > 0) && (mode < 6) ) { switch( --mode ) { case 0: attr = 0; break; case 1: case 2: case 3: attr = attr ^ (1 << (--mode) ); break; case 4: attr = attr ^ 32; } err = SetAttribute( attr, source ); } } break; /* Get File Date and Time */ case 'I': if( (handle = OpenFile( 0, get_spec( 3 ) )) == -1 ) err = 1; else err = 0; if( !err ) { if( !(err = GetFileTime( handle, date_time )) ) { clear_scrn( disp_attr, 2, 17 ); SetCurPos( 12, 10 ); printf( "File's date and time stamp: %s", date_time ); CloseFile( handle ); press(); } } break; /* Rename File */ case 'J': strcpy( source, get_spec( 2 ) ); err = RenameFile( source, get_spec( 3 ) ); break; /* Delete File */ case 'K': err = DelFile( get_spec( 3 ) ); break; /* Create File with Unique Name */ case 'L': strcpy( source, get_spec( 1 ) ); handle = UniqueFile( 0, source ); /* Normal file attr = 0 */ if( handle >= 0 ) { printf( "\n\nDOS creates file %s", source ); press(); err = 0; } else err = 1; break; /* Quick Move from one directory to another */ case 'M': clear_scrn( disp_attr, 2, 17 ); SetCurPos( 8, 0 ); puts( move_msg ); strcpy( source, get_spec( 2 ) ); err = RenameFile( source, get_spec( 3 ) ); break; /* Search files for specified text */ case 'N': clear_scrn( disp_attr, 2, 17 ); buffer = (char *) malloc( BUFFSIZE + 1 ); if( buffer == NULL ) { SetCurPos( 12, 26 ); puts( "Insufficient memory for option" ); err = 1; break; } SetCurPos( 7, 0 ); puts( grep_msg ); SetCurPos( 18, 0 ); printf( "Enter search text: " ); GetStr( text, MAXSEARCH ); /* Find first data file. */ if( err = FindFirst( 0, get_spec( 3 ), &file ) ) { clear_scrn( disp_attr, 2, 17 ); SetCurPos( 12, 24 ); puts( "No files found matching specification" ); } /* If file found, initialize screen coordinates and * open file for reading. */ else { clear_scrn( disp_attr, 2, 17 ); row = 6; col = 0; do { if( (handle = OpenFile( 0, file.filename )) != -1 ) { /* If file opened successfully, read a block * of BUFFSIZE bytes. If end-of-file encountered * (number of bytes read not equal to BUFFSIZE) * or read error, set error flag to break loop. * Terminate block with a NULL character to * make it an ASCIIZ string. */ err = 0; while( !err ) { len = ReadFile( handle, BUFFSIZE, buffer ); if( (len == 0) || (len != BUFFSIZE) ) ++err; ptr = buffer; *( ptr + len ) = 0; /* Search block for first character in text */ while( spec = StrFindChar( text[0], ptr, 0 ) ) { /* If initial character found, compare * remaining characters in search text. * If all characters match, display file * name and break out of loop. */ ptr = StrCompare( ++spec, &text[1], (strlen( text ) - 1) ); if( !ptr ) { SetCurPos( row++, col ); puts( file.filename ); if( row == 16) { row = 6; col += 20; } err = 1; break; } } } CloseFile( handle ); } else { err = 1; break; } } while( !FindNext( &file ) ); if( (row == 6) && (col == 0) ) { SetCurPos( 12, 22 ); puts( "Text not found in specified file(s)" ); } press(); err = 0; } free( buffer ); /* Free allocated block */ break; default: continue; } if( err ) { clear_scrn( disp_attr, 24, 24 ); SetCurPos( 24, 0 ); printf( "*** Error ***\a" ); press(); } } while( ch != ESCAPE ); /* Exit if ESC key pressed */ clear_scrn( disp_attr, 0, 24 ); /* Clear screen before exit */ SetCurPos( 23, 0 ); /* and set cursor to bottom */ return( 0 ); }
bool FileCreate(RAROptions *Cmd,File *NewFile,char *Name,wchar *NameW, OVERWRITE_MODE Mode,bool *UserReject,int64 FileSize, uint FileTime) { if (UserReject!=NULL) *UserReject=false; #if defined(_WIN_32) && !defined(_WIN_CE) bool ShortNameChanged=false; #endif while (FileExist(Name,NameW)) { #if defined(_WIN_32) && !defined(_WIN_CE) if (!ShortNameChanged) { ShortNameChanged=true; if (UpdateExistingShortName(Name,NameW)) continue; } #endif if (Mode==OVERWRITE_NONE) { if (UserReject!=NULL) *UserReject=true; return(false); } #ifdef SILENT Mode=OVERWRITE_ALL; #endif if (Cmd->AllYes || Mode==OVERWRITE_ALL) break; if (Mode==OVERWRITE_DEFAULT || Mode==OVERWRITE_FORCE_ASK) { eprintf(St(MFileExists),Name); int Choice=Ask(St(MYesNoAllRenQ)); if (Choice==1) break; if (Choice==2) { if (UserReject!=NULL) *UserReject=true; return(false); } if (Choice==3) { Cmd->Overwrite=OVERWRITE_ALL; break; } if (Choice==4) { if (UserReject!=NULL) *UserReject=true; Cmd->Overwrite=OVERWRITE_NONE; return(false); } if (Choice==5) { mprintf(St(MAskNewName)); char NewName[NM]; #ifdef _WIN_32 File SrcFile; SrcFile.SetHandleType(FILE_HANDLESTD); int Size=SrcFile.Read(NewName,sizeof(NewName)-1); NewName[Size]=0; OemToChar(NewName,NewName); #else if (fgets(NewName,sizeof(NewName),stdin)==NULL) { // Process fgets failure as if user answered 'No'. if (UserReject!=NULL) *UserReject=true; return(false); } #endif RemoveLF(NewName); if (PointToName(NewName)==NewName) strcpy(PointToName(Name),NewName); else strcpy(Name,NewName); if (NameW!=NULL) *NameW=0; continue; } if (Choice==6) ErrHandler.Exit(USER_BREAK); } if (Mode==OVERWRITE_AUTORENAME) { if (GetAutoRenamedName(Name)) { if (NameW!=NULL) *NameW=0; } else Mode=OVERWRITE_DEFAULT; continue; } } if (NewFile!=NULL && NewFile->Create(Name,NameW)) return(true); PrepareToDelete(Name,NameW); CreatePath(Name,NameW,true); return(NewFile!=NULL ? NewFile->Create(Name,NameW):DelFile(Name,NameW)); }
int main(int argc, char *argv[ ]){ ClearPrints(); chdir(CombineStrings("/home/", GetUser())); DelFile(output_log); DebugLog("--- Begin Android Dev Tools ARGS"); for(tick = 1; tick < argc; tick++) DebugLog(CombineStrings("ARG: ", argv[tick])); DebugLog(""); DebugLog("--- Begin Android Dev Tools"); CmdOut("aDev_adb devices > tmp.txt"); if(IsFileEmpty("tmp.txt")){ ClearPrints(); PrintText("--- Proprietary Files Not Found! ---"); PrintText("Run: \'aDev config\'"); LineSkip(); exit(-1); } DelFile("tmp.txt"); if(argc <= 1){ PrintText("--- Invalid parameters! ---"); PrintText("Run: \'aDev --help\'"); LineSkip(); exit(-1); } for(tick = 1; tick < argc; tick++){ if(IsStringEmpty(argv[tick])) continue; if(CompareStrings(argv[tick], "--help") || CompareStrings(argv[tick], "-h")){ PrintHelp(); exit(0); } if(CompareStrings(argv[tick], "--version") || CompareStrings(argv[tick], "-v")){ PrintVersion(); exit(0); } else if(CompareStrings(argv[tick], "test")){ PrintText("aDev was properly installed, enjoy!"); LineSkip(); exit(0); } else if(CompareStrings(argv[tick], "logcat")){ DevLog(1); exit(0); } else if(CompareStrings(argv[tick], "dmesg")){ DevLog(2); exit(0); } else if(CompareStrings(argv[tick], "kmsg")){ DevLog(3); exit(0); } else if(CompareStrings(argv[tick], "screenshot")){ ScreenShot(); exit(0); } else if(CompareStrings(argv[tick], "info")){ Info(); exit(0); } else if(CompareStrings(argv[tick], "adb")){ text = "aDev_adb "; for(tick2 = 1; tick2 < argc; tick2++) if(!CompareStrings(argv[tick2], "adb")) text = CombineStrings(text, CombineStrings(argv[tick2], " ")); CmdOut(text); exit(0); } else if(CompareStrings(argv[tick], "fastboot")){ text = "aDev_fastboot "; for(tick2 = 1; tick2 < argc; tick2++) if(!CompareStrings(argv[tick2], "fastboot")) text = CombineStrings(text, CombineStrings(argv[tick2], " ")); CmdOut(text); exit(0); } else{ for(tick2 = (argc - 1); tick2 < 0; tick2--){ if(!IsValidArg(argv[tick2])) break; if(tick2 == 1) quit(); } if(IsValidArg(argv[tick2])) tick2--; if(IsValidArg(argv[tick2])) quit(); PrintText(CombineStrings("Unknown Parameter: ", argv[tick2])); quit(); } } return 0; }
bool FileCreate(RAROptions *Cmd,File *NewFile,char *Name,wchar *NameW, OVERWRITE_MODE Mode,bool *UserReject,Int64 FileSize, uint FileTime) { if (UserReject!=NULL) *UserReject=false; while (FileExist(Name,NameW)) { if (Mode==OVERWRITE_NONE) { if (UserReject!=NULL) *UserReject=true; return(false); } #ifdef SILENT Mode=OVERWRITE_ALL; #endif if (Cmd->AllYes || Mode==OVERWRITE_ALL) break; if (Mode==OVERWRITE_ASK) { eprintf(St(MFileExists),Name); int Choice=Ask(St(MYesNoAllRenQ)); if (Choice==1) break; if (Choice==2) { if (UserReject!=NULL) *UserReject=true; return(false); } if (Choice==3) { Cmd->Overwrite=OVERWRITE_ALL; break; } if (Choice==4) { if (UserReject!=NULL) *UserReject=true; Cmd->Overwrite=OVERWRITE_NONE; return(false); } if (Choice==5) { mprintf(St(MAskNewName)); char NewName[NM]; #ifdef _WIN_32 File SrcFile; SrcFile.SetHandleType(FILE_HANDLESTD); int Size=SrcFile.Read(NewName,NM); NewName[Size]=0; OemToChar(NewName,NewName); #else fgets(NewName,sizeof(NewName),stdin); #endif RemoveLF(NewName); if (PointToName(NewName)==NewName) strcpy(PointToName(Name),NewName); else strcpy(Name,NewName); if (NameW!=NULL) *NameW=0; continue; } if (Choice==6) ErrHandler.Exit(USER_BREAK); } } if (NewFile!=NULL && NewFile->Create(Name,NameW)) return(true); PrepareToDelete(Name,NameW); CreatePath(Name,NameW,true); return(NewFile!=NULL ? NewFile->Create(Name,NameW):DelFile(Name,NameW)); }
gboolean delete_file(GtkWidget* widget, GdkEvent* event, gpointer data) { GtkTreeSelection* selection; GtkTreeModel* model;// = m_directory_model; GtkTreeIter iter; char tempstring[STRINGSIZE]; if(CheckCameraOpen()==FALSE) return FALSE; //HTREEITEM hItem = m_directory_tree.GetSelectedItem(); selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(m_directory_tree)); if (gtk_tree_selection_get_selected(selection, &model, &iter)) { // gpointer data = NULL; file_info* p = NULL; // gchar* filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(file_selection_box)); gchar* filename; //char [STRINGSIZE]; // char* storedir = dirpath; //string_combo s_c; gtk_tree_model_get (model, &iter, COL_FILENAME, &filename, COL_POINTER, &data, -1); p = data; if (p) { if(p->filetype!=FIFILE) { MessageBox("Sorry, delete is currently limited to files"); return FALSE; } if(p->partition!=0) { if (MessageBoxConfirm("Do you really want delete a file from a non-movie partition?\r\nThis could easily kill your camera.") == FALSE) return FALSE; } else { strcpy(tempstring, "Do you really want to delete "); if (strlen(tempstring) + strlen(p->filename) + 1 < STRINGSIZE) { strcat(tempstring,p->filename); strcat(tempstring,"?"); } if (MessageBoxConfirm(tempstring) == FALSE) { return FALSE; } if(ChangePartition(p->partition)==FALSE) { return FALSE; } if(ChangeDirectory(p->dirpath)==FALSE) { return FALSE; } EnableControls(FALSE); if(DelFile(p->filename)==FALSE) { Log(ERROR, "Failed to delete %s", p->filename); EnableControls(TRUE); return FALSE; } Log(ERROR, "Deleted %s successfully", p->filename); EnableControls(TRUE); } } } return TRUE; }