예제 #1
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();
        }
예제 #2
0
        private static async Task <ArgumentHandleResult> ProcessInputFile(string filename)
        {
            bool isDirectory;

            try {
                if (!FileUtils.Exists(filename))
                {
                    return(ArgumentHandleResult.Failed);
                }
                isDirectory = FileUtils.IsDirectory(filename);
            } catch (Exception) {
                return(ArgumentHandleResult.Failed);
            }

            if (!isDirectory && filename.EndsWith(@".acreplay", StringComparison.OrdinalIgnoreCase) ||
                Path.GetDirectoryName(filename)?.Equals(AcPaths.GetReplaysDirectory(), StringComparison.OrdinalIgnoreCase) == true)
            {
                await GameWrapper.StartReplayAsync(new Game.StartProperties(new Game.ReplayProperties {
                    Filename = filename
                }));

                return(ArgumentHandleResult.Successful);
            }

            if (!isDirectory && filename.EndsWith(@".kn5", StringComparison.OrdinalIgnoreCase))
            {
                await CustomShowroomWrapper.StartAsync(filename);

                return(ArgumentHandleResult.Successful);
            }

            return(ArgumentHandleResult.FailedShow);
        }
예제 #3
0
        private static async Task PrepareReplay(Game.StartProperties properties, IGameUi ui, CancellationToken cancellation)
        {
            var replayProperties = properties.ReplayProperties;

            if (replayProperties != null)
            {
                var replayFilename = replayProperties.Filename ?? Path.Combine(AcPaths.GetReplaysDirectory(), replayProperties.Name);
                ui.OnProgress("Checking replay for fake cars…");

                var fakes = await FakeCarsHelper.GetFakeCarsIds(replayFilename);

                if (fakes.Count > 0)
                {
                    Logging.Debug("Fakes found: " + fakes.Select(x => $"{x.FakeId} ({x.SourceId})").JoinToString(", "));
                    foreach (var fake in fakes)
                    {
                        var car = CarsManager.Instance.GetById(fake.SourceId);
                        if (car != null)
                        {
                            FakeCarsHelper.CreateFakeCar(car, fake.FakeId, null);
                        }
                        else
                        {
                            Logging.Warning("Original not found: " + fake.SourceId);
                        }
                    }
                }
            }
        }
예제 #4
0
        private static async Task <ArgumentHandleResult> ProcessInputFile(string filename)
        {
            bool isDirectory;

            try {
                if (!FileUtils.Exists(filename))
                {
                    return(ArgumentHandleResult.Failed);
                }
                isDirectory = FileUtils.IsDirectory(filename);
            } catch (Exception) {
                return(ArgumentHandleResult.Failed);
            }

            if (!isDirectory && filename.EndsWith(@".acreplay", StringComparison.OrdinalIgnoreCase) ||
                Path.GetDirectoryName(filename)?.Equals(AcPaths.GetReplaysDirectory(), StringComparison.OrdinalIgnoreCase) == true)
            {
                await GameWrapper.StartReplayAsync(new Game.StartProperties(new Game.ReplayProperties {
                    Filename = filename
                }));

                return(ArgumentHandleResult.Successful);
            }

            if (!isDirectory && filename.EndsWith(@".kn5", StringComparison.OrdinalIgnoreCase))
            {
                if ((Keyboard.Modifiers == ModifierKeys.Alt || Keyboard.Modifiers == ModifierKeys.Shift) && SettingsHolder.Common.DeveloperMode)
                {
                    try {
                        Kn5.FbxConverterLocation = PluginsManager.Instance.GetPluginFilename("FbxConverter", "FbxConverter.exe");
                        var kn5         = Kn5.FromFile(filename);
                        var destination = FileUtils.EnsureUnique(Path.Combine(Path.GetDirectoryName(filename) ?? @".",
                                                                              $"unpacked-{Path.GetFileName(filename)}"));
                        var name = kn5.RootNode.Name.StartsWith(@"FBX: ") ? kn5.RootNode.Name.Substring(5) :
                                   @"model.fbx";
                        Directory.CreateDirectory(destination);
                        await kn5.ExportFbxWithIniAsync(Path.Combine(destination, name));

                        var textures = Path.Combine(destination, "texture");
                        Directory.CreateDirectory(textures);
                        await kn5.ExportTexturesAsync(textures);

                        Process.Start(destination);
                    } catch (Exception e) {
                        Logging.Error(e);
                        return(ArgumentHandleResult.FailedShow);
                    }
                }
                else
                {
                    await CustomShowroomWrapper.StartAsync(filename);
                }

                return(ArgumentHandleResult.Successful);
            }

            return(ArgumentHandleResult.FailedShow);
        }
예제 #5
0
 public static bool HasWithExtension()
 {
     try {
         return(Directory.GetFiles(AcPaths.GetReplaysDirectory()).Any(file => file.EndsWith(ReplayObject.ReplayExtension)));
     } catch (Exception e) {
         Logging.Error("Can’t get files with extension: " + e);
         return(false);
     }
 }
예제 #6
0
 private ReplaysExtensionSetter()
 {
     try {
         _previous = Directory.GetFiles(AcPaths.GetReplaysDirectory());
     } catch (Exception e) {
         Logging.Error("Can’t get files: " + e);
         _previous = new string[0];
     }
 }
예제 #7
0
 private static IEnumerable <string> GetWithoutExtension()
 {
     try {
         return(Directory.GetFiles(AcPaths.GetReplaysDirectory(), "*", SearchOption.AllDirectories)
                .Where(file => !file.EndsWith(ReplayObject.ReplayExtension, StringComparison.OrdinalIgnoreCase) &&
                       !string.Equals(Path.GetFileName(file), @"cr", StringComparison.OrdinalIgnoreCase)));
     } catch (Exception e) {
         Logging.Error("Can’t get files without extension: " + e);
         return(new string[0]);
     }
 }
예제 #8
0
파일: Game.cs 프로젝트: windygu/actools
            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;
            }