예제 #1
0
        protected static (string certPass, string SignToolArgs) MakeSignToolArgs(BuildContext ctx, string timestampUrl)
        {
            var ap = ctx.GetArtifactPackage();

            var pc = ctx.Config.GetProductConfig(ap.TargetName);

            var(certFile, certPass) = ctx.GetCertificate();

            return(
                certPass,
                string.Join(' ',
                            "sign",
                            "/v",
                            "/debug",
                            "/fd", "SHA256",
                            "/tr", timestampUrl.Quote(),
                            "/td", "SHA256",
                            "/d", pc.PublishedName.Quote(),
                            "/du", pc.PublishedUrl,
                            "/f", certFile.Quote(),
                            "/p", certPass.Quote(),

                            // extra space before binary name
                            string.Empty)
                );
        }
예제 #2
0
        public static Task RunAsync(BuildContext ctx)
        {
            var ap = ctx.GetArtifactPackage();

            var destDir = Path.Combine(ctx.InDir, Path.GetFileNameWithoutExtension(ap.FileName));

            using var zf = ZipFile.Read(Path.Combine(ctx.InDir, ap.FileName));

            var firstEntryPath = zf.Entries.First().FileName;

            var archiveRootDir = firstEntryPath
                                 .Substring(0, firstEntryPath.IndexOfAny(new[] { '/', '\\' }));

            bool allDirsRooted = zf.Entries
                                 .All(itm => itm.FileName.StartsWith(archiveRootDir));

            if (!allDirsRooted)
            {
                throw new InvalidDataException(
                          $"Unexpected non-uniform root directory in product archive '{ap.FileName}'");
            }

            Directory.CreateDirectory(destDir);

            int totalItems  = zf.Count;
            int currentItem = 0;

            foreach (var itm in zf.Entries)
            {
                var fname = itm.FileName.Substring(archiveRootDir.Length + 1);

                if (itm.IsDirectory)
                {
                    Directory.CreateDirectory(
                        Path.Combine(destDir, fname));
                }
                else
                {
                    using var fs = File.Open(
                              Path.Combine(destDir, fname),
                              FileMode.Create,
                              FileAccess.Write);

                    itm.Extract(fs);
                }

                double progress = ((++currentItem * 100.0) / totalItems);
                if (progress % 10 == 0)
                {
                    Console.WriteLine((int)progress + "%");
                }
            }

            Console.WriteLine($"Extracted to: {destDir}");

            return(Task.CompletedTask);
        }
