IniFileService(string iniFilename) { iniReader_ = new IniFileNative(iniFilename); iniFileDirectory_ = Path.GetDirectoryName(iniFilename); logger_ = null; updateCount_ = 0; watcher_ = new FileSystemWatcher(); watcher_.Path = iniFileDirectory_; watcher_.Filter = Path.GetFileName(iniFilename); watcher_.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Size; watcher_.IncludeSubdirectories = false; watcher_.Changed += Watcher__Changed; watcher_.EnableRaisingEvents = true; }
/// <summary> /// iniファイルからサーバ設定ファイルを見付ける /// </summary> /// <param name="fileExtension">ファイル拡張子(".c", ".cpp" ...)</param> /// <returns>サーバ設定ファイル(絶対パス)、または空文字</returns> public string FindServerConfig(string fileExtension) { string absFileName = null; try { var serverIniFilename = SearchExistServerIni(); if (string.IsNullOrEmpty(serverIniFilename)) { return(null); } var serverIniReader = new IniFileNative(serverIniFilename); const string sectionName = "ServerConfig"; var path = serverIniReader.Read(fileExtension, sectionName); if (string.IsNullOrEmpty(path)) { logger_?.Info($"Not found key in ini file. section={sectionName} / key={fileExtension} / serverIniFilename={serverIniFilename}"); return(null); } if (Path.IsPathRooted(path)) { return(path); } //iniFileからの相対パス→絶対パス var serverIniDirectoryName = Path.GetDirectoryName(serverIniFilename); absFileName = Path.GetFullPath(Path.Combine(serverIniDirectoryName, path)); return(absFileName); } catch (Exception e) { logger_?.Error(e.ToString()); } finally{ logger_?.Info($"FindServerConfig return. \"{fileExtension}\" -> \"{absFileName}\""); } return(null); }