int main(int argc, char *argv[]) { ParseArguments(argc, argv);//incorrect arguments? print help & exit. Also, fill in SourceDirectoryName and DestinationDirectoryName; process flags. Vprintf("OddBackup, version %s.\nBackup '%s' to '%s'.\n", VERSION, SourceDirectoryName, DestinationDirectoryName); switch (Suspicion) { case 1: Vprintf("All attempts of shell-injections will be eliminated!\n");break; case 0: Vprintf("You'll be asked about fixing suspicious filenames.\n");break; case -1: Vprintf("You won't be disturbed with suspicious filenames. Enjoy your day!\n");break; } struct dirent * DirectoryEntryPointer; DIR * ProcessingDirPointer; PushDir(SourceDirectoryName); while (ProcessingDirectoryName = PopDir()) { if (DotsCheck(ProcessingDirectoryName))//eliminate "." and ".." entries { continue; } if (!TryDirectory(ProcessingDirectoryName)) { printf("Can't backup %s.\n", ProcessingDirectoryName); continue; } Dprintf("Processing %s\n", ProcessingDirectoryName); Vprintf("Entering %s\n", ProcessingDirectoryName); ProcessingDirPointer = opendir(ProcessingDirectoryName); CATCH_ERROR("Can't open directory"); while ((DirectoryEntryPointer = readdir(ProcessingDirPointer)) != NULL) { switch(DirectoryEntryPointer->d_type) { case DT_DIR : PushDir(AbsoluteSourceName(DirectoryEntryPointer->d_name)); break;//it's a directory - will be processed too case DT_REG : if (IsToBeBackuped(DirectoryEntryPointer->d_name))//it's a file { BackupAndGzip(DirectoryEntryPointer->d_name); }; break; default : printf("%s is neither file nor directory - can't backup.\n", DirectoryEntryPointer->d_name); } } Vprintf("Leaving %s\n", ProcessingDirectoryName); closedir(ProcessingDirPointer); free(ProcessingDirectoryName); } return 0; }
CLocalPath COptions::GetUnadjustedSettingsDir() { CLocalPath ret; #ifdef FZ_WINDOWS wchar_t buffer[MAX_PATH * 2 + 1]; if (SUCCEEDED(SHGetFolderPath(0, CSIDL_APPDATA, 0, SHGFP_TYPE_CURRENT, buffer))) { CLocalPath tmp(buffer); if (!tmp.empty()) { tmp.AddSegment(L"FileZilla"); } ret = tmp; } else { // Fall back to directory where the executable is DWORD c = GetModuleFileName(0, buffer, MAX_PATH * 2); if (c && c < MAX_PATH * 2) { std::wstring tmp; ret.SetPath(buffer, &tmp); } } #else std::wstring cfg = TryDirectory(GetEnv(_T("XDG_CONFIG_HOME")), _T("filezilla/"), true); if (cfg.empty()) { cfg = TryDirectory(wxGetHomeDir(), _T(".config/filezilla/"), true); } if (cfg.empty()) { cfg = TryDirectory(wxGetHomeDir(), _T(".filezilla/"), true); } if (cfg.empty()) { cfg = TryDirectory(GetEnv(_T("XDG_CONFIG_HOME")), _T("filezilla/"), false); } if (cfg.empty()) { cfg = TryDirectory(wxGetHomeDir(), _T(".config/filezilla/"), false); } if (cfg.empty()) { cfg = TryDirectory(wxGetHomeDir(), _T(".filezilla/"), false); } ret.SetPath(cfg); #endif return ret; }
CLocalPath COptions::GetUnadjustedSettingsDir() { wxFileName fn; #ifdef __WXMSW__ wxChar buffer[MAX_PATH * 2 + 1]; if (SUCCEEDED(SHGetFolderPath(0, CSIDL_APPDATA, 0, SHGFP_TYPE_CURRENT, buffer))) { fn = wxFileName(buffer, _T("")); fn.AppendDir(_T("FileZilla")); } else { // Fall back to directory where the executable is if (GetModuleFileName(0, buffer, MAX_PATH * 2)) fn = buffer; } #else wxString cfg = TryDirectory(GetEnv(_T("XDG_CONFIG_HOME")), _T("filezilla/"), true); if( cfg.empty() ) { cfg = TryDirectory(wxGetHomeDir(), _T(".config/filezilla/"), true); } if( cfg.empty() ) { cfg = TryDirectory(wxGetHomeDir(), _T(".filezilla/"), true); } if( cfg.empty() ) { cfg = TryDirectory(GetEnv(_T("XDG_CONFIG_HOME")), _T("filezilla/"), false); } if( cfg.empty() ) { cfg = TryDirectory(wxGetHomeDir(), _T(".config/filezilla/"), false); } if( cfg.empty() ) { cfg = TryDirectory(wxGetHomeDir(), _T(".filezilla/"), false); } fn = wxFileName(cfg, _T("")); #endif return CLocalPath(fn.GetPath()); }