bool SaveGameIterator::RescanSaveGames() { // delete old entries save_slots.clear(); char Path[_MAX_PATH]; PathJoin(Path, core->SavePath, SaveDir(), NULL); DirectoryIterator dir(Path); // create the save game directory at first access if (!dir) { mkdir(Path,S_IWRITE|S_IREAD|S_IEXEC); chmod(Path,S_IWRITE|S_IREAD|S_IEXEC); dir.Rewind(); } if (!dir) { //If we cannot open the Directory return false; } std::set<char*,iless> slots; do { const char *name = dir.GetName(); if (dir.IsDirectory() && IsSaveGameSlot( Path, name )) { slots.insert(strdup(name)); } } while (++dir); for (std::set<char*,iless>::iterator i = slots.begin(); i != slots.end(); i++) { save_slots.push_back(GetSaveGame(*i)); free(*i); } return true; }
Holder<SaveGame> SaveGameIterator::GetSaveGame(const char *slotname) { if (!slotname) { return NULL; } int prtrt = 0; char Path[_MAX_PATH]; //lets leave space for the filenames PathJoin(Path, core->SavePath, SaveDir(), slotname, NULL); char savegameName[_MAX_PATH]={0}; int savegameNumber = 0; int cnt = sscanf( slotname, SAVEGAME_DIRECTORY_MATCHER, &savegameNumber, savegameName ); //maximum pathlength == 240, without 8+3 filenames if ( (cnt != 2) || (strlen(Path)>240) ) { printf( "Invalid savegame directory '%s' in %s.\n", slotname, Path ); return NULL; } DirectoryIterator dir(Path); if (!dir) { return NULL; } do { if (strnicmp( dir.GetName(), "PORTRT", 6 ) == 0) prtrt++; } while (++dir); SaveGame* sg = new SaveGame( Path, savegameName, core->GameNameResRef, slotname, prtrt, savegameNumber ); return sg; }
static void CreateSavePath(char *Path, int index, const char *slotname) { PathJoin( Path, core->SavePath, SaveDir(), NULL ); //if the path exists in different case, don't make it again mkdir(Path,S_IWRITE|S_IREAD|S_IEXEC); chmod(Path,S_IWRITE|S_IREAD|S_IEXEC); //keep the first part we already determined existing char dir[_MAX_PATH]; snprintf( dir, _MAX_PATH, "%09d-%s", index, slotname ); PathJoin(Path, Path, dir, NULL); //this is required in case the old slot wasn't recognised but still there core->DelTree(Path, false); mkdir(Path,S_IWRITE|S_IREAD|S_IEXEC); chmod(Path,S_IWRITE|S_IREAD|S_IEXEC); }
void DocDir::RemoveOtherKey(const DocKey& key, int t1, int t2) { dword hv = GetHashValue(key); for(int i = 0; i < dir.GetCount(); i++) { int q = dir[i].Find(key, hv); if(q >= 0) { Entry& e = dir[i][q]; if(e.type != t1 && e.type != t2) { if(e.type == NORMAL || e.type == EXTERNAL) DeleteFile(DocFile(dir.GetKey(i), dir[i][q].text)); dir[i].Remove(q); } SaveDir(dir.GetKey(i)); SaveLinks(dir.GetKey(i)); } } }
void DocDir::RebuildDir(const String& package) { FindFile ff(DocFile(package, "*.dpp")); Progress pi("Rebuilding " + package + " doc directory %d"); ArrayMap<DocKey, Entry>& p = dir.GetAdd(package); p.Clear(); LoadLinks(package); while(ff) { DocKey key; pi.Step(); int q = ReadDocHeader(DocFile(package, ff.GetName()), key); if(q >= 0) { Entry& w = p.GetAdd(key); w.text = ff.GetName(); w.type = q; } ff.Next(); } SaveDir(package); }
static bool CreateSavePath(char *Path, int index, const char *slotname) { PathJoin( Path, core->SavePath, SaveDir(), NULL ); //if the path exists in different case, don't make it again if (!MakeDirectory(Path)) { printMessage("SaveGameIterator", "Unable to create save game directory '%s'\n", RED, Path); return false; } //keep the first part we already determined existing char dir[_MAX_PATH]; snprintf( dir, _MAX_PATH, "%09d-%s", index, slotname ); PathJoin(Path, Path, dir, NULL); //this is required in case the old slot wasn't recognised but still there core->DelTree(Path, false); if (!MakeDirectory(Path)) { printMessage("SaveGameIterator", "Unable to create save game directory '%s'\n", RED, Path); return false; } return true; }
void DocDir::SaveText(const String& package, const DocKey& k, const String& text, bool external) { RemoveOtherKey(k, NORMAL, EXTERNAL); CreateDocDir(package); String fn = DocFile(package, GetAddFileName(package, k, external ? EXTERNAL : NORMAL)); FileOut out(fn); out << "ITEM(" << AsCode(k) << ")"; if(external) out << " EXTERNAL"; out << "\r\n"; int n = 0; for(;;) { int m = min(text.GetLength() - n, 2048); if(m == 0) break; out << "TEXT(\r\n\t"; out << AsCString(~text + n, ~text + n + m, 64, "\t") << "\r\n"; out << ")\r\n"; n += m; } out << "END_ITEM\r\n"; SaveDir(package); SaveLinks(package); }
bool SaveGameIterator::RescanSaveGames() { // delete old entries save_slots.clear(); char Path[_MAX_PATH]; PathJoin(Path, core->SavePath, SaveDir(), NULL); DirectoryIterator dir(Path); // create the save game directory at first access if (!dir) { if (!MakeDirectory(Path)) { printMessage("SaveGameIterator", "Unable to create save game directory '%s'\n", RED, Path); return false; } dir.Rewind(); } if (!dir) { //If we cannot open the Directory return false; } std::set<char*,iless> slots; do { const char *name = dir.GetName(); if (dir.IsDirectory() && IsSaveGameSlot( Path, name )) { slots.insert(strdup(name)); } } while (++dir); for (std::set<char*,iless>::iterator i = slots.begin(); i != slots.end(); i++) { save_slots.push_back(BuildSaveGame(*i)); free(*i); } return true; }