Example #1
0
        public static void Import([NotNull] string carId)
        {
            if (carId == null)
            {
                throw new ArgumentNullException(nameof(carId));
            }

            var cmDistance = PlayerStatsManager.Instance.GetDistanceDrivenByCar(carId);

            if (cmDistance <= 0d)
            {
                return;
            }

            var filename = Path.Combine(AcPaths.GetPythonAppsDirectory(AcRootDirectory.Instance.RequireValue), OdometerAppId, DataFileName);

            if (!File.Exists(filename))
            {
                return;
            }

            var ini = new IniFile(filename);

            ImportIfNeeded(carId, ini["Cars"].GetDouble(carId, 0d) * ini["Adjustments"].GetDouble(carId, 1d));
        }
Example #2
0
        private void UpdateDirectories() {
            CarsDirectories?.Obsolete();
            TracksDirectories?.Obsolete();
            ShowroomsDirectories?.Obsolete();
            WeatherDirectories?.Obsolete();
            PpFiltersDirectories?.Obsolete();
            DriverModelsDirectories?.Obsolete();
            PythonAppsDirectories?.Obsolete();

            CarsDirectories = Value == null ? null : new AcDirectories(AcPaths.GetCarsDirectory(Value));
            TracksDirectories = Value == null ? null : new AcDirectories(AcPaths.GetTracksDirectory(Value));
            ShowroomsDirectories = Value == null ? null : new AcDirectories(AcPaths.GetShowroomsDirectory(Value));
            WeatherDirectories = Value == null ? null : new AcDirectories(AcPaths.GetWeatherDirectory(Value));
            PpFiltersDirectories = Value == null ? null : new AcDirectories(AcPaths.GetPpFiltersDirectory(Value));
            DriverModelsDirectories = Value == null ? null : new AcDirectories(AcPaths.GetDriverModelsDirectory(Value));
            PythonAppsDirectories = Value == null ? null : new AcDirectories(AcPaths.GetPythonAppsDirectory(Value));
            FontsDirectories = Value == null ? null : new AcDirectories(AcPaths.GetFontsDirectory(Value));
            KunosCareerDirectories = Value == null ? null : new AcDirectories(AcPaths.GetKunosCareerDirectory(Value));

            FileUtils.EnsureDirectoryExists(AcPaths.GetReplaysDirectory());
            ReplaysDirectories = ReplaysDirectories ?? new MultiDirectories(AcPaths.GetReplaysDirectory(), null);
            UserChampionshipsDirectories = UserChampionshipsDirectories ?? new AcDirectories(Path.Combine(AcPaths.GetDocumentsDirectory(), "champs"));

            CarsDirectories?.CreateIfMissing();
            TracksDirectories?.CreateIfMissing();
            ShowroomsDirectories?.CreateIfMissing();
            WeatherDirectories?.CreateIfMissing();
            PpFiltersDirectories?.CreateIfMissing();
            DriverModelsDirectories?.CreateIfMissing();
            PythonAppsDirectories?.CreateIfMissing();
            UserChampionshipsDirectories?.CreateIfMissing();
        }
Example #3
0
        public static void UpdateSidekickDatabase([NotNull] CarObject car, bool?separateFiles = null)
        {
            try {
                var directory = Path.Combine(AcPaths.GetPythonAppsDirectory(AcRootDirectory.Instance.RequireValue), SidekickAppId);
                if (!Directory.Exists(directory))
                {
                    return;
                }

                if (!AcSettingsHolder.Python.IsActivated(SidekickAppId))
                {
                    Logging.Write("App is not active");
                    return;
                }

                if (car.AcdData?.IsEmpty != false)
                {
                    Logging.Write("Data is damaged");
                    return;
                }

                var kunosCar            = car.Author == AcCommonObject.AuthorKunos;
                var separateFilesActual = separateFiles ?? !kunosCar;
                var updateIfChanged     = kunosCar ? SettingsHolder.Drive.SidekickUpdateExistingKunos :
                                          SettingsHolder.Drive.SidekickUpdateExistingMods;

                UpdateSidekickCompounds(directory, car.AcdData, car.Id, separateFilesActual, updateIfChanged);
                UpdateSidekickBrakes(directory, car.AcdData, car.Id, separateFilesActual, updateIfChanged);
            } catch (Exception e) {
                Logging.Error(e);
            }
        }
