コード例 #1
0
        public void Execute()
        {
            var mapfiles = new MapFileCollection(this.Path);

            foreach (((var src, var trg), var i) in mapfiles.GetFiles().Select((x, i) => (x, i)))
            {
                Log.Info($"{(i + 1).ToString().PadRight(5)} {trg}");
            }
        }
コード例 #2
0
ファイル: Pk3Packer.cs プロジェクト: sibel1us/Pack3r
        public static void PackPk3(
            string path,
            MapFileCollection files,
            HashSet <Pk3File> stockFiles)
        {
            var folder = FileUtil.NewTempFolder;

            var stock = new HashSet <string>(stockFiles.Select(x => x.Path));

            foreach ((string source, string target) in files.GetFiles())
            {
                // If exact match found in stock files, skip
                if (stock.Contains(target))
                {
                    Log.Debug($"Skipping '{target}', exists in stock pk3s.");
                    continue;
                }

                string sourceFile = null;
                string targetFile = null;

                // Exact match
                if (File.Exists(source))
                {
                    sourceFile = source;
                    targetFile = target;
                }
                else if (Path.GetExtension(source) == "" ||
                         Path.GetExtension(source) == ".tga" ||
                         Path.GetExtension(source) == ".jpg")
                {
                    string ambiguous = null;

                    if (File.Exists(ambiguous = Path.ChangeExtension(source, "tga")))
                    {
                        Log.Debug($"Using found tga version for file {target}");
                        sourceFile = ambiguous;
                        targetFile = Path.ChangeExtension(target, "tga");
                    }
                    else if (stock.Contains(ambiguous))
                    {
                        Log.Debug($"TGA for missing file '{target}' found in stock pk3s");
                        continue;
                    }
                    else if (File.Exists(ambiguous = Path.ChangeExtension(source, "jpg")))
                    {
                        Log.Debug($"Using found jpg version for file {target}");
                        sourceFile = ambiguous;
                        targetFile = Path.ChangeExtension(target, "jpg");
                    }
                    else if (stock.Contains(ambiguous))
                    {
                        Log.Debug($"JPG for missing file '{target}' found in stock pk3s");
                        continue;
                    }
                }

                if (sourceFile == null || targetFile == null)
                {
                    Log.Error($"Cannot find '{target}' in filesystem or stock pk3s.");
                    continue;
                }

                var fullPathToTarget = Path.Combine(folder, targetFile);
                Directory.CreateDirectory(Path.GetDirectoryName(fullPathToTarget));
                File.Copy(sourceFile, fullPathToTarget, false);

                Log.Debug($" -> {targetFile}");
            }

            ZipFile.CreateFromDirectory(folder, path);
        }