コード例 #1
0
        private void Load()
        {
            if (_acd != null || Mode == StorageMode.AcdFile)
            {
                // ReSharper disable once AssignNullToNotNullAttribute
                // with StorageMode.AcdFile, Filename is not null
                // TODO: sort everything better
                var acd = _acd ?? Acd.FromFile(Filename);

                var entry = acd.GetEntry(Name);
                if (entry != null)
                {
                    ParseString(entry.ToString());
                }
                else
                {
                    Clear();
                }
            }
            else if (Filename != null && File.Exists(Filename))
            {
                ParseString(File.ReadAllText(Filename));
            }
            else
            {
                Clear();
            }
        }
コード例 #2
0
        public static Task <List <string> > TestData(string carDir, double weight)
        {
            return(Task.Run(() => {
                var errors = new List <string>();

                try {
                    var acdFile = Path.Combine(carDir, "data.acd");
                    var acd = File.Exists(acdFile) ? Acd.FromFile(acdFile) : null;

                    var aeroIni = new IniFile(carDir, "aero.ini", acd);
                    if (aeroIni.ContainsKey("DATA"))
                    {
                        errors.Add("acd-obsolete-aero-data");
                    }

                    if (weight > 0)
                    {
                        var carIni = new IniFile(carDir, "car.ini", acd);
                        if (Math.Abs(weight + 75.0 - carIni["BASIC"].GetDouble("TOTALMASS", 0d)) > 90.0)
                        {
                            errors.Add("acd-invalid-weight");
                        }
                    }
                } catch (Exception) {
                    errors.Add("acd-test-error");
                }

                GC.Collect();
                return errors;
            }));
        }
コード例 #3
0
ファイル: DataWrapper.cs プロジェクト: Abishai2007/actools
        private DataWrapper(string carDirectory)
        {
            _carDirectory = carDirectory;
            _cache        = new Dictionary <string, AbstractDataFile>();

            var dataAcd = Path.Combine(carDirectory, "data.acd");

            if (File.Exists(dataAcd))
            {
                _acd     = Acd.FromFile(dataAcd);
                IsPacked = true;
            }
            else
            {
                var dataDirectory = Path.Combine(carDirectory, "data");
                if (Directory.Exists(dataDirectory))
                {
                    _acd = Acd.FromDirectory(dataDirectory);
                }
                else
                {
                    IsEmpty = true;
                }
            }
        }
コード例 #4
0
ファイル: DataWrapper.cs プロジェクト: Abishai2007/actools
        public void Refresh([CanBeNull] string localName)
        {
            lock (_cache) {
                if (localName == null)
                {
                    _cache.Clear();
                }
                else if (_cache.ContainsKey(localName))
                {
                    _cache.Remove(localName);
                }

                var dataAcd = Path.Combine(_carDirectory, "data.acd");
                if (File.Exists(dataAcd))
                {
                    if (!IsPacked)
                    {
                        _cache.Clear();
                    }

                    _acd     = Acd.FromFile(dataAcd);
                    IsPacked = true;
                    IsEmpty  = false;
                }
                else
                {
                    if (IsPacked)
                    {
                        _cache.Clear();
                    }

                    IsPacked = false;

                    var dataDirectory = Path.Combine(_carDirectory, "data");
                    if (Directory.Exists(dataDirectory))
                    {
                        _acd    = Acd.FromDirectory(dataDirectory);
                        IsEmpty = false;
                    }
                    else
                    {
                        IsEmpty = true;
                    }
                }

                OnDataChanged(localName);
            }
        }
コード例 #5
0
ファイル: ActionTest.cs プロジェクト: wxl-007/ShadowDota
        public Full(Action end)
        {
            //ThreadPool.QueueUserWorkItem( o => {
            array = new int[3];
            for (int i = 0; i < 3; ++i)
            {
                array[i] = i;
            }

            acd = new Acd();
            if (end != null)
            {
                end();
            }
            //});
        }
コード例 #6
0
        private void UpdateAcd(bool backup)
        {
            var acd = _acd;

            if (acd != null)
            {
                if (acd.IsPacked)
                {
                    acd.SetEntry(Name, Stringify());
                    acd.Save(_acdFilename);
                }
                else
                {
                    SaveTo(acd.GetFilename(Name), backup);
                }
            }
            else
            {
                var filename = Filename;
                if (filename == null)
                {
                    throw new Exception("File wasn’t loaded to be saved like this");
                }

                acd = Acd.FromFile(filename);
                acd.SetEntry(Name, Stringify());

                if (File.Exists(filename))
                {
                    if (backup)
                    {
                        FileUtils.Recycle(filename);
                    }
                    else
                    {
                        File.Delete(filename);
                    }
                }

                acd.Save(filename);
            }
        }