Example #4
0
        public static void UpdateDatabase([NotNull] CarObject car, bool?separateFiles = null)
        {
            try {
                var directory = Path.Combine(AcPaths.GetPythonAppsDirectory(AcRootDirectory.Instance.RequireValue), AppId);
                if (!Directory.Exists(directory))
                {
                    return;
                }

                if (!AcSettingsHolder.Python.IsActivated(AppId))
                {
                    Logging.Write("App is not active");
                    return;
                }

                if (car.AcdData?.IsEmpty != false)
                {
                    Logging.Write("Data is damaged");
                    return;
                }

                var kunosCar = car.Author == AcCommonObject.AuthorKunos;
                if (kunosCar)
                {
                    return;
                }

                var filename = Path.Combine(directory, @"tyres_data", @"added-by-cm.json");
                var front    = new JObject();
                var rear     = new JObject();
                var tyres    = car.AcdData.GetIniFile("tyres.ini");
                foreach (var name in tyres.GetExistingSectionNames(@"FRONT", -1))
                {
                    Wrap(front, tyres[name]);
                    Wrap(rear, tyres[name.Replace(@"FRONT", @"REAR")]);
                    void Wrap(JObject target, IniFileSection section)
                    {
                        target[section.GetNonEmpty("SHORT_NAME") ?? @"_"] = new JObject {
                            [@"DCAMBER_0"] = section.GetDouble("DCAMBER_0", 1d),
                            [@"DCAMBER_1"] = section.GetDouble("DCAMBER_1", 1d),
                            [@"LS_EXPY"]   = section.GetDouble("LS_EXPY", 1d),
                        };
                    }
                }

                File.WriteAllText(filename, new JObject {
                    [car.Id] = new JObject {
                        [@"FRONT"] = front, [@"REAR"] = rear
                    }
                }.ToString(Formatting.Indented));
            } catch (Exception e) {
                Logging.Error(e);
            }
        }
Example #5
0
        /// <summary>
        /// Meters!
        /// </summary>
        private static IEnumerable <Tuple <string, double> > LoadDistances()
        {
            var filename = Path.Combine(AcPaths.GetPythonAppsDirectory(AcRootDirectory.Instance.RequireValue), SidekickAppId, OdometerDataFileName);

            if (!File.Exists(filename))
            {
                yield break;
            }
            foreach (var v in new IniFile(filename))
            {
                var carId = v.Key;
                var value = v.Value.GetDouble("odometer", 0d);
                if (value > 0)
                {
                    yield return(Tuple.Create(carId, value));
                }
            }
        }
Example #6
0
        private LapTimesManager()
        {
            _sources = new[] {
                new LapTimesSource(CmSourceId,
                                   "Own CM storage", "Filled using shared memory or, if disabled, race results file.",
                                   "Settings.LapTimesSettings.SourceCm", true, true,
                                   null, null),
                new LapTimesSource(AcNewSourceId,
                                   "New AC storage", "Used by the original launcher. Much faster and more stable.",
                                   "Settings.LapTimesSettings.SourceAcNew", true, true,
                                   () => new AcLapTimesNewReader(AcPaths.GetDocumentsDirectory(), this), () => TracksManager.Instance.EnsureLoadedAsync()),
#if AC_OLD_DB
                new LapTimesSource(AcOldSourceId,
                                   "Old AC database", "Used by the original launcher. Reading is quite wobbly, so I recommend to keep it disabled.",
                                   "Settings.LapTimesSettings.SourceAcDb", false, false,
                                   () => new AcLapTimesReader(FileUtils.GetDocumentsDirectory()), null),
#endif
                new LapTimesSource(SidekickSourceId,
                                   "Sidekick", "Very good source of lap times, accurate and reliable.",
                                   "Settings.LapTimesSettings.SourceSidekick", true, false,
                                   () => new SidekickLapTimesReader(GetSidekickDirectory(), this), () => TracksManager.Instance.EnsureLoadedAsync())
                {
                    DetailsUrl = "http://www.racedepartment.com/downloads/sidekick.11007/",
                    ExtraTools = { CreateSidekickFixTool(GetSidekickDirectory) }
                },
                new LapTimesSource(RaceEssentialsSourceId,
                                   "Race Essentials", "Quite good source of lap times as well.",
                                   "Settings.LapTimesSettings.SourceRaceEssentials", true, false,
                                   () => new SidekickLapTimesReader(GetRaceEssentialsDirectory(), this), () => TracksManager.Instance.EnsureLoadedAsync())
                {
                    DetailsUrl = "http://www.racedepartment.com/downloads/sidekick.11007/",
                    ExtraTools = { CreateSidekickFixTool(GetRaceEssentialsDirectory) }
                },
                new LapTimesSource(Ov1InfoSourceId,
                                   "Rivali OV1 Info",
                                   "Sadly, there is no information about entries date. If you need a patch for 64-bit AC or layouts support, you can get it [url=\"https://acstuff.ru/f/d/15-rivali-ov1-info\"]here[/url].",
                                   "Settings.LapTimesSettings.SourceOv1Info", false, false,
                                   () => new Ov1InfoLapTimesReader(
                                       Path.Combine(AcPaths.GetPythonAppsDirectory(AcRootDirectory.Instance.RequireValue), "OV1Info"),
                                       this), () => TracksManager.Instance.EnsureLoadedAsync()),
            };

            Entries = new BetterObservableCollection <LapTimeEntry>();
        }
