コード例 #1
0
ファイル: FileListWindow.cs プロジェクト: wrightjjw/OpenSAGE
 private void AutoLoadImpl(string sourcePath,
                           string?mappedPath,
                           bool isFromGameFileSystem,
                           bool loadArtOnly)
 {
     if (!Path.EndsInDirectorySeparator(sourcePath))
     {
         sourcePath += Path.DirectorySeparatorChar;
     }
     var paths = isFromGameFileSystem
         ? TargetFileSystem.FindFiles(_ => true).Select(entry => entry.FilePath)
         : _autoDetect;
     var normalizedSourcePath = FileSystem.NormalizeFilePath(sourcePath);
     var filtered             = from path in paths
                                let normalized = FileSystem.NormalizeFilePath(path)
                                                 where normalized.StartsWith(normalizedSourcePath)
                                                 let relative = normalized[(normalizedSourcePath.Length)..]
コード例 #2
0
ファイル: FileListWindow.cs プロジェクト: wrightjjw/OpenSAGE
        public bool AutoLoad(string requiredAptFile, bool loadArtOnly)
        {
            requiredAptFile = FileSystem.NormalizeFilePath(requiredAptFile);
            var mappedPath = Path.GetDirectoryName(requiredAptFile);
            var name       = Path.GetFileName(requiredAptFile);

            var detectedFromGameFileSystem = TargetFileSystem
                                             .FindFiles(entry => Path.GetFileName(entry.FilePath) == name)
                                             .Select(entry => entry.FilePath)
                                             .ToArray();
            var detectedFromCustomFiles = _autoDetect
                                          .Where(path => FileSystem.NormalizeFilePath(Path.GetFileName(path)) == name);

            if (!detectedFromGameFileSystem.Any() && !detectedFromCustomFiles.Any())
            {
                return(false);
            }

            void Trace(string sourcePath, string from)
            {
                var text = $"Automatically loaded game:{sourcePath}  => game:{mappedPath} for {requiredAptFile}";

                Console.WriteLine(text + (loadArtOnly ? " (art)" : string.Empty));
            }

            foreach (var file in detectedFromCustomFiles)
            {
                var sourcePath = Path.GetDirectoryName(file);
                AutoLoadImpl(sourcePath !, mappedPath, isFromGameFileSystem: false, loadArtOnly);
                Trace(sourcePath !, "file");
            }

            foreach (var gameFile in detectedFromGameFileSystem)
            {
                var sourcePath = Path.GetDirectoryName(gameFile);
                AutoLoadImpl(sourcePath !, mappedPath, isFromGameFileSystem: true, loadArtOnly);
                Trace(sourcePath !, "game");
            }

            return(true);
        }