Exemplo n.º 1
0
        public int ExecuteInternal(string[] args)
        {
            var startTime = DateTime.UtcNow;

            ReadArgs(args);
            if (verboseMode)
            {
                Console.WriteLine($"Specification file: {specFileName}");
            }

            var deb = new DebPackage();

            deb.ReadSpecification(specFileName);

            if (!string.IsNullOrEmpty(versionFileName))
            {
                var fvi = FileVersionInfo.GetVersionInfo(versionFileName);
                deb.SetVersion(fvi.ProductVersion);
                if (verboseMode)
                {
                    Console.WriteLine($"Version from file: {fvi.ProductVersion}");
                }
            }
            if (!string.IsNullOrEmpty(versionOverride))
            {
                deb.SetVersion(versionOverride);
                if (verboseMode)
                {
                    Console.WriteLine($"Version from command line: {versionOverride}");
                }
            }

            string outDir   = deb.OutDir ?? @".\";
            string fileName = Path.Combine(outDir, deb.DefaultFileName);

            if (File.Exists(fileName))
            {
                // Delete existing file or it may be appended to or partially overwritten
                File.Delete(fileName);
            }
            if (deb.OutDir != null)
            {
                // Create specified out dir if it doesn't exist
                Directory.CreateDirectory(deb.OutDir);
            }

            using (FileStream file = File.OpenWrite(fileName))
            {
                deb.WritePackage(file);
            }

            if (verboseMode)
            {
                Console.WriteLine($"Package created in {(DateTime.UtcNow - startTime).TotalSeconds:N2}s.");
            }
            return(0);
        }
Exemplo n.º 2
0
        static int Main(string[] args)
        {
            var arg = new ArgParser(args);
            var deb = new DebPackage();

            if (arg["o"] == null)
            {
                Console.WriteLine(help);
                return(-1);
            }

            if (arg["file"] != null)
            {
                deb.ReadSpecification(arg["file"].Trim('\\'));
            }
            else if (arg["dir"] != null)
            {
                deb.ReadSpecificationDeb(arg["dir"].Trim('\\'));
            }
            else
            {
                Console.WriteLine(help);
                return(-1);
            }


            // set version package
            if (arg["v"] != null)
            {
                deb.SetVersion(arg["ver"]);
            }
            else if (arg["fv"] != null)
            {
                var ver = FileVersionInfo.GetVersionInfo(arg["fv"]).ProductVersion;
                if (ver != null)
                {
                    deb.SetVersion(ver);
                }
            }

            // set output dir
            if (arg["dir"] != null)
            {
                deb.OutDir = Path.GetDirectoryName(arg["o"]);
            }

            var debFile = arg["o"];

            if (arg["v"] != null || arg["fv"] != null)
            {
                debFile = Path.GetFileNameWithoutExtension(arg["o"]) + "." + deb.controlParams.Version.TrimStart('.').TrimEnd('.') + ".deb";
            }

            if (!debFile.EndsWith(".deb"))
            {
                debFile += ".deb";
            }

            using (FileStream file = File.OpenWrite(debFile))
            {
                deb.WritePackage(file);
            }

            return(0);
        }