public static CTestAdapterConfig ReadFromDisk(string file) { if (!File.Exists(file)) { return(null); } var ser = new XmlSerializer(typeof(CTestAdapterConfig)); while (CTestAdapterConfig.IsFileLocked(file)) { Thread.Sleep(50); } var str = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read); var cfg = (CTestAdapterConfig)ser.Deserialize(str); str.Close(); if (null == cfg) { return(null); } if (cfg._configFileName != file) { // @todo give some message here? } return(cfg); }
public static void WriteToDisk(CTestAdapterConfig cfg) { if (!cfg._dirty) { return; } if (!Directory.Exists(cfg.CacheDir)) { return; } var ser = new XmlSerializer(typeof(CTestAdapterConfig)); while (CTestAdapterConfig.IsFileLocked(cfg._configFileName)) { Thread.Sleep(50); } var str = new StreamWriter(cfg._configFileName); ser.Serialize(str, cfg); str.Close(); cfg._dirty = false; }
public void LoadCMakeCache(string fileName) { this._cmakeCacheFile = fileName; if (null == this._cmakeCacheFile || !File.Exists(this._cmakeCacheFile)) { this.Log(LogLevel.Debug, "LoadCMakeCache: clearing cmake CMakeCache"); this._cacheEntries.Clear(); return; } var newInfo = new FileInfo(this._cmakeCacheFile); if (this._cmakeCacheInfo != null) { this.Log(LogLevel.Debug, "LoadCMakeCache: comparing already loaded CMakeCache"); if (this._cmakeCacheInfo.FullName == newInfo.FullName && this._cmakeCacheInfo.LastWriteTime == newInfo.LastWriteTime && newInfo.Exists) { this.Log(LogLevel.Debug, "LoadCMakeCache: CMakeCache did not change, not reloading"); return; } } this.Log(LogLevel.Debug, "LoadCMakeCache: loading CMakeCache from \"" + this._cmakeCacheFile + "\""); this._cmakeCacheInfo = newInfo; this._cacheEntries.Clear(); if (!File.Exists(this._cmakeCacheFile)) { this.Log(LogLevel.Error, "LoadCMakeCache: CMakeCache not found at:\"" + this._cmakeCacheFile + "\""); return; } while (CTestAdapterConfig.IsFileLocked(this._cmakeCacheFile)) { Thread.Sleep(50); } var stream = new FileStream(this._cmakeCacheFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); var r = new StreamReader(stream); while (!r.EndOfStream) { var line = r.ReadLine(); if (null == line) { continue; } line = line.TrimStart(' '); if (line.Length == 0 || line.StartsWith("#") || line.StartsWith("//")) { continue; } var c = CMakeCache.CacheEntryRegex.Split(line); if (c.Length != 5) { this.Log(LogLevel.Warning, "LoadCMakeCache: CMakeCache load: element count != 5: (" + c.Length + ")" + line); var count = 0; foreach (var asdf in c) { this.Log(LogLevel.Warning, "v" + count + ": " + asdf); count++; } continue; } CMakeCacheEntryType myType; if (!Enum.TryParse(c[2], out myType)) { this.Log(LogLevel.Error, "LoadCMakeCache: cache load: error parsing enum Type: " + c[2]); continue; } var entry = new CMakeCacheEntry() { Name = c[1], Value = c[3] }; if (entry.Name.StartsWith("\"") && entry.Name.Length > 2) { entry.Name = entry.Name.Substring(1, entry.Name.Length - 2); } this._cacheEntries.Add(entry.Name, entry); } r.Close(); stream.Close(); r.Dispose(); stream.Dispose(); }