コード例 #7
0
ファイル: DataWrapper.cs プロジェクト: tankyx/actools
        protected override void RefreshOverride(string name)
        {
            var dataAcd = Path.Combine(ParentDirectory, "data.acd");

            if (File.Exists(dataAcd))
            {
                if (!IsPacked)
                {
                    ClearCache();
                }

                _acd = Acd.FromFile(dataAcd);
                SetIsPacked(true);
                SetIsEmpty(false);
            }
            else
            {
                if (IsPacked)
                {
                    ClearCache();
                }

                SetIsPacked(false);

                var dataDirectory = Path.Combine(ParentDirectory, "data");
                if (Directory.Exists(dataDirectory))
                {
                    _acd = Acd.FromDirectory(dataDirectory);
                    SetIsEmpty(false);
                }
                else
                {
                    SetIsEmpty(true);
                }
            }

            OnDataChanged(name);
        }
コード例 #8
0
ファイル: DataWrapper.cs プロジェクト: tankyx/actools
        private DataWrapper([NotNull] string carDirectory)
        {
            ParentDirectory = carDirectory;

            var dataAcd = Path.Combine(carDirectory, PackedFileName);

            if (File.Exists(dataAcd))
            {
                _acd = Acd.FromFile(dataAcd);
                SetIsPacked(true);
            }
            else
            {
                var dataDirectory = Path.Combine(carDirectory, UnpackedDirectoryName);
                if (Directory.Exists(dataDirectory))
                {
                    _acd = Acd.FromDirectory(dataDirectory);
                }
                else
                {
                    SetIsEmpty(true);
                }
            }
        }
コード例 #9
0
        protected AbstractDataFile(string carDir, string name, Acd acd)
        {
            Name         = name;
            _acdFilename = Path.Combine(carDir, "data.acd");

            if (acd != null)
            {
                _acd = acd;

                if (acd.IsPacked)
                {
                    Mode     = StorageMode.AcdFile;
                    Filename = null;
                }
                else
                {
                    Mode     = StorageMode.UnpackedFile;
                    Filename = acd.GetFilename(Name);
                }
            }
            else
            {
                if (File.Exists(_acdFilename))
                {
                    Mode     = StorageMode.AcdFile;
                    Filename = _acdFilename;
                }
                else
                {
                    Mode     = StorageMode.UnpackedFile;
                    Filename = Path.Combine(carDir, "data", name);
                }
            }

            Load();
        }
コード例 #10
0
 public RtoDataFile(string carDir, string filename, Acd loadedAcd) : base(carDir, filename, loadedAcd)
 {
 }
コード例 #11
0
ファイル: App.xaml.cs プロジェクト: WildGenie/actools
        private async void BackgroundInitialization()
        {
            try {
                await Task.Delay(1000);

                if (AppArguments.Has(AppFlag.TestIfAcdAvailable) && !Acd.IsAvailable())
                {
                    NonfatalError.NotifyBackground(@"This build can’t work with encrypted ACD-files");
                }

                if (AppUpdater.JustUpdated && SettingsHolder.Common.ShowDetailedChangelog)
                {
                    List <ChangelogEntry> changelog;
                    try {
                        changelog =
                            await Task.Run(() => AppUpdater.LoadChangelog().Where(x => x.Version.IsVersionNewerThan(AppUpdater.PreviousVersion)).ToList());
                    } catch (WebException e) {
                        NonfatalError.NotifyBackground(AppStrings.Changelog_CannotLoad, ToolsStrings.Common_MakeSureInternetWorks, e);
                        return;
                    } catch (Exception e) {
                        NonfatalError.NotifyBackground(AppStrings.Changelog_CannotLoad, e);
                        return;
                    }

                    Logging.Debug("Changelog entries: " + changelog.Count);
                    if (changelog.Any())
                    {
                        Toast.Show(AppStrings.App_AppUpdated, AppStrings.App_AppUpdated_Details, () => {
                            ModernDialog.ShowMessage(changelog.Select(x => $@"[b]{x.Version}[/b]{Environment.NewLine}{x.Changes}")
                                                     .JoinToString(Environment.NewLine.RepeatString(2)), AppStrings.Changelog_RecentChanges_Title,
                                                     MessageBoxButton.OK);
                        });
                    }
                }

                await Task.Delay(1500);

                PresetsPerModeBackup.Revert();
                WeatherSpecificCloudsHelper.Revert();
                WeatherSpecificTyreSmokeHelper.Revert();
                WeatherSpecificVideoSettingsHelper.Revert();
                CarSpecificControlsPresetHelper.Revert();
                CopyFilterToSystemForOculusHelper.Revert();

                await Task.Delay(1500);

                CustomUriSchemeHelper.EnsureRegistered();

                await Task.Delay(5000);

                await Task.Run(() => {
                    foreach (var f in from file in Directory.GetFiles(FilesStorage.Instance.GetDirectory("Logs"))
                             where file.EndsWith(@".txt") || file.EndsWith(@".log") || file.EndsWith(@".json")
                             let info = new FileInfo(file)
                                        where info.LastWriteTime < DateTime.Now - TimeSpan.FromDays(3)
                                        select info)
                    {
                        f.Delete();
                    }
                });
            } catch (Exception e) {
                Logging.Error(e);
            }
        }