Example #7
0
        /// <summary>
        /// Meters!
        /// </summary>
        private static IEnumerable <Tuple <string, double> > LoadDistances()
        {
            var filename = Path.Combine(AcPaths.GetPythonAppsDirectory(AcRootDirectory.Instance.RequireValue), OdometerAppId, DataFileName);

            if (!File.Exists(filename))
            {
                yield break;
            }

            var section = new IniFile(filename)["Cars"];

            foreach (var v in section)
            {
                var carId = v.Key;
                var value = v.Value.As <double>();
                if (value > 0)
                {
                    yield return(Tuple.Create(carId, value));
                }
            }
        }
Example #8
0
        public static void OdometerExport([NotNull] string carId)
        {
            if (carId == null)
            {
                throw new ArgumentNullException(nameof(carId));
            }

            var cmDistance = PlayerStatsManager.Instance.GetDistanceDrivenByCar(carId);

            if (!(cmDistance > 0d))
            {
                return;
            }

            var filename = Path.Combine(AcPaths.GetPythonAppsDirectory(AcRootDirectory.Instance.RequireValue), SidekickAppId, OdometerDataFileName);

            if (!File.Exists(filename))
            {
                return;
            }

            var ini         = new IniFile(filename);
            var section     = ini[carId];
            var appDistance = section.GetDouble("odometer", 0d) * 1e3;

            if (cmDistance <= appDistance + 100)
            {
                return;
            }

            section.Set("odometer", cmDistance / 1e3);

            if (!section.ContainsKey("odometer.originalvalue"))
            {
                section.Set("odometer.originalvalue", appDistance / 1e3);
            }

            ini.Save();
            Logging.Debug($"Driven distance for {carId} updated: app had {appDistance / 1e3:F1} km, CM has {cmDistance / 1e3:F1} km, which is more.");
        }
Example #9
0
        public static void Export([NotNull] string carId)
        {
            if (carId == null)
            {
                throw new ArgumentNullException(nameof(carId));
            }

            var cmDistance = PlayerStatsManager.Instance.GetDistanceDrivenByCar(carId);

            if (!(cmDistance > 0d))
            {
                return;
            }

            var filename = Path.Combine(AcPaths.GetPythonAppsDirectory(AcRootDirectory.Instance.RequireValue), OdometerAppId, DataFileName);

            if (!File.Exists(filename))
            {
                return;
            }

            var ini         = new IniFile(filename);
            var cars        = ini["Cars"];
            var multiplier  = ini["Adjustments"].GetDouble(carId, 1d);
            var appDistance = cars.GetDouble(carId, 0d) * multiplier;

            if (cmDistance <= appDistance + 100)
            {
                return;
            }

            cars.Set(carId, cmDistance / multiplier);
            if (!cars.ContainsKey(carId + ".originalvalue"))
            {
                cars.Set(carId + ".originalvalue", appDistance / multiplier);
            }

            ini.Save();
            Logging.Debug($"Driven distance for {carId} updated: app had {appDistance / 1e3:F1} km, CM has {cmDistance / 1e3:F1} km, which is more.");
        }
Example #10
0
        public static void OdometerImport([NotNull] string carId)
        {
            if (carId == null)
            {
                throw new ArgumentNullException(nameof(carId));
            }

            var cmDistance = PlayerStatsManager.Instance.GetDistanceDrivenByCar(carId);

            if (cmDistance <= 0d)
            {
                return;
            }

            var filename = Path.Combine(AcPaths.GetPythonAppsDirectory(AcRootDirectory.Instance.RequireValue), SidekickAppId, OdometerDataFileName);

            if (!File.Exists(filename))
            {
                return;
            }

            OdometerImportIfNeeded(carId, new IniFile(filename)[carId].GetDouble("odometer", 0d) * 1e3);
        }
Example #11
0
 private static IEnumerable <string> GetAvatarFilename()
 {
     return(OverlayAppIds.Select(x => Path.Combine(AcPaths.GetPythonAppsDirectory(AcRootDirectory.Instance.RequireValue), x, "images",
                                                   $"avatar_{AvatarId}.png")));
 }
Example #12
0
 private static string GetRaceEssentialsDirectory()
 {
     return(Path.Combine(AcPaths.GetPythonAppsDirectory(AcRootDirectory.Instance.RequireValue), "RaceEssentials"));
 }
Example #13
0
 private static string GetSidekickDirectory()
 {
     return(Path.Combine(AcPaths.GetPythonAppsDirectory(AcRootDirectory.Instance.RequireValue), "Sidekick"));
 }