Ejemplo n.º 1
0
            internal void Set()
            {
                _disposeLater = new List <IDisposable>();
                _removeLater  = new List <string>();

                var iniFilename = AcPaths.GetRaceIniFilename();

                if (OptionEnableRaceIniRestoration)
                {
                    _disposeLater.Add(FileUtils.RestoreLater(iniFilename));
                }

                var iniFile = PreparedConfig;

                if (iniFile == null)
                {
                    iniFile = new IniFile(iniFilename);

                    ClearUpIniFile(iniFile);
                    SetDefaultProperies(iniFile);

                    if (BasicProperties != null)
                    {
                        BasicProperties?.Set(iniFile);
                        ModeProperties?.Set(iniFile);
                        ConditionProperties?.Set(iniFile);
                        TrackProperties?.Set(iniFile);
                    }
                    else if (ReplayProperties != null)
                    {
                        if (ReplayProperties.Name == null && ReplayProperties.Filename != null)
                        {
                            var dir = AcPaths.GetReplaysDirectory();
                            if (Path.GetDirectoryName(ReplayProperties.Filename)?.Equals(dir, StringComparison.OrdinalIgnoreCase) == true)
                            {
                                ReplayProperties.Name = Path.GetFileName(ReplayProperties.Filename);
                            }
                            else
                            {
                                var removeLaterFilename = FileUtils.GetTempFileName(dir, ".tmp");
                                ReplayProperties.Name = Path.GetFileName(removeLaterFilename);
                                File.Copy(ReplayProperties.Filename, removeLaterFilename);
                                _removeLater.Add(removeLaterFilename);
                            }
                        }

                        ReplayProperties.Set(iniFile);
                    }
                    else if (BenchmarkProperties != null)
                    {
                        BenchmarkProperties.Set(iniFile);
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }
                }

                foreach (var properties in AdditionalPropertieses.OfType <RaceIniProperties>())
                {
                    properties.Set(iniFile);
                }

                iniFile.Save(iniFilename);

                _disposeLater.AddRange(AdditionalPropertieses.OfType <AdditionalProperties>().Select(x => x.Set())
                                       .Prepend(AssistsProperties?.Set()).NonNull());

                StartTime = DateTime.Now;
            }