コード例 #12
0
 public IniFile(string carDir, string filename, Acd loadedAcd, IniFileMode mode) : base(carDir, InnerIniFileModeTrick(filename, mode), loadedAcd)
 {
     _trickIniFileMode = null;
     _iniFileMode      = mode;
 }
コード例 #13
0
 public IniFile(string carDir, string filename, Acd loadedAcd) : this(carDir, filename, loadedAcd, IniFileMode.Normal)
 {
 }
コード例 #14
0
        private static async void BackgroundInitialization()
        {
            try {
                await Task.Delay(500);

                AppArguments.Set(AppFlag.SimilarThreshold, ref CarAnalyzer.OptionSimilarThreshold);

                string additional = null;
                AppArguments.Set(AppFlag.SimilarAdditionalSourceIds, ref additional);
                if (!string.IsNullOrWhiteSpace(additional))
                {
                    CarAnalyzer.OptionSimilarAdditionalSourceIds = additional.Split(';', ',').Select(x => x.Trim()).Where(x => x.Length > 0).ToArray();
                }

                await Task.Delay(500);

                if (AppArguments.Has(AppFlag.TestIfAcdAvailable) && !Acd.IsAvailable())
                {
                    NonfatalError.NotifyBackground(@"This build can’t work with encrypted ACD-files");
                }

                if (AppUpdater.JustUpdated && SettingsHolder.Common.ShowDetailedChangelog)
                {
                    List <ChangelogEntry> changelog;
                    try {
                        changelog = await Task.Run(() =>
                                                   AppUpdater.LoadChangelog().Where(x => x.Version.IsVersionNewerThan(AppUpdater.PreviousVersion)).ToList());
                    } catch (WebException e) {
                        NonfatalError.NotifyBackground(AppStrings.Changelog_CannotLoad, ToolsStrings.Common_MakeSureInternetWorks, e);
                        return;
                    } catch (Exception e) {
                        NonfatalError.NotifyBackground(AppStrings.Changelog_CannotLoad, e);
                        return;
                    }

                    Logging.Debug("Changelog entries: " + changelog.Count);
                    if (changelog.Any())
                    {
                        Toast.Show(AppStrings.App_AppUpdated, AppStrings.App_AppUpdated_Details, () => {
                            ModernDialog.ShowMessage(changelog.Select(x => $@"[b]{x.Version}[/b]{Environment.NewLine}{x.Changes}")
                                                     .JoinToString(Environment.NewLine.RepeatString(2)), AppStrings.Changelog_RecentChanges_Title,
                                                     MessageBoxButton.OK);
                        });
                    }
                }

                await Task.Delay(1500);

                RevertFileChanges();

                await Task.Delay(1500);

                CustomUriSchemeHelper.EnsureRegistered();

                await Task.Delay(5000);

                await Task.Run(() => {
                    foreach (var f in from file in Directory.GetFiles(FilesStorage.Instance.GetDirectory("Logs"))
                             where file.EndsWith(@".txt") || file.EndsWith(@".log") || file.EndsWith(@".json")
                             let info = new FileInfo(file)
                                        where info.LastWriteTime < DateTime.Now - TimeSpan.FromDays(3)
                                        select info)
                    {
                        f.Delete();
                    }
                });
            } catch (Exception e) {
                Logging.Error(e);
            }
        }
