コード例 #1
0
        private IList <FileInfo> ProcessTtfFonts(Config config, IList <FileInfo> fonts, ProgressBar pb)
        {
            var failureList = new List <FileInfo>();

            if (!fonts.Any())
            {
                return(failureList);
            }

            pb.StartProcessingTtf();

            foreach (var font in fonts)
            {
                pb.StartProcessingTtf(font.Name);
                // X: & cd "{TtxExeDirectory}" & ttx.exe -o "{OutputDirectory}\{fontName}" -m "{InputDirectory}\{fontName}" GaspHack.ttx
                var exitCode = CmdExecutor.ExecuteCommand(
                    $"{config.TtxExeDirectory.Substring(0, 2)} & cd \"{config.TtxExeDirectory}\" & ttx.exe -o \"{Path.Combine(config.OutputDirectory, font.Name)}\" -m \"{font.FullName}\" GaspHack.ttx");
                if (exitCode != 0)
                {
                    failureList.Add(font);
                }

                pb.DoneProcessingTtf(font.Name);
            }

            // # {InputDirectory}\*.ttf should == # {OutputDirectory}\*.ttf + # failure fonts
            Debug.Assert(fonts.Count ==
                         Directory.EnumerateFiles(config.OutputDirectory, "*.*").Count(it => it.ToLowerInvariant().EndsWith(".ttf")) +
                         failureList.Count);

            pb.DoneProcessingTtf();

            return(failureList);
        }
コード例 #2
0
        private IList <FileInfo> ProcessTtcFonts(Config config, IList <FileInfo> fonts, ProgressBar pb)
        {
            var failureList = new List <FileInfo>();

            if (!fonts.Any())
            {
                return(failureList);
            }

            var tempInputDirectory = Path.Combine(config.InputDirectory, "temp");

            if (!Directory.Exists(tempInputDirectory))
            {
                // Create a temp folder in the input folder
                Directory.CreateDirectory(tempInputDirectory);
            }
            else
            {
                // Clean the temp files
                DirectoryCleaner.CleanDirectoryAsync(tempInputDirectory).Wait();
            }

            // Create a temp folder in the output folder
            var tempOutputDirectory = Path.Combine(config.OutputDirectory, "temp");

            if (!Directory.Exists(tempOutputDirectory))
            {
                // Create a temp folder in the input folder
                Directory.CreateDirectory(tempOutputDirectory);
            }
            else
            {
                // Clean the temp files
                DirectoryCleaner.CleanDirectoryAsync(tempOutputDirectory).Wait();
            }

            pb.StartProcessingTtc();

            foreach (var font in fonts)
            {
                pb.StartProcessingTtc(font.Name);

                // X: & cd {InputDirectory}\temp & call "{AfdkoDirectory}\otc2otf.cmd" "{fontFullname}"
                pb.StartExtractingTtc(font.Name);
                var exitCode =
                    CmdExecutor.ExecuteCommand(
                        $"{tempInputDirectory.Substring(0, 2)} & cd \"{tempInputDirectory}\" & call \"{Path.Combine(config.AfdkoDirectory, "otc2otf.cmd")}\" \"{font.FullName}\"");

                Debug.Assert(exitCode == 0); // TODO
                if (exitCode != 0)
                {
                    failureList.Add(font);
                }
                else
                {
                    pb.StartProcessingExtractedFilesOf(font.Name);
                    var extractedTtfFiles = Directory.GetFiles(tempInputDirectory);
                    Debug.Assert(extractedTtfFiles.Any());
                    var exitCode2 = 0;
                    // Gasphack the extracted TTF files. Note that they should be processed in order of creation time to maintain the same order as the components in the original TTC file.
                    foreach (var extractedTtf in extractedTtfFiles.Select(it => new FileInfo(it)).OrderBy(it => it.CreationTimeUtc))
                    {
                        // X: & cd "{TtxExeDirectory}" & ttx.exe -o "{OutputDirectory}\temp\{fontName}" -m "{InputDirectory}\temp\{fontName}" GaspHack.ttx
                        exitCode2 = CmdExecutor.ExecuteCommand(
                            $"{config.TtxExeDirectory.Substring(0, 2)} & cd \"{config.TtxExeDirectory}\" & ttx.exe -o \"{Path.Combine(tempOutputDirectory, extractedTtf.Name)}\" -m \"{extractedTtf.FullName}\" GaspHack.ttx");
                        Debug.Assert(exitCode2 == 0); // TODO
                        if (exitCode2 != 0)
                        {
                            break;
                        }
                    }

                    if (exitCode2 != 0)
                    {
                        failureList.Add(font);
                    }
                    else
                    {
                        Debug.Assert(Directory.EnumerateFiles(tempOutputDirectory).Any());
                        pb.StartBuildingProcessedTtc(font.Name);
                        // X: & cd "{OutputDirectory}" & call "{AfdkoDirectory}\otf2otc.cmd" -o "{OutputDirectory}\{fontName}" "{OutputDirectory}\temp\1.ttf" "{OutputDirectory}\temp\2.ttf" ...
                        // Note that the input files should be ordered be creation time to maintain the same order as the components in the original TTC file.
                        var command = $"{config.OutputDirectory.Substring(0, 2)} & cd \"{config.OutputDirectory}\" & call \"{Path.Combine(config.AfdkoDirectory, "otf2otc.cmd")}\" -o \"{Path.Combine(config.OutputDirectory, font.Name)}\" ";
                        command = Directory.EnumerateFiles(tempOutputDirectory).Select(it => new FileInfo(it)).OrderBy(it => it.CreationTimeUtc)
                                  .Aggregate(command,
                                             (current, processedExtractedTtf) => current + $"\"{processedExtractedTtf.FullName}\" ");

                        var exitCode3 = CmdExecutor.ExecuteCommand(command);
                        Debug.Assert(exitCode3 == 0); // TODO
                        if (exitCode3 != 0)
                        {
                            failureList.Add(font);
                        }
                    }
                }

                // Clean the temp files
                Task.WaitAll(
                    DirectoryCleaner.CleanDirectoryAsync(tempInputDirectory),
                    DirectoryCleaner.CleanDirectoryAsync(tempOutputDirectory)
                    );
                pb.DoneProcessingTtc(font.Name);
            }

            // Delete the temp folders
            Debug.Assert(!Directory.EnumerateFiles(tempInputDirectory).Any());
            Debug.Assert(!Directory.EnumerateFiles(tempOutputDirectory).Any());
            try
            {
                Directory.Delete(tempInputDirectory);
                Directory.Delete(tempOutputDirectory);
            }
            catch (IOException)
            {
                // Doesn't matter if the temp folder is occupied.
            }

            // # {InputDirectory}\*.ttc should == # {OutputDirectory}\*.ttc + # failure fonts
            Debug.Assert(fonts.Count ==
                         Directory.EnumerateFiles(config.OutputDirectory, "*.*").Count(it => it.ToLowerInvariant().EndsWith(".ttc")) +
                         failureList.Count);

            pb.DoneProcessingTtc();

            return(failureList);
        }
コード例 #3
0
 public static void Run()
 {
     CmdExecutor.ExecuteCommand("D: & mkdir aaa", true);
 }