void Instance::LoadModList() { if (GetModListFile().FileExists()) { wxFileInputStream inputStream(GetModListFile().GetFullPath()); wxStringList modListFile = ReadAllLines(inputStream); for (wxStringList::iterator iter = modListFile.begin(); iter != modListFile.end(); iter++) { // Normalize the path to the instMods dir. wxFileName modFile(*iter); modFile.Normalize(wxPATH_NORM_ALL, GetInstModsDir().GetFullPath()); modFile.MakeRelativeTo(); if (!Any(modList.begin(), modList.end(), [&modFile] (Mod mod) -> bool { return mod.GetFileName().SameAs(wxFileName(modFile)); })) { //SetNeedsRebuild(); modList.push_back(Mod(modFile)); } } } for (size_t i = 0; i < modList.size(); i++) { if (!modList[i].GetFileName().FileExists()) { SetNeedsRebuild(); modList.erase(modList.begin() + i); i--; } } LoadModListFromDir(GetInstModsDir()); }
// Makes ALL the directories! \o/ void Instance::MkDirs() { if (!GetRootDir().DirExists()) GetRootDir().Mkdir(); if (!GetMCDir().DirExists()) GetMCDir().Mkdir(); if (!GetBinDir().DirExists()) GetBinDir().Mkdir(); if (!GetSavesDir().DirExists()) GetSavesDir().Mkdir(); if (!GetMLModsDir().DirExists()) GetMLModsDir().Mkdir(); if (!GetCoreModsDir().DirExists()) GetCoreModsDir().Mkdir(); if (!GetResourceDir().DirExists()) GetResourceDir().Mkdir(); if (!GetScreenshotsDir().DirExists()) GetScreenshotsDir().Mkdir(); if (!GetTexturePacksDir().DirExists()) GetTexturePacksDir().Mkdir(); if (!GetInstModsDir().DirExists()) GetInstModsDir().Mkdir(); }
void Instance::InsertMod(size_t index, const wxFileName &source) { wxFileName dest(Path::Combine(GetInstModsDir().GetFullPath(), source.GetFullName())); if (!source.SameAs(dest)) { wxCopyFile(source.GetFullPath(), dest.GetFullPath()); } dest.MakeRelativeTo(); SetNeedsRebuild(); int oldIndex = Find(modList.begin(), modList.end(), [&dest] (Mod mod) -> bool { return mod.GetFileName().SameAs(dest); }); if (oldIndex != -1) { modList.erase(modList.begin() + oldIndex); } if (index >= modList.size()) modList.push_back(Mod(dest)); else modList.insert(modList.begin() + index, Mod(dest)); SaveModList(); }
Instance::Instance(const wxString &rootDir) : modList(this), m_running(false) { if (!rootDir.EndsWith("/")) this->rootDir = wxFileName::DirName(rootDir + "/"); else this->rootDir = wxFileName::DirName(rootDir); config = new wxFileConfig(wxEmptyString, wxEmptyString, GetConfigPath().GetFullPath(), wxEmptyString, wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_RELATIVE_PATH); evtHandler = NULL; MkDirs(); // initialize empty mod lists - they are filled later and only if requested (see apropriate Get* methods) modList.SetDir(GetInstModsDir().GetFullPath()); mlModList.SetDir(GetMLModsDir().GetFullPath()); coreModList.SetDir(GetCoreModsDir().GetFullPath()); worldList.SetDir(GetSavesDir().GetFullPath()); tpList.SetDir(GetTexturePacksDir().GetFullPath()); modloader_list_inited = false; coremod_list_inited = false; jar_list_inited = false; world_list_initialized = false; tp_list_initialized = false; parentModel = nullptr; UpdateVersion(); }
void Instance::SaveModList() { wxString text; for (ModIterator iter = modList.begin(); iter != modList.end(); iter++) { wxFileName modFile = iter->GetFileName(); modFile.MakeRelativeTo(GetInstModsDir().GetFullPath()); text.Append(modFile.GetFullPath()); text.Append(_("\n")); } wxFile outFile(GetModListFile().GetFullPath(), wxFile::write); wxFileOutputStream out(outFile); WriteAllText(out, text); }