TiXmlElement *COptions::GetXML() { simple_lock lock(m_mutex); USES_CONVERSION; CStdString xmlFileName = GetExecutableDirectory() + _T("FileZilla Server.xml"); char* bufferA = T2A(xmlFileName); if (!bufferA) { return 0; } TiXmlDocument *pDocument = new TiXmlDocument; if (!pDocument->LoadFile(bufferA)) { delete pDocument; return NULL; } TiXmlElement* pElement = pDocument->FirstChildElement("FileZillaServer"); if (!pElement) { delete pDocument; return NULL; } // Must call FreeXML m_mutex.lock(); return pElement; }
json_value* GetApplicationSettings() { static json_value* ret = new json_value(); static bool settings_fetched = false; if (settings_fetched) return ret; settings_fetched = true; LOG_DEBUG << "Fetching settings from settings.json file"; std::string settingsFile = GetExecutableDirectory() + "\\settings.json"; std::string contents = GetFileContents(settingsFile); if (contents.empty()) { LOG_WARNING << "Error opening settings.json file"; return ret; } json_settings settings; memset(&settings, 0, sizeof(json_settings)); char error[256]; json_value* json_parsed = json_parse_ex(&settings, contents.c_str(), &error[0]); if (json_parsed == 0) { LOG_WARNING << "Error while parsing settings.json file: " << error; return ret; } ret = json_parsed; return ret; }
BOOL COptions::FreeXML(TiXmlElement *pXML, bool save) { ASSERT(pXML); if (!pXML) return FALSE; simple_lock lock(m_mutex); // As locked by GetXML m_mutex.unlock(); if (!save) { delete pXML->GetDocument(); return FALSE; } USES_CONVERSION; CStdString xmlFileName = GetExecutableDirectory() + _T("FileZilla Server.xml"); char* bufferA = T2A(xmlFileName); if (!bufferA) { delete pXML->GetDocument(); return FALSE; } if (!pXML->GetDocument()->SaveFile(bufferA)) { delete pXML->GetDocument(); return FALSE; } delete pXML->GetDocument(); return TRUE; }
std::string GetAbsolutePath(std::string path) { if (path.length() && path.find(":") == std::string::npos) { path = GetExecutableDirectory() + "\\" + path; path = GetRealPath(path); } return path; }
ff::String ff::GetCurrentDirectory() { #if METRO_APP return GetExecutableDirectory(); #else String szValue; StackCharVector512 value; value.Resize(512); DWORD size = ::GetCurrentDirectory((DWORD)value.Size(), value.Data()); if (size > value.Size()) { value.Resize(size); size = ::GetCurrentDirectory((DWORD)value.Size(), value.Data()); } if (size) { szValue = value.Data(); StripSuperLongPrefix(szValue); } return szValue; #endif }
void Configuration::CheckOptionValues(bool reset) { Strings::CheckValue(ArchivePath, "", reset); Numbers::CheckValue(BinarySerialize, false, true, false, reset); Strings::CheckValue(ConfigFile, "Plato.config", reset); Numbers::CheckValue(DebugLevel, 0, 10, 10, reset); Numbers::CheckValue(RunDiagnostics, false, true, true, reset); Numbers::CheckValue(EpochCount, 0, LONG_MAX, -1, reset); Strings::CheckValue(PathPrefix, "$(PlatoPrefix)Plato", reset); Strings::CheckValue(PlatoPrefix, GetExecutableDirectory(), reset); Numbers::CheckValue(TraceLevel, 0, 10, 10, reset); }
void Initialize() { char buffer[_MAX_PATH]; if (GetTempPath(sizeof(buffer), buffer) == 0) { g_sTempPath = "c:\\"; } else { g_sTempPath = buffer; } g_bIsAdmin = ::IsAdmin(); g_bIsWindowsNT = ::IsWindowsNT(); g_bIE5 = (GetDllVersion("shdocvw.dll") >= PACKVERSION(5,0)); // Guess which mode ! g_sInternetMethod = (g_bIE5 ? "ie5" : "direct"); // The TeXLive registry key g_sRegKey = ConcatPath( TEXLIVE_REGENTRY, TEXLIVE_VERSION); // VarTexmf will be stored in temp dir g_sVarTexmf = ConcatPath(g_sTempPath, "TeX\\texmf"); // Get the cdrom texmf tree CString sDummyName; DWORD dwDummySize; #ifdef TEST g_sTexmfMain = "e:\\TeXLive\\setupw32"; #else GetExecutableDirectory(g_sTexmfMain, sDummyName, dwDummySize); #endif // Assume we are in \bin\win32 subdirectory, so: GetParentDirectory(g_sTexmfMain); GetParentDirectory(g_sTexmfMain); g_sDriveRootPath = g_sTexmfMain; g_sBinDir = ConcatPath(g_sTexmfMain, "bin\\win32"); g_sSetupw32 = ConcatPath(g_sTexmfMain, "setupw32"); g_sSupport = ConcatPath(g_sTexmfMain, "support"); g_sTexmfMain = ConcatPath(g_sTexmfMain, "texmf"); if (! DirectoryExists(g_sTexmfMain) ) { AfxMessageBox(IDS_NO_TEXLIVE_TEXMF, MB_OK | MB_ICONSTOP); exit(1); } if (! DirectoryExists(g_sBinDir) ) { AfxMessageBox(IDS_NO_TEXLIVE_BINARIES, MB_OK | MB_ICONSTOP); exit(1); } GetEditorLocation(g_sEditor); }
Configuration::Configuration(const string& modelName, char* arguments[]) { DebugLevel = 0; TraceLevel = 0; BinarySerialize = false; RunDiagnostics = false; EpochCount = 0; ArchivePath = NULL; ConfigFile = NULL; PathPrefix = NULL; PlatoPrefix = NULL; ModelParameters = NULL; CheckOptionValues(true); ModelParameters = new CommandLine(arguments); // Work out a config file to open. const string* newConfigFile = ModelParameters->GetOptionValue("ConfigFile"); try { // Initialise the name of the config file to load. if (newConfigFile==NULL || newConfigFile->empty()) { string* tmp = new string(GetExecutableDirectory()); *tmp += PlatformDirectorySeparator + modelName + ".config"; newConfigFile = tmp; } } catch (...) { Trace::WriteLine(1, "Configuration: Configuration: setting ConfigFile exception."); string* tmp = new string(modelName); *tmp += ".config"; newConfigFile = tmp; } // Find an appropriate config file that exists. ifstream* textFile = new ifstream(newConfigFile->c_str()); if(textFile->fail()) { delete textFile; textFile = new ifstream(ConfigFile->c_str()); if(textFile->fail()) { delete ConfigFile; ConfigFile = newConfigFile; } else { delete newConfigFile; } } else { delete ConfigFile; ConfigFile = newConfigFile; } delete textFile; LoadConfigFile(); }
void COptions::SaveOptions() { USES_CONVERSION; CStdString xmlFileName = GetExecutableDirectory() + _T("FileZilla Server.xml"); char* bufferA = T2A(xmlFileName); if (!bufferA) return; TiXmlDocument document; if (!document.LoadFile(bufferA)) return; TiXmlElement* pRoot = document.FirstChildElement("FileZillaServer"); if (!pRoot) return; TiXmlElement* pSettings; while ((pSettings = pRoot->FirstChildElement("Settings"))) pRoot->RemoveChild(pSettings); pSettings = pRoot->LinkEndChild(new TiXmlElement("Settings"))->ToElement(); for (unsigned int i = 0; i < OPTIONS_NUM; i++) { if (!m_OptionsCache[i].bCached) continue; CStdString valuestr; if (!m_OptionsCache[i].nType) valuestr = m_OptionsCache[i].str; else valuestr.Format( _T("%I64d"), m_OptionsCache[i].value); TiXmlElement* pItem = pSettings->LinkEndChild(new TiXmlElement("Item"))->ToElement(); pItem->SetAttribute("name", ConvToNetwork(m_Options[i].name).c_str()); if (!m_OptionsCache[i].nType) pItem->SetAttribute("type", "string"); else pItem->SetAttribute("type", "numeric"); pItem->LinkEndChild(new TiXmlText(ConvToNetwork(valuestr).c_str())); } SaveSpeedLimits(pSettings); document.SaveFile(bufferA); }
void RunConformanceTest(const std::string &testPath, const ConformanceConfig& config) { std::vector<char*> args; // Empty first argument for the program name args.push_back(""); std::vector<char> widthArg = FormatArg("-width=%u", config.width); args.push_back(widthArg.data()); std::vector<char> heightArg = FormatArg("-height=%u", config.height); args.push_back(heightArg.data()); std::vector<char> displayArg = FormatArg("-d=%u", config.displayType); args.push_back(displayArg.data()); std::vector<char> runArg = FormatArg("-run=%s/conformance_tests/%s", GetExecutableDirectory().c_str(), testPath.c_str()); args.push_back(runArg.data()); // Redirect cout std::streambuf* oldCoutStreamBuf = std::cout.rdbuf(); std::ostringstream strCout; std::cout.rdbuf(strCout.rdbuf()); if (GTFMain(args.size(), args.data()) != 0) { FAIL() << "GTFMain failed."; } // Restore old cout std::cout.rdbuf(oldCoutStreamBuf); std::string log = strCout.str(); // Look for failures size_t offset = 0; std::string offsetSearchString = "failure = "; while ((offset = log.find("failure = ", offset)) != std::string::npos) { offset += offsetSearchString.length(); size_t failureCount = atoll(log.c_str() + offset); EXPECT_EQ(0, failureCount) << log; } }
std::string AlloyContext::getFullPath(const std::string& partialFile) { std::string fileName = partialFile; if (ALY_PATH_SEPARATOR[0] != '/') { for (char& c : fileName) { if (c == '/') { c = ALY_PATH_SEPARATOR[0]; } } } else if (ALY_PATH_SEPARATOR[0] != '\\') { for (char& c : fileName) { if (c == '\\') { c = ALY_PATH_SEPARATOR[0]; } } } for (std::string& dir : assetDirectories) { std::string fullPath = RemoveTrailingSlash(dir) + ALY_PATH_SEPARATOR+ fileName; if (FileExists(fullPath)) { return fullPath; } } std::string executableDir = GetExecutableDirectory(); for (std::string& dir : assetDirectories) { std::string fullPath = RemoveTrailingSlash(executableDir) + ALY_PATH_SEPARATOR+ RemoveTrailingSlash(dir) + ALY_PATH_SEPARATOR + fileName; if (FileExists(fullPath)) { return fullPath; } } std::cout << "Could not find \"" << fileName << "\"\nThis is where I looked:" << std::endl; for (std::string& dir : assetDirectories) { std::string fullPath = RemoveTrailingSlash(dir) + ALY_PATH_SEPARATOR+ fileName; std::cout << "\"" << fullPath << "\"" << std::endl; fullPath = executableDir + ALY_PATH_SEPARATOR + RemoveTrailingSlash(dir) + ALY_PATH_SEPARATOR + fileName; std::cout << "\"" << fullPath << "\"" << std::endl; } throw std::runtime_error( MakeString() << "Could not find \"" << fileName << "\""); return std::string(""); }
//************************************************************************** // // DbgGetLogFileName // // // // Parameter List : // Return Value : // Modification history : // // xxjun98:CJC ->creation // //************************************************************************** bool DbgGetLogFileName( STRING512 pcName ) { // use the provided buffer to get the directory name, then tack on // "\debug.txt" #ifndef _NO_DEBUG_TXT if ( ! GetExecutableDirectory( pcName ) ) { return false; } if ( strlen( pcName ) > (512 - strlen( "\\debug.txt" ) - 1 ) ) { // no room! return false; } strcat( pcName, "\\debug.txt" ); #endif return true; }
FilePath Application::GetConfigFilePath (const wxString &configFileName, bool createConfigDir) { DirectoryPath configDir; if (!Core->IsInPortableMode()) { #ifdef TC_MACOSX wxFileName configPath (L"~/Library/Application Support/CipherShed"); configPath.Normalize(); configDir = wstring (configPath.GetFullPath()); #else wxStandardPathsBase& stdPaths = wxStandardPaths::Get(); configDir = wstring (stdPaths.GetUserDataDir()); #endif } else configDir = GetExecutableDirectory(); if (createConfigDir && !configDir.IsDirectory()) Directory::Create (configDir); FilePath filePath = wstring (wxFileName (wstring (configDir), configFileName).GetFullPath()); return filePath; }
void COptions::Init() { if (m_bInitialized) return; simple_lock lock(m_mutex); m_bInitialized = TRUE; for (int i = 0; i < OPTIONS_NUM; ++i) m_sOptionsCache[i].bCached = FALSE; USES_CONVERSION; CStdString xmlFileName = GetExecutableDirectory() + _T("FileZilla Server.xml"); char* bufferA = T2A(xmlFileName); if (!bufferA) { return; } TiXmlDocument document; WIN32_FILE_ATTRIBUTE_DATA status{}; if (!GetStatus64(xmlFileName, status) ) { document.LinkEndChild(new TiXmlElement("FileZillaServer")); document.SaveFile(bufferA); } else if (status.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { return; } if (!document.LoadFile(bufferA)) { return; } TiXmlElement* pRoot = document.FirstChildElement("FileZillaServer"); if (!pRoot) { return; } TiXmlElement* pSettings = pRoot->FirstChildElement("Settings"); if (!pSettings) pSettings = pRoot->LinkEndChild(new TiXmlElement("Settings"))->ToElement(); TiXmlElement* pItem; for (pItem = pSettings->FirstChildElement("Item"); pItem; pItem = pItem->NextSiblingElement("Item")) { const char* pName = pItem->Attribute("name"); if (!pName) continue; CStdString name(pName); const char* pType = pItem->Attribute("type"); if (!pType) continue; CStdString type(pType); TiXmlNode* textNode = pItem->FirstChild(); CStdString value; if (textNode && textNode->ToText()) value = ConvFromNetwork(textNode->Value()); else if (type == _T("numeric")) continue; for (int i = 0; i < OPTIONS_NUM; ++i) { if (!_tcscmp(name, m_Options[i].name)) { if (m_sOptionsCache[i].bCached) break; if (type == _T("numeric")) { if (m_Options[i].nType != 1) break; _int64 value64 = _ttoi64(value); if (IsNumeric(value)) SetOption(i + 1, value64, false); } else { if (m_Options[i].nType != 0) break; SetOption(i + 1, value, false); } break; } } } ReadSpeedLimits(pSettings); UpdateInstances(); }
void GetWinFontInfo() { /* ;default settings, can be changed in GAME_INI_FILE [LargeFont1] Name=Tahoma Height=-12 Weight=400 [SmallFont1] Name=Tahoma Height=-12 Weight=400 [TinyFont1] Name=Tahoma Height=-12 Weight=400 [12PointFont1] Name=Tahoma Height=-14 Weight=400 [CompFont] Name=Tahoma Height=-12 Weight=400 [SmallCompFont] Name=Tahoma Height=-12 Weight=400 [10PointRoman] Name=Tahoma Height=-12 Weight=400 [12PointRoman] Name=Tahoma Height=-14 Weight=400 [14PointSansSerif] Name=Tahoma Height=-16 Weight=400 [10PointArial] Name=Tahoma Height=-12 Weight=400 [14PointArial] Name=Tahoma Height=-16 Weight=700 [12PointArial] Name=Tahoma Height=-14 Weight=400 [BlockyFont] Name=Tahoma Height=-12 Weight=700 [BlockyFont2] Name=Tahoma Height=-12 Weight=700 [10PointArialBold] Name=Tahoma Height=-12 Weight=400 [12PointArialFixedFont] Name=Tahoma Height=-14 Weight=400 [16PointArial] Name=Tahoma Height=-18 Weight=400 [BlockFontNarrow] Name=Tahoma Height=-12 Weight=700 [14PointHumanist] Name=Tahoma Height=-16 Weight=400 [HugeFont] Name=Tahoma Height=-20 Weight=400 */ #ifndef USE_VFS char INIFile[MAX_PATH]; GetExecutableDirectory( INIFile ); strcat(INIFile, "\\"); strcat(INIFile, GAME_INI_FILE); gWinFontAdjust = GetPrivateProfileInt("Ja2 Settings", "WIN_FONT_ADJUST", 0, INIFile); for (UINT16 i=0; i<WIN_LASTFONT; i++) { GetPrivateProfileString(FontInfo[i].FontName, "Name", FontInfo[i].LogFont.lfFaceName, FontInfo[i].LogFont.lfFaceName, LF_FACESIZE, INIFile); FontInfo[i].LogFont.lfHeight = gWinFontAdjust + GetPrivateProfileInt(FontInfo[i].FontName, "Height", FontInfo[i].LogFont.lfHeight, INIFile); FontInfo[i].LogFont.lfWeight = GetPrivateProfileInt(FontInfo[i].FontName, "Weight", FontInfo[i].LogFont.lfWeight, INIFile); } #else vfs::PropertyContainer props; props.initFromIniFile(GAME_INI_FILE); gWinFontAdjust = (LONG)props.getIntProperty(L"Ja2 Settings", L"WIN_FONT_ADJUST", 0); for (UINT16 i=0; i<WIN_LASTFONT; i++) { vfs::String name = props.getStringProperty(FontInfo[i].FontName, L"Name", FontInfo[i].LogFont.lfFaceName); strncpy(FontInfo[i].LogFont.lfFaceName, name.utf8().c_str(), LF_FACESIZE); FontInfo[i].LogFont.lfHeight = gWinFontAdjust + (LONG)props.getIntProperty(FontInfo[i].FontName, "Height", FontInfo[i].LogFont.lfHeight); FontInfo[i].LogFont.lfWeight = (LONG)props.getIntProperty(FontInfo[i].FontName, "Weight", FontInfo[i].LogFont.lfWeight); } #endif }
//Simply create videosurface, load image, and draw it to the screen. void InitJA2SplashScreen() { UINT32 uiLogoID = 0; STRING512 CurrentDir; STRING512 DataDir; HVSURFACE hVSurface; VSURFACE_DESC VSurfaceDesc; INT32 i = 0; InitializeJA2Clock(); //InitializeJA2TimerID(); // Get Executable Directory GetExecutableDirectory( CurrentDir ); // Adjust Current Dir sprintf( DataDir, "%s\\Data", CurrentDir ); if ( !SetFileManCurrentDirectory( DataDir ) ) { DebugMsg( TOPIC_JA2, DBG_LEVEL_3, "Could not find data directory, shutting down"); return; } //Initialize the file database InitializeFileDatabase( gGameLibaries, NUMBER_OF_LIBRARIES ); #if !defined( ENGLISH ) && defined( JA2TESTVERSION ) memset( &VSurfaceDesc, 0, sizeof( VSURFACE_DESC ) ); VSurfaceDesc.fCreateFlags = VSURFACE_CREATE_FROMFILE | VSURFACE_SYSTEM_MEM_USAGE; sprintf( VSurfaceDesc.ImageFile, "LOADSCREENS\\Notification.sti" ); if( !AddVideoSurface( &VSurfaceDesc, &uiLogoID ) ) { AssertMsg( 0, String( "Failed to load %s", VSurfaceDesc.ImageFile ) ); return; } GetVideoSurface(&hVSurface, uiLogoID ); BltVideoSurfaceToVideoSurface( ghFrameBuffer, hVSurface, 0, 0, 0, 0, NULL ); DeleteVideoSurfaceFromIndex( uiLogoID ); InvalidateScreen(); RefreshScreen( NULL ); guiSplashStartTime = GetJA2Clock(); while( i < 60 * 15 )//guiSplashStartTime + 15000 > GetJA2Clock() ) { //Allow the user to pick his bum. InvalidateScreen(); RefreshScreen( NULL ); i++; } #endif #ifdef ENGLISH ClearMainMenu(); #else { memset( &VSurfaceDesc, 0, sizeof( VSURFACE_DESC ) ); VSurfaceDesc.fCreateFlags = VSURFACE_CREATE_FROMFILE | VSURFACE_SYSTEM_MEM_USAGE; GetMLGFilename( VSurfaceDesc.ImageFile, MLG_SPLASH ); if( !AddVideoSurface( &VSurfaceDesc, &uiLogoID ) ) { AssertMsg( 0, String( "Failed to load %s", VSurfaceDesc.ImageFile ) ); return; } GetVideoSurface( &hVSurface, uiLogoID ); BltVideoSurfaceToVideoSurface( ghFrameBuffer, hVSurface, 0, 0, 0, 0, NULL ); DeleteVideoSurfaceFromIndex( uiLogoID ); } #endif InvalidateScreen(); RefreshScreen( NULL ); guiSplashStartTime = GetJA2Clock(); }
String GetDataDirectory() { String l_return = GetExecutableDirectory(); l_return = l_return.substr( 0, l_return.find_last_of( FOLDER_SEPARATOR ) + 1 ) + _T( "share" ) + FOLDER_SEPARATOR + _T( "ProceduralGenerator" ); return l_return; }
static std::string GetDataDirectory(const std::string &append = "") { return GetExecutableDirectory() + "../../tests/data" + append; }
void COptions::SetOption(int nOptionID, _int64 value, bool save /*=true*/) { switch (nOptionID) { case OPTION_MAXUSERS: if (value < 0) value = 0; break; case OPTION_THREADNUM: if (value < 1) value = 2; else if (value > 50) value = 2; break; case OPTION_TIMEOUT: if (value < 0) value = 120; else if (value > 9999) value = 120; break; case OPTION_NOTRANSFERTIMEOUT: if (value < 600 && value != 0) value = 600; else if (value > 9999) value = 600; break; case OPTION_LOGINTIMEOUT: if (value < 0) value = 60; else if (value > 9999) value = 60; break; case OPTION_ADMINPORT: if (value > 65535) value = 14147; else if (value < 1) value = 14147; break; case OPTION_LOGTYPE: if (value != 0 && value != 1) value = 0; break; case OPTION_LOGLIMITSIZE: if ((value > 999999 || value < 10) && value != 0) value = 100; break; case OPTION_LOGDELETETIME: if (value > 999 || value < 0) value = 14; break; case OPTION_DOWNLOADSPEEDLIMITTYPE: case OPTION_UPLOADSPEEDLIMITTYPE: if (value < 0 || value > 2) value = 0; break; case OPTION_DOWNLOADSPEEDLIMIT: case OPTION_UPLOADSPEEDLIMIT: if (value < 1) value = 1; else if (value > 1048576) value = 1048576; break; case OPTION_BUFFERSIZE: if (value < 256 || value > (1024*1024)) value = 32768; break; case OPTION_BUFFERSIZE2: if (value < 256 || value > (1024*1024*128)) value = 262144; break; case OPTION_CUSTOMPASVIPTYPE: if (value < 0 || value > 2) value = 0; break; case OPTION_MODEZ_USE: if (value < 0 || value > 1) value = 0; break; case OPTION_MODEZ_LEVELMIN: if (value < 0 || value > 8) value = 1; break; case OPTION_MODEZ_LEVELMAX: if (value < 8 || value > 9) value = 9; break; case OPTION_MODEZ_ALLOWLOCAL: if (value < 0 || value > 1) value = 0; break; case OPTION_AUTOBAN_ATTEMPTS: if (value < OPTION_AUTOBAN_ATTEMPTS_MIN) value = OPTION_AUTOBAN_ATTEMPTS_MIN; if (value > OPTION_AUTOBAN_ATTEMPTS_MAX) value = OPTION_AUTOBAN_ATTEMPTS_MAX; break; case OPTION_AUTOBAN_BANTIME: if (value < 1) value = 1; if (value > 999) value = 999; break; } Init(); { simple_lock lock(m_mutex); m_sOptionsCache[nOptionID-1].nType = 1; m_sOptionsCache[nOptionID-1].value = value; m_sOptionsCache[nOptionID-1].bCached = TRUE; m_OptionsCache[nOptionID-1] = m_sOptionsCache[nOptionID - 1]; } if (!save) return; CStdString valuestr; valuestr.Format( _T("%I64d"), value); USES_CONVERSION; CStdString xmlFileName = GetExecutableDirectory() + _T("FileZilla Server.xml"); char* bufferA = T2A(xmlFileName); if (!bufferA) return; TiXmlDocument document; if (!document.LoadFile(bufferA)) return; TiXmlElement* pRoot = document.FirstChildElement("FileZillaServer"); if (!pRoot) return; TiXmlElement* pSettings = pRoot->FirstChildElement("Settings"); if (!pSettings) pSettings = pRoot->LinkEndChild(new TiXmlElement("Settings"))->ToElement(); TiXmlElement* pItem; for (pItem = pSettings->FirstChildElement("Item"); pItem; pItem = pItem->NextSiblingElement("Item")) { const char* pName = pItem->Attribute("name"); if (!pName) continue; CStdString name(pName); if (name != m_Options[nOptionID-1].name) continue; break; } if (!pItem) pItem = pSettings->LinkEndChild(new TiXmlElement("Item"))->ToElement(); pItem->Clear(); pItem->SetAttribute("name", ConvToNetwork(m_Options[nOptionID-1].name).c_str()); pItem->SetAttribute("type", "numeric"); pItem->LinkEndChild(new TiXmlText(ConvToNetwork(valuestr).c_str())); document.SaveFile(bufferA); }
void COptions::SetOption(int nOptionID, LPCTSTR value, bool save /*=true*/) { CStdString str = value; Init(); switch (nOptionID) { case OPTION_SERVERPORT: case OPTION_TLSPORTS: { std::set<int> portSet; str.TrimLeft(_T(" ,")); int pos = str.FindOneOf(_T(" ,")); while (pos != -1) { int port = _ttoi(str.Left(pos)); if (port >= 1 && port <= 65535) portSet.insert(port); str = str.Mid(pos + 1); str.TrimLeft(_T(" ,")); pos = str.FindOneOf(_T(" ,")); } if (str != _T("")) { int port = _ttoi(str); if (port >= 1 && port <= 65535) portSet.insert(port); } str = _T(""); for (std::set<int>::const_iterator iter = portSet.begin(); iter != portSet.end(); iter++) { CStdString tmp; tmp.Format(_T("%d "), *iter); str += tmp; } str.TrimRight(' '); } break; case OPTION_WELCOMEMESSAGE: { std::vector<CStdString> msgLines; int oldpos = 0; str.Replace(_T("\r\n"), _T("\n")); int pos = str.Find(_T("\n")); CStdString line; while (pos != -1) { if (pos) { line = str.Mid(oldpos, pos - oldpos); line = line.Left(CONST_WELCOMEMESSAGE_LINESIZE); line.TrimRight(_T(" ")); if (msgLines.size() || line != _T("")) msgLines.push_back(line); } oldpos = pos + 1; pos = str.Find(_T("\n"), oldpos); } line = str.Mid(oldpos); if (line != _T("")) { line = line.Left(CONST_WELCOMEMESSAGE_LINESIZE); msgLines.push_back(line); } str = _T(""); for (unsigned int i = 0; i < msgLines.size(); i++) str += msgLines[i] + _T("\r\n"); str.TrimRight(_T("\r\n")); if (str == _T("")) { str = _T("%v"); str += _T("\r\nwritten by Tim Kosse ([email protected])"); str += _T("\r\nPlease visit https://filezilla-project.org/"); } } break; case OPTION_ADMINIPBINDINGS: { CStdString sub; std::list<CStdString> ipBindList; for (unsigned int i = 0; i<_tcslen(value); i++) { TCHAR cur = value[i]; if ((cur < '0' || cur > '9') && cur != '.' && cur != ':') { if (sub == _T("") && cur == '*') { ipBindList.clear(); ipBindList.push_back(_T("*")); break; } if (sub != _T("")) { if (IsIpAddress(sub)) ipBindList.push_back(sub); sub = _T(""); } } else sub += cur; } if (sub != _T("")) { if (IsIpAddress(sub)) ipBindList.push_back(sub); } str = _T(""); for (std::list<CStdString>::iterator iter = ipBindList.begin(); iter!=ipBindList.end(); iter++) if (!IsLocalhost(*iter)) str += *iter + _T(" "); str.TrimRight(_T(" ")); } break; case OPTION_ADMINPASS: if (str != _T("") && str.GetLength() < 6) return; break; case OPTION_MODEZ_DISALLOWED_IPS: case OPTION_IPFILTER_ALLOWED: case OPTION_IPFILTER_DISALLOWED: case OPTION_ADMINIPADDRESSES: { str.Replace('\r', ' '); str.Replace('\n', ' '); str.Replace('\r', ' '); while (str.Replace(_T(" "), _T(" "))); str += _T(" "); CStdString ips; int pos = str.Find(' '); while (pos != -1) { CStdString sub = str.Left(pos); str = str.Mid(pos + 1); str.TrimLeft(' '); if (sub == _T("*")) ips += _T(" ") + sub; else { if (IsValidAddressFilter(sub)) ips += " " + sub; pos = str.Find(' '); } } ips.TrimLeft(' '); str = ips; } break; case OPTION_IPBINDINGS: { std::list<CStdString> ipBindList; str += _T(" "); while (!str.empty()) { int pos = str.Find(' '); if (pos < 0) { break; } CStdString sub = str.Left(pos); str = str.Mid(pos + 1); if (sub == _T("*")) { ipBindList.clear(); ipBindList.push_back(_T("*")); break; } else if (IsIpAddress(sub, true)) { ipBindList.push_back(sub); } } if (ipBindList.empty()) ipBindList.push_back(_T("*")); str.clear(); for (auto const& ip : ipBindList) { str += ip + _T(" "); } str.TrimRight(_T(" ")); } break; case OPTION_CUSTOMPASVIPSERVER: if (str.Find(_T("filezilla.sourceforge.net")) != -1) str = _T("http://ip.filezilla-project.org/ip.php"); break; } { simple_lock lock(m_mutex); m_sOptionsCache[nOptionID-1].bCached = TRUE; m_sOptionsCache[nOptionID-1].nType = 0; m_sOptionsCache[nOptionID-1].str = str; m_OptionsCache[nOptionID-1]=m_sOptionsCache[nOptionID-1]; } if (!save) return; USES_CONVERSION; CStdString xmlFileName = GetExecutableDirectory() + _T("FileZilla Server.xml"); char* bufferA = T2A(xmlFileName); if (!bufferA) return; TiXmlDocument document; if (!document.LoadFile(bufferA)) return; TiXmlElement* pRoot = document.FirstChildElement("FileZillaServer"); if (!pRoot) return; TiXmlElement* pSettings = pRoot->FirstChildElement("Settings"); if (!pSettings) pSettings = pRoot->LinkEndChild(new TiXmlElement("Settings"))->ToElement(); TiXmlElement* pItem; for (pItem = pSettings->FirstChildElement("Item"); pItem; pItem = pItem->NextSiblingElement("Item")) { const char* pName = pItem->Attribute("name"); if (!pName) continue; CStdString name(pName); if (name != m_Options[nOptionID-1].name) continue; break; } if (!pItem) pItem = pSettings->LinkEndChild(new TiXmlElement("Item"))->ToElement(); pItem->Clear(); pItem->SetAttribute("name", ConvToNetwork(m_Options[nOptionID - 1].name).c_str()); pItem->SetAttribute("type", "string"); pItem->LinkEndChild(new TiXmlText(ConvToNetwork(value).c_str())); document.SaveFile(bufferA); }