void ListDir(Tree T, int Depth) { if(T){ for(int i = 1; i <= Depth; i++) printf(" "); printf("%c\n", T -> Element); if(T -> Left) ListDir(T -> Left, Depth + 1); if(T -> Right) ListDir(T -> Right, Depth + 1); } }
/*---------------------------------------------------------------------- | NPT_File::GetSize +---------------------------------------------------------------------*/ NPT_Result NPT_File::GetSize(NPT_LargeSize& size) { // default value size = 0; // get the file info NPT_FileInfo info; GetInfo(info); switch (info.m_Type) { case NPT_FileInfo::FILE_TYPE_DIRECTORY: { NPT_List<NPT_String> entries; NPT_CHECK_WARNING(ListDir(entries)); size = entries.GetItemCount(); break; } case NPT_FileInfo::FILE_TYPE_REGULAR: case NPT_FileInfo::FILE_TYPE_OTHER: size = info.m_Size; return NPT_SUCCESS; default: break; } return NPT_SUCCESS; }
bool sprawl::filesystem::RmTree(sprawl::String const& path) { if(!path::IsDirectory(path)) { return Remove(path); } auto dirList = ListDir(path); for(auto& entry : dirList) { entry = path::Join(path, entry); if(path::IsDirectory(entry) && !path::IsLink(entry)) { if(!RmTree(entry)) { return false; } } else { if(!Remove(entry)) { return false; } } } if(!RmDir(path)) { return false; } return true; }
void ResourceListBuilder::BuildResourceList(const std::vector<std::string> &paths, bool checkpak, bool rdisp) { resourcedisp = rdisp; pakparse = checkpak; if (paths.empty()) { // no paths, thus no reslist return; } for(std::vector<std::string>::const_iterator it = paths.begin(); it != paths.end(); ++it) { if (rdisp) { printf("Searching %s for resources:\n", it->c_str()); } else if (verbal) { printf("Searching %s for resources...\n", it->c_str()); } firstdir = true; ListDir(*it, "", true); } printf("\n"); }
// Win 32 DIR parser void ListBuilder::ListDir(const std::string &path) { WIN32_FIND_DATA filedata; // add *.* for searching all files. std::string searchdir = path + "*.*"; // find first file HANDLE filehandle = FindFirstFile(searchdir.c_str(), &filedata); if (filehandle == INVALID_HANDLE_VALUE) { if (firstdir) { if (GetLastError() & ERROR_PATH_NOT_FOUND || GetLastError() & ERROR_FILE_NOT_FOUND) { printf("The directory you specified (%s) can not be found or is empty.\n", path.c_str()); } else { printf("There was an error with the directory you specified (%s) - ERROR NO: %lu.\n", path.c_str(), GetLastError()); } } return; } firstdir = false; do { std::string file = path + filedata.cFileName; // Check for directory if (filedata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // Should we process the directory? if (recursive) { // Look for files in subdir, but ignore . and .. if (strcmp(filedata.cFileName, ".") && strcmp(filedata.cFileName, "..")) { ListDir(file + "\\"); } } } else { // Check if the file is a .bsp if (!CompareStrEndNoCase(file, ".bsp")) { AddFile(file, true); } } } while (FindNextFile(filehandle, &filedata)); // Close search FindClose(filehandle); }
void __fastcall TfrmOpenFTPDialog::tvFolderChange(TObject *Sender, TTreeNode *Node) { AnsiString Path; GetNodePath(Node,Path); if(Path != IdFTP1->RetrieveCurrentDir()) { IdFTP1->ChangeDir(Path); ListDir(Node); } }
/** * * @author OLiver * @author FloSoft */ void dskSelectMap::Msg_OptionGroupChange(const unsigned int /*ctrl_id*/, const unsigned short selection) { ctrlTable* table = GetCtrl<ctrlTable>(1); // Tabelle leeren table->DeleteAllItems(); static const unsigned int ids[] = { 39, 40, 41, 42, 43, 52, 91, 93, 48 }; // Und wieder füllen lassen FillTable(ListDir(GetFilePath(FILE_PATHS[ids[selection]]), "swd")); FillTable(ListDir(GetFilePath(FILE_PATHS[ids[selection]]), "wld")); // Dann noch sortieren bool sortAsc = true; table->SortRows(0, &sortAsc); // und Auswahl zurücksetzen table->SetSelection(0); }
void dskSelectMap::Msg_OptionGroupChange(const unsigned int /*ctrl_id*/, const int selection) { ctrlTable* table = GetCtrl<ctrlTable>(1); // Tabelle leeren table->DeleteAllItems(); // Old, New, Own, Continents, Campaign, RTTR, Other, Sea, Played static const boost::array<unsigned, 9> ids = {{ 39, 40, 41, 42, 43, 52, 91, 93, 48 }}; // Und wieder füllen lassen FillTable(ListDir(GetFilePath(FILE_PATHS[ids[selection]]), "swd")); FillTable(ListDir(GetFilePath(FILE_PATHS[ids[selection]]), "wld")); // Dann noch sortieren bool sortAsc = true; table->SortRows(0, &sortAsc); // und Auswahl zurücksetzen table->SetSelection(0); }
void iwPlayReplay::Msg_MsgBoxResult(const unsigned msgbox_id, const MsgboxResult mbr) { // Sollen alle Replays gelöscht werden? if(mbr == MSR_YES && msgbox_id == 1) { // Dateien löschen std::string tmp = GetFilePath(FILE_PATHS[51]); tmp += "*.rpl"; ListDir(tmp, false, RemoveReplay, 0); // Tabelle leeren GetCtrl<ctrlTable>(0)->DeleteAllItems(); } }
void iwSaveLoad::RefreshTable() { static bool loadedOnce = false; GetCtrl<ctrlTable>(0)->DeleteAllItems(); std::vector<std::string> saveFiles = ListDir(GetFilePath(FILE_PATHS[85]), "sav"); for(std::vector<std::string>::iterator it = saveFiles.begin(); it != saveFiles.end(); ++it) { Savegame save; // Datei öffnen if(!save.Load(*it, false, false)) { // Show errors only first time this is loaded if(!loadedOnce) { LOG.write(_("Invalid Savegame %1%! Reason: %2%\n")) % *it % (save.GetLastErrorMsg().empty() ? _("Unknown") : save.GetLastErrorMsg()); } continue; } // Zeitstring erstellen std::string dateStr = TIME.FormatTime("%d.%m.%Y - %H:%i", &save.save_time); // Dateiname noch rausextrahieren aus dem Pfad bfs::path path = *it; if(!path.has_filename()) continue; bfs::path fileName = path.filename(); // ".sav" am Ende weg RTTR_Assert(fileName.has_extension()); fileName.replace_extension(); std::string fileNameStr = cvWideStringToUTF8(fileName.wstring()); std::string startGF = helpers::toString(save.start_gf); // Und das Zeug zur Tabelle hinzufügen GetCtrl<ctrlTable>(0)->AddRow(0, fileNameStr.c_str(), save.mapName.c_str(), dateStr.c_str(), startGF.c_str(), it->c_str()); } // Nach Zeit Sortieren bool bFalse = false; GetCtrl<ctrlTable>(0)->SortRows(2, &bFalse); loadedOnce = true; }
/** * * @author OLiver * @author FloSoft */ void dskSelectMap::Msg_OptionGroupChange(const unsigned int ctrl_id, const unsigned short selection) { ctrlTable* table = GetCtrl<ctrlTable>(1); // Tabelle leeren table->DeleteAllItems(); static const unsigned int ids[] = { 39, 40, 41, 42, 43, 52, 91, 93, 48 }; char path[4096]; // Und wieder füllen lassen snprintf(path, 4096, "%s*.swd", GetFilePath(FILE_PATHS[ids[selection]]).c_str()); ListDir(path, false, FillTable, (void*)table ); // Nach beiden Kartentypen suchen snprintf(path, 4096, "%s*.wld", GetFilePath(FILE_PATHS[ids[selection]]).c_str()); ListDir(path, false, FillTable, (void*)table ); // Dann noch sortieren table->SortRows(0); // und Auswahl zurücksetzen table->SetSelection(0); }
BOOST_FIXTURE_TEST_CASE(TestListDir, FileOpenFixture) { std::string parentPath = tmpPath.string(); std::vector<std::string> files = ListDir(parentPath, "txt"); BOOST_TEST_REQUIRE(files.size() == 3u); for(const std::string& file : files) { BOOST_REQUIRE(bfs::exists(file)); BOOST_REQUIRE(bfs::path(file).is_absolute()); // Filepath must be utf8 encoded BOOST_REQUIRE(isValidUTF8(file)); bfs::path filePath(file); // String result must still be utf8 BOOST_REQUIRE(isValidUTF8(filePath.string())); // Scopes for auto-close { // path input bnw::ifstream sFile(filePath); BOOST_REQUIRE(sFile); std::string content; BOOST_REQUIRE(sFile >> content); BOOST_TEST_REQUIRE(content == "OK"); } { // string input bnw::ifstream sFile(file); BOOST_REQUIRE(sFile); std::string content; BOOST_REQUIRE(sFile >> content); BOOST_TEST_REQUIRE(content == "OK"); } { // Memory mapped file boost::iostreams::mapped_file_source mmapFile; mmapFile.open(bfs::path(file)); BOOST_TEST_REQUIRE(mmapFile.is_open()); using MMStream = boost::iostreams::stream<boost::iostreams::mapped_file_source>; MMStream map(mmapFile); std::string content; BOOST_REQUIRE(map >> content); BOOST_TEST_REQUIRE(content == "OK"); } } }
/// Updatet die Playlist - Combo void iwMusicPlayer::UpdatePlaylistCombo(const std::string& highlight_entry) { GetCtrl<ctrlComboBox>(2)->DeleteAllItems(); std::list<std::string> segments; ListDir(std::string(FILE_PATHS[90]) + "*.pll", false, NULL, NULL, &segments); unsigned i = 0; for(std::list<std::string>::iterator it = segments.begin(); it != segments.end(); ++it, ++i) { std::string entry = it->substr(it->find_last_of("/") + 1); entry.erase(entry.length() - 4, 4); GetCtrl<ctrlComboBox>(2)->AddString(entry); if(entry == highlight_entry) GetCtrl<ctrlComboBox>(2)->SetSelection(i); } }
void __fastcall TfrmOpenFTPDialog::ToolButton2Click(TObject *Sender) { if(cbxServer->Text == "") { MessageBox(Handle,"请输入服务器地址!","提示",MB_OK | MB_ICONWARNING); cbxServer->SetFocus(); return; } if(IdFTP1->Connected()) IdFTP1->Disconnect(); if(cbxServer->Items->IndexOf(cbxServer->Text) > -1) IdFTP1->Host = frmMain->FTPConfig->GetFTPAttributeValue(cbxServer->Text,"Server"); else IdFTP1->Host = cbxServer->Text; try { IdFTP1->Port = StrToInt(txtPort->Text); } catch(...) { txtPort->Text = "21"; IdFTP1->Port = 21; } Screen->Cursor = crHourGlass; IdFTP1->Username = txtUserName->Text; IdFTP1->Password = txtPassword->Text; IdFTP1->Passive = cbPasv->Checked; try { IdFTP1->Connect(true,1000); } catch(Exception * E) { Screen->Cursor = crDefault; MessageBox(Handle,("连接服务器失败:" + E->Message).c_str(),"错误",MB_OK | MB_ICONSTOP); return; } tvFolder->Items->Clear(); IdFTP1->ChangeDir("/"); //IdFTP1->Quote("pwd /usr/catis/DATA/XiChang25_5ES"); //IdFTP1->Quote("dir"); TTreeNode * RootNode = tvFolder->Items->AddChild(NULL,IdFTP1->RetrieveCurrentDir()); RootNode->ImageIndex = 1; RootNode->SelectedIndex = 2; ListDir(RootNode); }
int main(int argc, char **argv) { int counter = 1; if(argc <= 1 && argc >= 2) { perror("You need to provide one or more source paths and one destination.\n Format: source [...] destination"); exit(1); } while(++counter < argc) { printf("\nListing %s...\n", argv[counter - 1]); ListDir(argv[counter - 1], argv[argc - 1]); } return counter; }
void iwSaveLoad::RefreshTable() { static bool loadedOnce = false; GetCtrl<ctrlTable>(0)->DeleteAllItems(); std::vector<std::string> saveFiles = ListDir(RTTRCONFIG.ExpandPath(FILE_PATHS[85]), "sav"); for(auto& saveFile : saveFiles) { Savegame save; // Datei öffnen if(!save.Load(saveFile, false, false)) { // Show errors only first time this is loaded if(!loadedOnce) { LOG.write(_("Invalid Savegame %1%! Reason: %2%\n")) % saveFile % (save.GetLastErrorMsg().empty() ? _("Unknown") : save.GetLastErrorMsg()); } continue; } // Zeitstring erstellen std::string dateStr = s25util::Time::FormatTime("%d.%m.%Y - %H:%i", save.GetSaveTime()); // Dateiname noch rausextrahieren aus dem Pfad bfs::path path = saveFile; if(!path.has_filename()) continue; // Just filename w/o extension bfs::path fileName = path.stem(); std::string startGF = helpers::toString(save.start_gf); // Und das Zeug zur Tabelle hinzufügen GetCtrl<ctrlTable>(0)->AddRow(0, fileName.string().c_str(), save.GetMapName().c_str(), dateStr.c_str(), startGF.c_str(), saveFile.c_str()); } // Nach Zeit Sortieren bool bFalse = false; GetCtrl<ctrlTable>(0)->SortRows(2, &bFalse); loadedOnce = true; }
int main(int argc,char **argv) { CNTFS::reader::MFT::RecordReader *root; ntfsreader* r; if (argc < 2) { printf("%s <disk image>\n"); return 1; } r = new ntfsreader(argv[1]); if (!r->ok()) return 1; if (!r->init()) return 1; if (!r->mount()) { unsigned char buffy[512]; int i; // look for NTFS partition if (r->blockread(0,1,buffy) == 0) return 1; for (i=0;i < 4;i++) { if (buffy[0x1BE + (i * 0x10) + 4] == 0x07) { r->partition_offset = llei32(buffy + 0x1BE + (i * 0x10) + 8); break; } } if (i >= 4) return 1; if (!r->mount()) return 1; } if (!r->CheckMFT()) return 1; // check and verify the $MFT if (!(root=r->GetRootDir())) return 1; // get the root directory mkdir("__RIPPED__"); if (chdir("__RIPPED__") < 0) return 0; ListDir(root); if (chdir("..") < 0) return 0; r->umount(); r->freeMe(); delete r; return 0; }
bool Avatar::Initialize(const char *pPath, const char *pModel, const char *sdmpath) { pAnimator_ = paAnimatorCreate(); if (pAnimator_ == NULL) return false; pTracker_ = paTrackerCreate(); if (pTracker_ == NULL) { paAnimatorRelease(&pAnimator_); pAnimator_ = NULL; return false; } pEvent_ = paEventCreate(); for (int i = 0; i < 2; ++i) { pQueues_[i] = paEventQueueCreate(4); } if (pModel == NULL) return true; vctstrModels_ = ListDir(pModel); std::string filename = vctstrModels_[iModelIndex_]; pModel_ = paAvatarModelCreate(filename.c_str()); if (pModel_ == NULL) { for (int i = 0; i < 2; ++i) { paEventQueueRelease(&pQueues_[i]); pQueues_[i] = NULL; } paEventRelease(&pEvent_); pEvent_ = NULL; paTrackerRelease(&pTracker_); pTracker_ = NULL; paAnimatorRelease(&pAnimator_); pAnimator_ = NULL; return false; } return true; }
iwPlayReplay::iwPlayReplay(void) : IngameWindow(CGI_PLAYREPLAY, 0xFFFF, 0xFFFF, 600, 300, _("Play Replay"), LOADER.GetImageN("resource", 41)) { ctrlTable* table = AddTable(0, 20, 30, 560, 220, TC_GREEN2, NormalFont, 5, _("Filename"), 300, ctrlTable::SRT_STRING, _("Stocktaking date"), 220, ctrlTable::SRT_DATE, _("Player"), 360, ctrlTable::SRT_STRING, _("Length"), 120, ctrlTable::SRT_NUMBER, "", 0, ctrlTable::SRT_DEFAULT); // Starten AddTextButton(1, 195, 260, 100, 22, TC_GREEN2, _("Start"), NormalFont); // Aufräumen AddTextButton(2, 305, 260, 100, 22, TC_RED1, _("Clear"), NormalFont); // Verzeichnis auflisten std::string tmp = GetFilePath(FILE_PATHS[51]); tmp += "*.rpl"; ListDir(tmp, false, FillReplayTable, table); // Erst einmal nach Dateiname sortieren table->SortRows(0); GAMECLIENT.SetInterface(NULL); }
int main(int argc, char **argv) { DInit(600); argc--; argv++; if (argc == 0) Usage(); switch ((*argv++)[1]) { case 'l': ListDir(*argv); break; case 'c': CheckDir(*argv); break; case 's': SalvageDir(*argv, argv[1]); break; case 'f': CRTest(*argv, argv[1], atoi(argv[2])); break; case 'd': DelTest(*argv, argv[1]); break; case 'r': LookupDir(*argv, argv[1]); break; case 'a': AddEntry(*argv, argv[1]); break; default: Usage(); } exit(0); }
// TODO: implement this for other platforms void FileUtils::CopyRecursive(std::string &dir, std::string &dest, std::string exclude) { if (!IsDirectory(dest)) { CreateDirectory(dest); } #ifdef DEBUG std::cout << "\n>Recursive copy " << dir << " to " << dest << std::endl; #endif std::vector<std::string> files; ListDir(dir, files); for (size_t i = 0; i < files.size(); i++) { std::string& filename = files[i]; if (!exclude.empty() && exclude == filename) continue; std::string srcName = Join(dir.c_str(), filename.c_str(), NULL); std::string destName = Join(dest.c_str(), filename.c_str(), NULL); if (IsDirectory(srcName)) { #ifdef DEBUG std::cout << "create dir: " << destName << std::endl; #endif CreateDirectory(destName); CopyRecursive(srcName, destName); } else { std::wstring wideSrcName = UTILS_NS::UTF8ToWide(srcName); std::wstring wideDestName = UTILS_NS::UTF8ToWide(destName); CopyFileW(wideSrcName.c_str(), wideDestName.c_str(), FALSE); } } }
void ListDir(char * lpPath) { char szFind[MAX_PATH], szFile[MAX_PATH]; WIN32_FIND_DATA FindFileData; strcpy(szFind, lpPath); strcat(szFind, "\\*.*"); HANDLE hFind = ::FindFirstFile(szFind, &FindFileData); if(INVALID_HANDLE_VALUE == hFind) return; while(TRUE) { if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if(FindFileData.cFileName[0] != '.') { strcpy(szFile, lpPath); strcat(szFile, "\\"); strcat(szFile, FindFileData.cFileName); ListDir(szFile); } } else { printf("%s\\%s\n", lpPath, FindFileData.cFileName); strcpy(szFile, lpPath); strcat(szFile, "\\"); strcat(szFile, FindFileData.cFileName); readFile(szFile); } if(!FindNextFile (hFind, &FindFileData) ) break; } }
int WebController::HandleJsonRequest(struct mg_connection *conn, const char *object, const char *func) { json_token *data = NULL; json_token *paramtoken; char *content; int params; int ret; content = strndup(conn->content, conn->content_len); debug("%s",content); free(content); data = parse_json2(conn->content, conn->content_len); if (data == NULL) { debug("parsing api request failed"); return MG_FALSE; } params = 0; paramtoken = find_json_token(data, "params"); if (paramtoken != NULL) { if (paramtoken->type == JSON_TYPE_OBJECT) { params = 1; } else if (paramtoken->type == JSON_TYPE_ARRAY) { params = paramtoken->num_desc; } else { params = 1; } } //Reset global response string gp_response[0] = '\0'; //gp_response = (char*) malloc(sizeof(char) * ( MAX_LINE)); ret = 0; if (!strcmp("kmx", object)) { if (FUNC_SIGP("loadGlobalFile", 2)) { int fileType = -1; char * file = NULL; toki(paramtoken + 1, &fileType); toks(paramtoken + 2, &file, 0); if (file != NULL) { if(strlen(file) > 0){ if(fileType == 1){ this->LoadGcode(file); } else if(fileType == 2){ this->LoadMachineConfiguration(file); } } free(file); } } else if(FUNC_SIGP("listDir", 1)){ ListDir(paramtoken); } else if (FUNC_SIGP("jog", 2)) { int axis; int speed; toki(paramtoken + 1, &axis); toki(paramtoken + 2, &speed); this->Jog(axis, speed); } else if (FUNC_SIGP("onFeedhold", 0)) { this->Feedhold(); } else if (FUNC_SIGP("onSimulate", 0)) { this->Simulate(); } else if (FUNC_SIGP("onEmergencyStop", 0)) { this->EmergencyStop(); } else if (FUNC_SIGP("onHalt", 0)) { this->Halt(); } else if (FUNC_SIGP("onStep", 0)) { this->Step(); } else if (FUNC_SIGP("onReset", 0)) { this->Reset(); } else if (FUNC_SIGP("onCycleStart", 0)) { this->CycleStart(); } else if(FUNC_SIGP("onUpdateMotionParams", 0)) { this->UpdateMotionParams(); } else if (FUNC_SIGP("onInvokeAction", 1)) { BOOL FlushBeforeUnbufferedOperation = FALSE; int action; toki(paramtoken + 1, &action); ret = this->InvokeAction(action,FlushBeforeUnbufferedOperation); } else if (FUNC_SIGP("onDoErrorMessage", 1)) { char *p1 = NULL; toks(paramtoken, &p1, 0); this->DoErrorMessage(p1); EMIT_RESPONSE("[S]", p1); free(p1); } else { log_info("Function request is not part of API %s",func); } } else { log_info("API not implemented %s",object); } mg_send_header(conn, "Content-Type", "application/json"); //Need to send some data or connection will not be closed if (gp_response[0] == '\0') { EMIT_RESPONSE("N"); } mg_printf_data(conn, "%s", gp_response); //free(gp_response); free(data); return MG_TRUE; }
// Win 32 DIR parser void ResourceListBuilder::ListDir(const std::string &path, const std::string &filepath, bool reporterror) { WIN32_FIND_DATA filedata; // add *.* for searching all files. std::string searchdir = path + filepath + "*.*"; // find first file HANDLE filehandle = FindFirstFile(searchdir.c_str(), &filedata); if (filehandle == INVALID_HANDLE_VALUE) { if (firstdir && reporterror) { if (GetLastError() & ERROR_PATH_NOT_FOUND || GetLastError() & ERROR_FILE_NOT_FOUND) { printf("The directory you specified (%s) can not be found or is empty.\n", path.c_str()); } else { printf("There was an error with the directory you specified (%s) - ERROR NO: %lu.\n", path.c_str(), GetLastError()); } } return; } firstdir = false; do { std::string file = filepath + filedata.cFileName; // Check for directory if (filedata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // Look for files in subdir, but ignore . and .. if (strcmp(filedata.cFileName, ".") && strcmp(filedata.cFileName, "..")) { // Call this function recursive ListDir(path, file + PATH_SEPARATOR, reporterror); } } else { const std::string fileLower = strToLowerCopy(file); const size_t dotIndex = fileLower.find_last_of('.'); if(dotIndex != std::string::npos) { const std::string extension = fileLower.substr(dotIndex + 1); if ( extension == "mdl" || extension == "wav" || extension == "spr" || extension == "bmp" || extension == "tga" || extension == "txt" || extension == "wad" ) { // resource, add to list replaceCharAll(file, '\\', '/'); // replace backslashes resources[strToLowerCopy(file)] = file; if (resourcedisp) { printf("Added \"%s\" to resource list\n", file.c_str()); } } if ((extension == "pad") && pakparse) { // get pakfilelist BuildPakResourceList(path + file); } } } } while (FindNextFile(filehandle, &filedata)); // Close search FindClose(filehandle); }
/*---------------------------------------------------------------------- | NPT_File::ListDir +---------------------------------------------------------------------*/ NPT_Result NPT_File::ListDir(NPT_List<NPT_String>& entries) { entries.Clear(); return ListDir(m_Path.GetChars(), entries); }
void ListDir(CNTFS::reader::MFT::RecordReader *root) { CNTFS::reader::MFT::RecordReader::DirectorySearch ds(root); if (indent >= 30) return; indent++; int i; if (ds.Gather()) { if (ds.FindFirst()) { do { if (ds.found_name) ds.found_name->Unicode2Ansi(); // enter subdirectory and enumerate if (ds.found_name->file_attributes & CNTFS::reader::MFT::FILE_ATTR_DUP_FILE_NAME_INDEX_PRESENT) { // avoid reentry problems---don't enter $ROOT again if (ds.MFT_current == 5) continue; for (i=1;i < indent;i++) printf(" "); printf("-----------------------------------------------\n"); for (i=1;i < indent;i++) printf(" "); printf(" CONTENTS OF DIRECTORY %s\n",ds.found_name->name_a); for (i=1;i < indent;i++) printf(" "); printf(" ---------------------------------------------\n"); mkdir(ds.found_name->name_a); if (chdir(ds.found_name->name_a) < 0) continue; // okay, make an object for subdirs CNTFS::reader::MFT::RecordReader sub(root->mom); if (!sub.Parse(ds.MFT_current)) continue; ListDir(&sub); printf("\n"); chdir(".."); } else { for (i=1;i < indent;i++) printf(" "); printf(" %s\n",ds.found_name->name_a); if (ds.found_name->name_a) { CNTFS::reader::MFT::RecordReader sub(root->mom); if (sub.Parse(ds.MFT_current)) { CNTFS::reader::MFT::NTFSFileData filo_basic(&sub); // the base file object CNTFS::reader::MFT::NTFSFileDataCompressed *compressed; // interpreter object for compressed NTFS files CNTFS::reader::MFT::NTFSFileData *filo; // points to either base or through interpreter filo = &filo_basic; compressed=NULL; if (filo->SetupData()) { if (filo->NeedInterpreter()) { // if the file is compressed at filesystem level we will need to // map all read operations through an interpreter object that will // perform on the fly decompression of the compressed data. if (filo->attributes & CNTFS::reader::MFT::ATTR_IS_COMPRESSED) { compressed = new CNTFS::reader::MFT::NTFSFileDataCompressed(filo); if (compressed) { if (compressed->SetupData()) { filo = compressed; } } } } if (filo->seek(0) == 0) { unsigned char buffera[4096]; FILE *fp = fopen(ds.found_name->name_a,"wb"); int br; if (!strcmpi(ds.found_name->name_a,"wword60.doc")) br = br; if (fp) { while ((br=filo->read(buffera,sizeof(buffera))) > 0) fwrite(buffera,br,1,fp); fclose(fp); } } } if (compressed) delete compressed; } } } } while (ds.FindNext()); } } indent--; }
// Linux dir parser void ListBuilder::ListDir(const std::string &path) { struct stat filestatinfo; // Force as a struct for GCC // Open the current dir DIR *directory = opendir(path.c_str()); // Is it open? if (directory == NULL) { // dir cannot be opened if (firstdir) { printf("There was an error with the directory you specified (%s)\nDid you enter the correct directory?\n", path.c_str()); } return; } firstdir = false; // Start going through dirs finding files. while (true) { const dirent * const direntry = readdir(directory); if(direntry == NULL) { break; } // Do we have a dir? std::string file = path + direntry->d_name; int i; if (symlink) { i = stat(file.c_str(), &filestatinfo); // Get the info about the files the links point to } else { i = lstat(file.c_str(), &filestatinfo); // Get the info about the links } if (i == 0) { if (!S_ISLNK(filestatinfo.st_mode) || symlink) { // Check for directory if (S_ISDIR(filestatinfo.st_mode)) { // Should we process the directory? if (recursive) { // Look for files in subdir, but ignore . and .. if (strcmp(direntry->d_name, ".") && strcmp(direntry->d_name, "..")) { ListDir(file + "/"); } } } else { // Check if the file is a .bsp if (!CompareStrEndNoCase(file, ".bsp")) { AddFile(file, true); } } } } } // close the dir closedir(directory); }
void main() { char filepath[MAX_PATH] = ".\\TestDir"; ListDir(filepath); }
void dskSinglePlayer::Msg_ButtonClick(const unsigned int ctrl_id) { switch(ctrl_id) { case 3: // "Letztes Spiel fortsetzen" { std::list<std::string> liste; std::string tmp = GetFilePath(FILE_PATHS[85]); tmp += "*.sav"; ListDir(tmp.c_str(), false, NULL, NULL, &liste); std::string path; unser_time_t recent = 0; for(std::list<std::string>::iterator it = liste.begin(); it != liste.end(); ++it) { Savegame save; // Datei öffnen if (!save.Load(*it, false, false)) continue; if (save.save_time > recent) { recent = save.save_time; path = *it; } } if (recent != 0) { // Dateiname noch rausextrahieren aus dem Pfad size_t pos = path.find_last_of('/'); if(pos == std::string::npos) return; std::string extracted_filename = path.substr(pos + 1); // ".sav" am Ende weg assert(extracted_filename.length() >= 4); extracted_filename.erase(extracted_filename.length() - 4); // Server info CreateServerInfo csi; csi.gamename = extracted_filename; csi.password = "******"; csi.port = 3665; csi.type = NP_LOCAL; csi.ipv6 = false; csi.use_upnp = false; WindowManager::inst().Switch(new dskSelectMap(csi)); if(GAMESERVER.TryToStart(csi, path, MAPTYPE_SAVEGAME)) { WindowManager::inst().Draw(); WindowManager::inst().Show(new iwPleaseWait); } else { WindowManager::inst().Show(new iwMsgbox(_("Error"), _("The specified file couldn't be loaded!"), this, MSB_OK, MSB_EXCLAMATIONRED)); } } else { WindowManager::inst().Show(new iwMsgbox(_("Error"), _("The specified file couldn't be loaded!"), this, MSB_OK, MSB_EXCLAMATIONRED)); } liste.clear(); } break; case 4: // "Replay abspielen" { WindowManager::inst().Show(new iwPlayReplay); } break; case 5: // "Kampagne" { /// @todo Hier dann Auswahl zwischen Kampagne(n) und "Freies Spiel" WindowManager::inst().Show(new iwMsgbox(_("Not available"), _("Please use \'Unlimited Play\' to create a Singleplayer game."), this, MSB_OK, MSB_EXCLAMATIONGREEN)); } break; case 6: // "Freies Spiel" { PrepareSinglePlayerServer(); } break; case 7: // "Spiel laden" { PrepareLoadGame(); } break; case 8: // "Zurück" { WindowManager::inst().Switch(new dskMainMenu); } break; } }
void ListBuilder::BuildList(std::vector<file_s> &srclist) { #ifdef _DEBUG if (srclist.empty()) { printf("P_ERROR (ListBuilder::BuildList): Source list empty.\n"); return; } #endif PrepExList(); // walk entries and take appropritate actions. for (size_t i = 0; i < srclist.size(); i++) { file_s &file = srclist[i]; if (file.folder == false) { // single file processing AddFile(file.name, false); } else { // folder processing // prepare folder name #ifdef _WIN32 if (file.name[file.name.length() - 1] != '\\') { // No ending "\", add file.name += "\\"; } #else if (file.name[file.name.length() - 1] != '/') { // No ending "/", add file.name += "/"; } #endif recursive = file.recursive; if (verbal) { if (recursive) { printf("Searching %s and subdirectories for bsp files...\n", file.name.c_str()); } else { printf("Searching %s for bsp files...\n", file.name.c_str()); } } firstdir = true; ListDir(file.name); } } }