예제 #3
0
        public static async Task RunAsync(BuildContext ctx)
        {
            var ap = ctx.GetArtifactPackage();

            var destDir = Path.Combine(ctx.InDir, Path.GetFileNameWithoutExtension(ap.FileName));

            var di = new DirectoryInfo(destDir);

            if (!di.Exists)
            {
                using var zf = ZipFile.Open(Path.Combine(ctx.InDir, ap.FileName), ZipArchiveMode.Read);
                zf.ExtractToDirectory(destDir);
            }
            await Console.Out.WriteLineAsync($"Extracted to: {destDir}");
        }
        public static async Task RunAsync(BuildContext ctx)
        {
            var ap = ctx.GetArtifactPackage();

            var SignToolExePath = Path.Combine(
                ctx.ToolsDir,
                MagicStrings.Dirs.Cert,
                MagicStrings.Files.SignToolExe);

            foreach (var binary in ctx.Config.GetProductConfig(ap.TargetName).PublishedBinaries)
            {
                bool signed   = false;
                int  tryCount = ctx.Config.TimestampUrls.Count;

                for (int tryNr = 0; tryNr < tryCount; ++tryNr)
                {
                    var timestampUrl = ctx.Config.TimestampUrls[tryNr];
                    var(certPass, SignToolArgs) = MakeSignToolArgs(ctx, timestampUrl);

                    var FullSignToolArgs = SignToolArgs + Path
                                           .Combine(ctx.InDir, Path.GetFileNameWithoutExtension(ap.FileName), binary)
                                           .Quote();

                    await Console.Out.WriteAsync(SignToolExePath + " ");

                    await Console.Out.WriteLineAsync(FullSignToolArgs.Replace(certPass, "[redacted]"));

                    try
                    {
                        await Command.RunAsync(SignToolExePath, FullSignToolArgs, noEcho : true);

                        signed = true;
                        break;
                    }
                    catch (Exception /*ex*/)
                    {
                        await Console.Out.WriteLineAsync(
                            $"Error: timestap server {timestampUrl} is unavailable, " +
                            $"{tryCount - tryNr - 1} server(s) left to try.");
                    }
                }

                if (!signed)
                {
                    throw new Exception("Error: None of the timestamp servers available.");
                }
            }
        }
        public static async Task RunAsync(BuildContext ctx)
        {
            var ap = ctx.GetArtifactPackage();

            var SignToolExePath = Path.Combine(
                ctx.ToolsDir,
                MagicStrings.Dirs.Cert,
                MagicStrings.Files.SignToolExe);

            bool signed   = false;
            int  tryCount = ctx.Config.TimestampUrls.Count;

            for (int tryNr = 0; tryNr < tryCount; ++tryNr)
            {
                var timestampUrl = ctx.Config.TimestampUrls[tryNr];
                var(certPass, SignToolArgs) = MakeSignToolArgs(ctx, timestampUrl);

                SignToolArgs += Path
                                .Combine(ctx.OutDir, ap.CanonicalTargetName,
                                         Path.GetFileNameWithoutExtension(ap.FileName) + MagicStrings.Ext.DotMsi)
                                .Quote();

                Console.WriteLine(SignToolExePath + " ");
                Console.WriteLine(SignToolArgs.Replace(certPass, "[redacted]"));

                try
                {
                    await Command.RunAsync(SignToolExePath, SignToolArgs, noEcho : true);

                    signed = true;
                    break;
                }
                catch (Exception /*ex*/)
                {
                    Console.WriteLine(
                        $"Error: timestap server {timestampUrl} is unavailable, " +
                        $"{tryCount - tryNr - 1} server(s) left to try.");
                }
            }

            if (!signed)
            {
                throw new Exception("Error: None of the timestamp servers available.");
            }
        }
        public static async Task RunAsync(BuildContext ctx)
        {
            var cmd = ctx.GetCommand();
            var ap  = ctx.GetArtifactPackage();

            var args = string.Join(' ', new string[]
            {
                "--package=" + Path.GetFileNameWithoutExtension(ap.FileName).Quote(),
                ((cmd as ISupportWxsOnlySwitch).WxsOnly ? "--wxs-only" : string.Empty),
                "--keep-temp-files --verbose",
            });

            var compilerPath = Path
                               .Combine(ctx.CompilerDir, MagicStrings.Beats.CompilerName + MagicStrings.Ext.DotExe)
                               .Quote();

            await SimpleExec.Command.RunAsync(compilerPath, args, ctx.InDir);
        }
예제 #7
0
        public static async Task RunAsync(BuildContext ctx)
        {
            var  cmd         = ctx.GetCommand();
            bool forceSwitch = (cmd as ISupportForceSwitch)?.ForceSwitch ?? false;

            var ap = ctx.GetArtifactPackage();

            var(wasAlreadyPresent, localPath) = await ArtifactsApi.FetchArtifact(ctx, ap, forceSwitch);

            if (wasAlreadyPresent)
            {
                await Console.Out.WriteLineAsync("Download skipped, file exists: " + localPath);
            }
            else
            {
                var fileSize = new FileInfo(localPath).Length;
                await Console.Out.WriteLineAsync($"Saved: ({fileSize.Bytes().Humanize("MB")}) {localPath}");
            }
        }
예제 #8
0
        public static async Task RunAsync(BuildContext ctx)
        {
            var  cmd         = ctx.GetCommand();
            bool forceSwitch = (cmd as ISupportForceSwitch)?.ForceSwitch ?? false;

            var ap = ctx.GetArtifactPackage();

            long reportThreshold = 0;

            var(wasAlreadyPresent, localPath) =
                await ArtifactsApi.FetchArtifact(
                    ctx, ap, forceSwitch,
                    (bytesRead, bytesReadTotal) =>
            {
                reportThreshold += bytesRead;

                // Throttle reporting
                if (reportThreshold >= (1024 * 1024 * 5))
                {
                    reportThreshold = 0;
                    Console.Out.WriteAsync(".");
                }
            },
                    bytesReadTotal =>
            {
                Console.Out.WriteLineAsync();
            });

            if (wasAlreadyPresent)
            {
                Console.WriteLine("Download skipped, file exists: " + localPath);
            }
            else
            {
                var fileSize = new FileInfo(localPath).Length;
                Console.WriteLine($"Saved: ({fileSize.Bytes().Humanize("MB")}) {localPath}");
            }
        }