C4PortraitSelDlg::C4PortraitSelDlg(C4FileSel_BaseCB *pSelCallback, bool fSetPicture, bool fSetBigIcon) : C4FileSelDlg(Config.General.ExePath, FormatString(LoadResStr("IDS_MSG_SELECT"), LoadResStr("IDS_TYPE_PORTRAIT")).getData(), pSelCallback, false), pCheckSetPicture(NULL), pCheckSetBigIcon(NULL), fDefSetPicture(fSetPicture), fDefSetBigIcon(fSetBigIcon) { char path[_MAX_PATH + 1]; // add common picture locations StdStrBuf strLocation; SCopy(Config.AtUserPath(""), path, _MAX_PATH); TruncateBackslash(path); strLocation.Format("%s %s", C4ENGINECAPTION, LoadResStr("IDS_TEXT_USERPATH")); AddLocation(strLocation.getData(), path); SCopy(Config.AtExePath(""), path, _MAX_PATH); TruncateBackslash(path); strLocation.Format("%s %s", C4ENGINECAPTION, LoadResStr("IDS_TEXT_PROGRAMDIRECTORY")); AddCheckedLocation(strLocation.getData(), Config.General.ExePath); #ifdef _WIN32 if (SHGetSpecialFolderPath(NULL, path, CSIDL_PERSONAL, FALSE)) AddCheckedLocation(LoadResStr("IDS_TEXT_MYDOCUMENTS"), path); if (SHGetSpecialFolderPath(NULL, path, CSIDL_MYPICTURES, FALSE)) AddCheckedLocation(LoadResStr("IDS_TEXT_MYPICTURES"), path); if (SHGetSpecialFolderPath(NULL, path, CSIDL_DESKTOPDIRECTORY, FALSE)) AddCheckedLocation(LoadResStr("IDS_TEXT_DESKTOP"), path); #endif #ifdef __APPLE__ AddCheckedLocation(LoadResStr("IDS_TEXT_HOME"), getenv("HOME")); #else AddCheckedLocation(LoadResStr("IDS_TEXT_HOMEFOLDER"), getenv("HOME")); #endif #ifndef _WIN32 sprintf(path, "%s%c%s", getenv("HOME"), (char)DirectorySeparator, (const char *)"Desktop"); AddCheckedLocation(LoadResStr("IDS_TEXT_DESKTOP"), path); #endif // build dialog InitElements(); // select last location SetCurrentLocation(Config.Startup.LastPortraitFolderIdx, false); }
bool C4Network2Res::SetByCore(const C4Network2ResCore &nCore, bool fSilent, const char *szAsFilename, int32_t iRecursion) // by main thread { StdStrBuf sFilename; // try open local file const char *szFilename = szAsFilename ? szAsFilename : GetC4Filename(nCore.getFileName()); if (SetByFile(szFilename, false, nCore.getType(), nCore.getID(), nCore.getFileName(), fSilent)) { // check contents checksum if (Core.getContentsCRC() == nCore.getContentsCRC()) { // set core fDirty = true; Core = nCore; // ok then return true; } } // get and search for filename without specified folder (e.g., Castle.ocs when the opened game is Easy.ocf\Castle.ocs) const char *szFilenameOnly = GetFilename(szFilename); const char *szFilenameC4 = GetC4Filename(szFilename); if (szFilenameOnly != szFilenameC4) { sFilename.Copy(szFilename, SLen(szFilename) - SLen(szFilenameC4)); sFilename.Append(szFilenameOnly); if (SetByCore(nCore, fSilent, szFilenameOnly, Config.Network.MaxResSearchRecursion)) return true; } // if it could still not be set, try within all folders of root (ignoring special folders), and try as file outside the folder // but do not recurse any deeper than set by config (default: One folder) if (iRecursion >= Config.Network.MaxResSearchRecursion) return false; StdStrBuf sSearchPath; const char *szSearchPath; if (!iRecursion) szSearchPath = Config.General.ExePath.getData(); else { sSearchPath.Copy(szFilename, SLen(szFilename) - SLen(szFilenameC4)); szSearchPath = sSearchPath.getData(); } StdStrBuf sNetPath; sNetPath.Copy(Config.Network.WorkPath); char *szNetPath = sNetPath.GrabPointer(); TruncateBackslash(szNetPath); sNetPath.Take(szNetPath); for (DirectoryIterator i(szSearchPath); *i; ++i) if (DirectoryExists(*i)) if (!*GetExtension(*i)) // directories without extension only if (!szNetPath || !*szNetPath || !ItemIdentical(*i, szNetPath)) // ignore network path { // search for complete name at subpath (e.g. MyFolder\Easy.ocf\Castle.ocs) sFilename.Format("%s%c%s", *i, DirectorySeparator, szFilenameC4); if (SetByCore(nCore, fSilent, sFilename.getData(), iRecursion + 1)) return true; } // file could not be found locally return false; }
bool C4Network2ResList::CreateNetworkFolder() { // get network path without trailing backslash char szNetworkPath[_MAX_PATH+1]; SCopy(Config.AtNetworkPath(""), szNetworkPath, _MAX_PATH); TruncateBackslash(szNetworkPath); // but make sure that the configured path has one AppendBackslash(Config.Network.WorkPath); // does not exist? if (!DirectoryExists(szNetworkPath)) { if (!CreatePath(szNetworkPath)) { LogFatal("Network: could not create network path!"); return false; } return true; } return true; }