コード例 #15
0
ファイル: RulesSet_Test.cs プロジェクト: WildGenie/actools
        public string GetHash(string carDir)
        {
            var acdFilename = Path.Combine(carDir, "data.acd");
            var acdFile     = File.Exists(acdFilename) ? Acd.FromFile(acdFilename) : null;

            var files  = new Dictionary <string, IniFile>();
            var result = new StringBuilder();

            foreach (var rule in _rules)
            {
                if (!files.ContainsKey(rule.Filename))
                {
                    files[rule.Filename] = new IniFile(carDir, rule.Filename, acdFile);
                }

                var file = files[rule.Filename];

                if (file[rule.Section].ContainsKey(rule.Property))
                {
                    var propertyValue = file[rule.Section].GetPossiblyEmpty(rule.Property)?.Trim();
                    if (propertyValue == null)
                    {
                        continue;
                    }

                    switch (rule.Type)
                    {
                    case RuleType.Vector2:
                    case RuleType.Vector3:
                    case RuleType.Vector4: {
                        if (propertyValue.Length == 0)
                        {
                            break;
                        }

                        var value = propertyValue.Split(',').Select(x => {
                                double parsed;
                                double.TryParse(x.Trim(), NumberStyles.Any,
                                                CultureInfo.InvariantCulture, out parsed);
                                return(parsed);
                            }).ToList();
                        var len = rule.Type == RuleType.Vector2 ? 2 : rule.Type == RuleType.Vector3 ? 3 : 4;
                        if (value.Count == len)
                        {
                            for (var i = 0; i < len; i++)
                            {
                                if (i > 0)
                                {
                                    result.Append(",");
                                }

                                value[i] /= rule.GetDoubleParam(i, rule.GetDoubleParam(0, 1.0));
                                result.Append(Math.Round(value[i]).ToString("F0"));
                            }
                        }
                        break;
                    }

                    case RuleType.Number: {
                        double parsed;
                        double.TryParse(propertyValue, NumberStyles.Any, CultureInfo.InvariantCulture,
                                        out parsed);

                        parsed /= rule.GetDoubleParam(0, 1.0);
                        result.Append(Math.Round(parsed).ToString("F0"));
                        break;
                    }

                    case RuleType.String: {
                        result.Append(propertyValue);
                        break;
                    }
                    }
                }

                result.Append("\n");
            }

            return(Convert.ToBase64String(Encoding.UTF8.GetBytes(result.ToString())));
        }
コード例 #16
0
ファイル: FakeCarsHelper.cs プロジェクト: windygu/actools
        public static void CreateFakeCar([NotNull] CarObject source, string fakeCarId, [CanBeNull] Action <Acd> dataPreprocessor)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            var sw = Stopwatch.StartNew();

            try {
                var path      = Path.Combine(CarsManager.Instance.Directories.GetMainDirectory(), fakeCarId);
                var directory = new DirectoryInfo(path);
                if (!directory.Exists)
                {
                    FileUtils.HardLinkOrCopyRecursive(source.Location, path, (filename, isDirectory) => {
                        if (isDirectory)
                        {
                            return(false);
                        }
                        var relative = FileUtils.GetRelativePath(filename, source.Location).ToLower();
                        return(Regex.IsMatch(relative,
                                             @"^(?:animations\\\w*\.ksanim|skins\\[^\\]+\\(?!preview(?:_original)?\.jpg|ui_skin\.json)|texture\\|[^\\]+\.kn5|body_shadow\.png|tyre_shadow_\d\.png|driver_base_pos\.knh)"));
                    }, true);

                    CarObject.ReplaceSound(source, path);
                }
                else
                {
                    var now = DateTime.Now;
                    if ((now - directory.LastWriteTime).TotalMinutes > 1d)
                    {
                        return;
                    }

                    directory.LastWriteTime = now;
                }

                var dataFilename = Path.Combine(source.Location, "data.acd");
                Acd acd;
                if (File.Exists(dataFilename))
                {
                    acd = Acd.FromFile(dataFilename);
                }
                else
                {
                    var dataDirectory = Path.Combine(source.Location, "data");
                    if (Directory.Exists(dataDirectory))
                    {
                        acd = Acd.FromDirectory(dataDirectory);
                    }
                    else
                    {
                        return;
                    }
                }

                dataPreprocessor?.Invoke(acd);
                acd.Save(Path.Combine(path, "data.acd"));
            } finally {
                Logging.Debug($"Time taken to create {fakeCarId}: {sw.Elapsed.TotalMilliseconds:F1} ms");
            }
        }