Example #1
0
        public static string Compile(string fileName, string workspace, string template, string csl, string ext)
        {
            var arguments = new List <string>();

            arguments.AddRange(new string[] { "-f", "markdown", "--resource-path", workspace, "-V", $"resources={workspace.Replace('\\', '/')}", "--wrap=none" });
            var pdfName = Path.ChangeExtension(fileName, ".pdf");

            if (template == null)
            {
                arguments.Add("-s");
            }
            else
            {
                arguments.Add("--template");
                arguments.Add(template.Substring(0, template.LastIndexOf(".")));
            }

            if (csl != null)
            {
                arguments.Add("--csl");
                arguments.Add(csl);
            }

            foreach (var bibFile in Directory.GetFiles(workspace, "*.bib", SearchOption.AllDirectories))
            {
                arguments.Add("--bibliography");
                arguments.Add(bibFile);
            }

            arguments.Add("-o");
            arguments.Add(pdfName);

            arguments.Add("-t");
            arguments.Add("latex");

            foreach (var file in Directory.GetFiles(workspace, ext, SearchOption.AllDirectories))
            {
                arguments.Add(file);
            }

            var argumentList = new StringBuilder();

            foreach (var value in arguments)
            {
                argumentList.Append($"\"{value}\" ");
            }

            var argsString = argumentList.ToString();

            var exitCode = ProgramUtility.Execute("pandoc", argsString);

            if (exitCode != 0)
            {
                throw new InvalidProgramException("Pandoc finished unexpectedly");
            }
            File.Move(pdfName, fileName);
            return(fileName);
        }
Example #2
0
        public static async Task Update(IProgress <WebDownloadProgress> progress)
        {
            var bytes = await DownloadNewestVersion(progress);

            var tempFile = Path.GetTempFileName() + ".exe";
            var curFile  = Assembly.GetExecutingAssembly().Location;

            File.WriteAllBytes(tempFile, bytes);

            var sb = new StringBuilder();

            sb.AppendLine("@echo off");
            sb.AppendLine("timeout 2");
            sb.Append("copy /b/y \"").Append(tempFile).Append("\" \"").Append(curFile).AppendLine("\"");
            sb.Append("start \"\" \"").Append(curFile).AppendLine("\"");
            sb.AppendLine("exit");

            var tempBat = Path.GetTempFileName() + ".bat";

            File.WriteAllText(tempBat, sb.ToString());

            ProgramUtility.ExecuteNonWaiting(tempBat);
            Environment.Exit(0);
        }
Example #3
0
 public static bool Exists()
 {
     return(ProgramUtility.DoesExecute("pandoc", "-v"));
 }