private void ImportLut(string filename) { try { string name; if (!FileUtils.ArePathsEqual(Path.GetDirectoryName(filename), AcPaths.GetDocumentsCfgDirectory())) { name = Prompt.Show("Choose a name for the new LUT setting:", "New LUT", Path.GetFileNameWithoutExtension(filename) + ".lut", "?", required: true, maxLength: 120); if (string.IsNullOrWhiteSpace(name)) { return; } if (!name.EndsWith(".lut", StringComparison.OrdinalIgnoreCase)) { name += ".lut"; } File.Copy(filename, Path.Combine(AcPaths.GetDocumentsCfgDirectory(), name), true); } else { name = Path.GetFileName(filename); } SwitchFfPostProcessLutName(name); } catch (Exception e) { NonfatalError.Notify("Can’t import LUT-file", e); } }
private static bool InstallModule() { try { var ini = new IniFile(Path.Combine(AcPaths.GetDocumentsCfgDirectory(), "launcher.ini")); var theme = ini["WINDOW"].GetNonEmpty("theme"); var directory = Path.Combine(AcRootDirectory.Instance.RequireValue, @"launcher", @"themes", theme ?? @"default", @"modules", ModuleId); var installed = false; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); using (var stream = new MemoryStream(BinaryResources.ModuleCmHelper)) using (var archive = new ZipArchive(stream)) { archive.ExtractToDirectory(directory); } installed = true; } var active = ini["MODULES"].GetStrings("ACTIVE"); if (!active.ArrayContains(ModuleId)) { ini["MODULES"].Set("ACTIVE", active.Append(@"CmHelper").Distinct()); ini.Save(); installed = true; } return(installed); } catch (Exception e) { throw new InformativeException("Can’t install UI module", e); } }
private void ImportCsv(string filename) { try { if (_wrapper == null) { throw new InformativeException("Can’t import CSV-file", "LUTLibrary.dll missing or can’t be loaded."); } var name = Prompt.Show("Choose a name for the new LUT setting:", "New LUT", Path.GetFileNameWithoutExtension(filename) + ".lut", "?", required: true, maxLength: 120); if (string.IsNullOrWhiteSpace(name)) { return; } if (!name.EndsWith(@".lut", StringComparison.OrdinalIgnoreCase)) { name += @".lut"; } var lutData = new LutDataFile(); var lut = _wrapper.ToLut(filename); if (lut == null) { throw new Exception(@"Expected field or method is missing"); } lutData.Values.AddRange(lut); lutData.Save(Path.Combine(AcPaths.GetDocumentsCfgDirectory(), name)); SwitchFfPostProcessLutName(name); } catch (Exception e) { NonfatalError.Notify("Can’t import CSV-file", e); } }
public static void PrepareIni(string carName, string skinName, string trackName, string trackConfig) { var ini = Path.Combine(AcPaths.GetDocumentsCfgDirectory(), "race.ini"); IniFile.Write(ini, "RACE", "MODEL", carName); IniFile.Write(ini, "RACE", "SKIN", skinName); IniFile.Write(ini, "CAR_0", "SKIN", skinName); IniFile.Write(ini, "RACE", "TRACK", trackName); IniFile.Write(ini, "RACE", "CONFIG_TRACK", trackConfig ?? ""); }
private static void DisableGhostCar() { var ini = Path.Combine(AcPaths.GetDocumentsCfgDirectory(), "race.ini"); IniFile.Write(ini, "GHOST_CAR", "RECORDING", "0"); IniFile.Write(ini, "GHOST_CAR", "PLAYING", "0"); IniFile.Write(ini, "GHOST_CAR", "SECONDS_ADVANTAGE", "0"); IniFile.Write(ini, "GHOST_CAR", "LOAD", "1"); IniFile.Write(ini, "GHOST_CAR", "FILE", ""); IniFile.Write(ini, "GHOST_CAR", "ENABLED", "0"); }
public static void PrepareIniRaceMode(RaceProperties properties) { var ini = Path.Combine(AcPaths.GetDocumentsCfgDirectory(), "race.ini"); var iniFile = new IniFile(ini); for (var i = 1; i < 100; i++) { var key = "CAR_" + i; if (iniFile.ContainsKey(key)) { iniFile.Remove(key); } else { break; } } iniFile.Save(); DisableGhostCar(); IniFile.Write(ini, "RACE", "CARS", properties.BotCars.Count() + 1); IniFile.Write(ini, "RACE", "AI_LEVEL", properties.AiLevel.RoundToInt()); IniFile.Write(ini, "RACE", "DRIFT_MODE", "0"); IniFile.Write(ini, "RACE", "RACE_LAPS", properties.RaceLaps); IniFile.Write(ini, "RACE", "FIXED_SETUP", properties.FixedSetup); IniFile.Write(ini, "RACE", "PENALTIES", properties.Penalties); IniFile.Write(ini, "GROOVE", "VIRTUAL_LAPS", "10"); IniFile.Write(ini, "GROOVE", "MAX_LAPS", "30"); IniFile.Write(ini, "GROOVE", "STARTING_LAPS", "0"); IniFile.Write(ini, "SESSION_0", "NAME", "Quick Race"); IniFile.Write(ini, "SESSION_0", "TYPE", "3"); IniFile.Write(ini, "SESSION_0", "LAPS", properties.RaceLaps); IniFile.Write(ini, "SESSION_0", "STARTING_POSITION", properties.StartingPosition); IniFile.Write(ini, "SESSION_0", "DURATION_MINUTES", "0"); IniFile.Write(ini, "SESSION_0", "SPAWN_SET", "START"); var j = 0; foreach (var botCar in properties.BotCars) { var section = "CAR_" + ++j; IniFile.Write(ini, section, "MODEL", botCar.CarId); IniFile.Write(ini, section, "MODEL_CONFIG", ""); IniFile.Write(ini, section, "SETUP", botCar.Setup); IniFile.Write(ini, section, "AI_LEVEL", botCar.AiLevel.RoundToInt()); IniFile.Write(ini, section, "SKIN", botCar.SkinId); IniFile.Write(ini, section, "DRIVER_NAME", botCar.DriverName); IniFile.Write(ini, section, "NATIONALITY", botCar.Nationality); } }
private TrackStatesHelper() { _templates = Path.Combine(AcPaths.GetDocumentsCfgDirectory(), "templates"); RegisterBuiltInPresets(); Directory.CreateDirectory(_templates); _watcher = new FileSystemWatcher { Path = _templates, Filter = "tracks.ini", NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName, EnableRaisingEvents = true }; _watcher.Changed += Handler; _watcher.Created += Handler; _watcher.Deleted += Handler; _watcher.Renamed += Handler; }
protected IniSettings([Localizable(false)] string name, bool reload = true, bool systemConfig = false) { try { var directory = systemConfig ? AcPaths.GetSystemCfgDirectory(AcRootDirectory.Instance.RequireValue) : AcPaths.GetDocumentsCfgDirectory(); Filename = Path.Combine(directory, name + ".ini"); if (reload) { Reload(); } var watcher = GetWatcher(directory); watcher.Changed += OnChanged; watcher.Created += OnChanged; watcher.Deleted += OnChanged; watcher.Renamed += OnRenamed; } catch (Exception e) { Logging.Warning("IniSettings exception: " + e); } }
public static void PrepareIniDriftMode() { var ini = Path.Combine(AcPaths.GetDocumentsCfgDirectory(), "race.ini"); DisableGhostCar(); IniFile.Write(ini, "RACE", "CARS", "1"); IniFile.Write(ini, "RACE", "AI_LEVEL", "90"); IniFile.Write(ini, "RACE", "DRIFT_MODE", "0"); IniFile.Write(ini, "RACE", "RACE_LAPS", "5"); IniFile.Write(ini, "RACE", "FIXED_SETUP", "0"); IniFile.Write(ini, "RACE", "PENALTIES", "1"); IniFile.Write(ini, "GROOVE", "VIRTUAL_LAPS", "10"); IniFile.Write(ini, "GROOVE", "MAX_LAPS", "1"); IniFile.Write(ini, "GROOVE", "STARTING_LAPS", "1"); IniFile.Write(ini, "SESSION_0", "NAME", "Drift Session"); IniFile.Write(ini, "SESSION_0", "TYPE", "6"); IniFile.Write(ini, "SESSION_0", "SPAWN_SET", "PIT"); }
public static void PrepareIniHotlapMode() { var ini = Path.Combine(AcPaths.GetDocumentsCfgDirectory(), "race.ini"); EnableGhostCar(); IniFile.Write(ini, "RACE", "CARS", "1"); IniFile.Write(ini, "RACE", "AI_LEVEL", "90"); IniFile.Write(ini, "RACE", "DRIFT_MODE", "0"); IniFile.Write(ini, "RACE", "RACE_LAPS", "5"); IniFile.Write(ini, "RACE", "FIXED_SETUP", "0"); IniFile.Write(ini, "RACE", "PENALTIES", "1"); IniFile.Write(ini, "GROOVE", "VIRTUAL_LAPS", "10"); IniFile.Write(ini, "GROOVE", "MAX_LAPS", "1"); IniFile.Write(ini, "GROOVE", "STARTING_LAPS", "1"); IniFile.Write(ini, "SESSION_0", "NAME", "Hotlap"); IniFile.Write(ini, "SESSION_0", "TYPE", "4"); IniFile.Write(ini, "SESSION_0", "DURATION_MINUTES", "0"); IniFile.Write(ini, "SESSION_0", "SPAWN_SET", "HOTLAP_START"); }
public static string GetUserConfigFilename(string configName) { return(Path.Combine(AcPaths.GetDocumentsCfgDirectory(), "extension", configName)); }
public static string GetWindowPositionConfig() { return(Path.Combine(AcPaths.GetDocumentsCfgDirectory(), "extension", "window_position.ini")); }
public static void SendLogs(string message = null) { var logsDirectory = FilesStorage.Instance.GetDirectory("Logs"); using (var memory = new MemoryStream()) { using (var writer = WriterFactory.Open(memory, ArchiveType.Zip, CompressionType.Deflate)) { if (!string.IsNullOrWhiteSpace(message)) { try { writer.WriteString("Message.txt", message); } catch (Exception e) { Logging.Warning("Can’t attach Message.txt: " + e); } } try { writer.Write("AC Log.txt", AcPaths.GetLogFilename()); } catch (Exception e) { Logging.Warning("Can’t attach AC Log.txt: " + e); } string wpfVersion; try { using (var r = Registry.LocalMachine.OpenSubKey( @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\Setup\Windows Presentation Foundation")) { wpfVersion = r?.GetValue("Version")?.ToString(); } } catch (Exception e) { Logging.Warning("Can’t get WPF version: " + e); wpfVersion = null; } try { writer.WriteString("Description.txt", JsonConvert.SerializeObject(new { BuildInformation.AppVersion, BuildInformation.Platform, MainExecutingFile.Location, Environment.OSVersion, Environment.CommandLine, Environment = Environment.GetEnvironmentVariables(), SteamId = SteamIdHelper.Instance.Value, typeof(string).Assembly.ImageRuntimeVersion, WpfVersion = wpfVersion }, Formatting.Indented)); } catch (Exception e) { Logging.Warning("Can’t attach Description.txt: " + e); } try { writer.WriteString("Values.txt", ValuesStorage.Storage.GetData()); } catch (Exception e) { Logging.Warning("Can’t attach Values.data: " + e); } try { if (File.Exists(FilesStorage.Instance.GetFilename("Arguments.txt"))) { writer.Write("Arguments.txt", FilesStorage.Instance.GetFilename("Arguments.txt")); } } catch (Exception e) { Logging.Warning("Can’t attach Arguments.txt: " + e); } foreach (var fileInfo in new DirectoryInfo(AcPaths.GetDocumentsCfgDirectory()).GetFiles("*.ini").Where(x => x.Length < 500000).Take(100)) { try { writer.Write("Config/" + fileInfo.Name, fileInfo.FullName); } catch (Exception e) { Logging.Warning("Can’t attach Config/" + fileInfo.Name + ": " + e); } } if (AcRootDirectory.Instance.Value != null) { foreach (var fileInfo in new DirectoryInfo(AcPaths.GetSystemCfgDirectory(AcRootDirectory.Instance.RequireValue)).GetFiles("*.ini") .Where(x => x.Length < 500000) .Take(100)) { try { writer.Write("SysConfig/" + fileInfo.Name, fileInfo.FullName); } catch (Exception e) { Logging.Warning("Can’t attach SysConfig/" + fileInfo.Name + ": " + e); } } } var raceOut = AcPaths.GetResultJsonFilename(); if (File.Exists(raceOut)) { try { writer.Write("Race.json", raceOut); } catch (Exception e) { Logging.Warning("Can’t attach Race.json:" + e); } } var career = AcPaths.GetKunosCareerProgressFilename(); if (File.Exists(career)) { try { writer.Write("Career.ini", career); } catch (Exception e) { Logging.Warning("Can’t attach Career.ini:" + e); } } foreach (var filename in Directory.GetFiles(logsDirectory, "Main*.log").TakeLast(35) .Union(Directory.GetFiles(logsDirectory, "Packed*.log").TakeLast(35))) { var name = Path.GetFileName(filename); try { writer.Write("Logs/" + name, filename); } catch (Exception e) { Logging.Warning("Can’t attach Logs/" + name + ": " + e); } } } var data = memory.ToArray(); if (data.Length > 20000000) { File.WriteAllBytes(FilesStorage.Instance.GetTemporaryFilename("Report.zip"), data); throw new Exception("Size limit exceeded"); } InternalUtils.SendAppReport(memory.ToArray(), $@"Name: {GetUserName()}; Operating system: {GetWindowsName()}; App version: {BuildInformation.AppVersion}.", CmApiProvider.UserAgent); } }
protected void SetAcX86Param() { IniFile.Write(Path.Combine(AcPaths.GetDocumentsCfgDirectory(), "launcher.ini"), "WINDOW", "X86", Use32BitVersion ? @"1" : @"0"); }
private void CreateConfigs() { if (Configs != null) { Configs.ValueChanged -= OnConfigsValueChanged; Configs.Dispose(); } if (!Directory.Exists(_dir)) { Mode = Mode.NoShadersPatch; Configs = null; return; } FileUtils.EnsureDirectoryExists(Path.Combine(AcPaths.GetDocumentsCfgDirectory(), "extension")); var anyConfigFound = false; Configs = new PythonAppConfigs(new PythonAppConfigParams(_dir) { FilesRelativeDirectory = AcRootDirectory.Instance.Value ?? _dir, ScanFunc = d => Directory.GetFiles(d, "*.ini").Where(x => !Path.GetFileName(x).StartsWith(@"data_")), ConfigFactory = (p, f) => { var fileName = Path.GetFileName(f); if (fileName == null) { return(null); } anyConfigFound = true; var userEditedFile = Path.Combine(AcPaths.GetDocumentsCfgDirectory(), "extension", fileName); var cfg = PythonAppConfig.Create(p, f, true, userEditedFile); if (_isLive && cfg.Sections.GetByIdOrDefault("ℹ")?.GetByIdOrDefault("LIVE_SUPPORT")?.Value == @"0") { return(null); } return(string.IsNullOrWhiteSpace(cfg.ShortDescription) ? null : cfg); }, SaveOnlyNonDefault = true, Flags = new Dictionary <string, string> { [@"IS_LIVE__"] = _isLive.As <string>() } }); if (Configs.Count > 0) { Mode = Mode.EverythingIsFine; } else if (anyConfigFound) { Mode = Mode.NoFittingConfigs; } else { Mode = Mode.NoConfigs; } SelectedConfig = Configs.GetByIdOrDefault(_selectedConfigId.Value) ?? Configs.FirstOrDefault(); Configs.ValueChanged += OnConfigsValueChanged; }