public static bool TryLoadLocation(string rootPath, bool enabled, out InstallationLocation location) { string autoUpdatePath = System.IO.Path.Combine(rootPath ?? ".", AUTO_UPDATE_CONFIG); string version; // XXX can we register for changes on these files without breaking DCS? how does that work in Windows? if (File.Exists(autoUpdatePath)) { version = JsonConvert.DeserializeObject <AutoUpdateConfig>(File.ReadAllText(autoUpdatePath)).Version; } else { string exePath = System.IO.Path.Combine(rootPath ?? ".", "bin", "DCS.exe"); if (File.Exists(exePath)) { version = ExtractFileVersion(exePath); } else { // fail, which happens for stale settings location = null; return(false); } } location = new InstallationLocation(rootPath, version, enabled); return(true); }
private static void OnChangeEnabled(DependencyObject target, DependencyPropertyChangedEventArgs e) { InstallationLocation location = (InstallationLocation)target; if (_suppressEvents) { return; } location.UpdateSettings(); location.NotifyChangeEnabled(); }
internal bool TryRemove(InstallationLocation oldItem) { if (oldItem == null) { return(false); } if (!Items.Remove(oldItem)) { return(false); } oldItem.DeleteSettings(); Removed?.Invoke(this, new LocationEvent(oldItem)); return(true); }
private void DoAdd(InstallationLocation newItem) { newItem.ChangeEnabled += (sender, e) => { InstallationLocation location = (InstallationLocation)sender; if (location.IsEnabled) { Enabled?.Invoke(this, new LocationEvent(location)); } else { Disabled?.Invoke(this, new LocationEvent(location)); } }; Items.Add(newItem); }
private void LoadAll() { // load from settings XML _suppressWrites = true; try { foreach (InstallationLocation item in InstallationLocation.ReadSettings()) { DoAdd(item); } IsRemote = ConfigManager.SettingsManager.LoadSetting("DCSInstallation", "IsRemote", false); } finally { _suppressWrites = false; } }
internal bool TryAdd(InstallationLocation newItem) { // scan list; O(n) but this is a UI action if (Items.Any(existing => existing.Path.Equals(newItem.Path, StringComparison.CurrentCultureIgnoreCase))) { return(false); } // add to our collection and register handlers DoAdd(newItem); // write it to settings file newItem.UpdateSettings(); // notify our customers Added?.Invoke(this, new LocationEvent(newItem)); return(true); }
public static bool TryBrowseLocation(string selectedFile, out InstallationLocation location) { string rootPath; string shortName = System.IO.Path.GetFileName(selectedFile); if (shortName.Equals(DCS_EXE, StringComparison.InvariantCultureIgnoreCase)) { // user picked DCS.exe, maybe this is Steam or maybe they just chose to rootPath = System.IO.Path.GetDirectoryName(System.IO.Path.GetDirectoryName(selectedFile)); } else { rootPath = System.IO.Path.GetDirectoryName(selectedFile); } Debug.Assert(rootPath != null, "a file path we retrieved from open file dialog should not have a null directory"); return(TryLoadLocation(rootPath, true, out location)); }
/// <summary> /// parses the options.lua file from DCS or returns false if it cannot /// </summary> /// <param name="location"></param> /// <param name="options"></param> /// <returns></returns> public static bool TryReadOptions(InstallationLocation location, out DCSOptions options) { string optionsPath = location.OptionsPath; if (!File.Exists(optionsPath)) { options = null; return(false); } try { string optionsText = File.ReadAllText(optionsPath); NLua.Lua parser = new NLua.Lua(); parser.DoString(optionsText, "options.lua"); object graphics = parser.GetObjectFromPath("options.graphics"); if (graphics is NLua.LuaTable graphicsTable && graphicsTable["width"] is long width && graphicsTable["height"] is long height && graphicsTable["multiMonitorSetup"] is string multiMonitorSetup) { options = new DCSOptions { Graphics = new GraphicsTable(width, height, multiMonitorSetup) }; return(true); } } catch (Exception ex) { // this is sort of ok, we might not have access, so we just don't check this part Logger.Info(ex, "failed to read DCS-owned options.lua file; Helios will not be able to check settings"); } options = null; return(false); }
internal LocationEvent(InstallationLocation location) { Location = location; }