示例#1
0
        static void Main(string[] args)
        {
            FlagParser.Parse(args);
            var file = FlagParser.StringFlag("file", string.Empty, true);
            var hash = FlagParser.StringFlag("hash", string.Empty, true);

            if (string.IsNullOrWhiteSpace(file) || string.IsNullOrWhiteSpace(hash))
            {
                Console.WriteLine("Invalid Parameters");
                return;
            }
            using var hashAlgo = HashAlgorithm.Create(hash ?? "SHA512");
            using var stream   = File.OpenRead(file);
            var checksum = BitConverter.ToString(hashAlgo.ComputeHash(stream)).Replace("-", string.Empty).ToLowerInvariant();

            Console.WriteLine("--- File Checksum ---");
            Console.WriteLine(checksum);
        }
示例#2
0
        static void Main(string[] args)
        {
            Dictionary <string, List <string> > admin1codes;
            Dictionary <string, List <string> > admin2codes;
            Dictionary <string, List <string> > countries;
            Dictionary <string, List <string> > features;
            List <string> filters;

            FlagParser.ContinueOnError = true;
            FlagParser.Parse(args);
            bool help = FlagParser.BoolFlag("help", false, false);

            if (help || args.Length == 0)
            {
                DisplayUsage();
                return;
            }
            // process input flags
            string admin1File  = FlagParser.StringFlag("admin1", string.Empty, true);
            string admin2File  = FlagParser.StringFlag("admin2", string.Empty, true);
            string countryFile = FlagParser.StringFlag("countries", string.Empty, true);
            string featureFile = FlagParser.StringFlag("feature", string.Empty, true);
            string input       = FlagParser.StringFlag("input", string.Empty, true);
            string output      = FlagParser.StringFlag("output", string.Empty, true);
            string filter      = FlagParser.StringFlag("filter", string.Empty, false);
            string outputType  = FlagParser.StringFlag("type", "default", false);

            if (FlagParser.Errors.Count > 0)
            {
                foreach (var e in FlagParser.Errors)
                {
                    Console.WriteLine(e);
                }
                return;
            }

            // read admin1 codes
            admin1codes = ReadAdmin1File(admin1File);
            if (admin1codes == null)
            {
                return;
            }

            // read admin2 codes
            admin2codes = ReadAdmin2File(admin2File);
            if (admin2codes == null)
            {
                return;
            }

            // read country codes
            countries = ReadCountryFile(countryFile);
            if (countries == null)
            {
                return;
            }

            // read feature codes
            features = ReadFeatureFile(featureFile);
            if (features == null)
            {
                return;
            }

            // put filters as list
            filters = new List <string>();
            var fltrs = filter.Split(new char[] { ',' });

            foreach (var fltr in fltrs)
            {
                filters.Add(fltr);
            }

            switch (outputType)
            {
            case "full-structured":
                GenerateFullStructuredOutput(input, output, features, filters, countries, admin1codes, admin2codes);
                break;

            case "full-flat":
            default:
                GenerateDefaultOutput(input, output, features, filters, countries, admin1codes, admin2codes);
                break;
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            FlagParser.Parse(args);
            var exeFile = FlagParser.StringFlag("exeFile", string.Empty, true);
            var exePath = FlagParser.StringFlag("exePath", string.Empty, true);
            var zipFile = FlagParser.StringFlag("zipFile", string.Empty, true);

            if (string.IsNullOrWhiteSpace(exeFile) || string.IsNullOrWhiteSpace(exePath) || string.IsNullOrWhiteSpace(zipFile))
            {
                Console.WriteLine("Invalid Parameters");
                return;
            }
            // make sure exe file to update is not running
            foreach (var proc in Process.GetProcesses())
            {
                try
                {
                    if (proc.MainModule.FileName.Equals(exeFile, StringComparison.OrdinalIgnoreCase))
                    {
                        Console.WriteLine("-- Waiting for exit " + exeFile + " --");
                        proc.WaitForExit();
                        Console.WriteLine("-- Application closed " + exeFile + " --");
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                    Debug.WriteLine(e.StackTrace);
                }
            }
            Console.WriteLine("-- Waiting for process to close --");
            Thread.Sleep(5000);
            Console.WriteLine("-- Extrating Files --");
            // open zip file
            using var zip = ZipStorer.Open(zipFile, FileAccess.Read);
            var dir = zip.Files.Values;

            foreach (var item in dir)
            {
                try
                {
                    if (item.FilenameInZip.ToLower().Contains("zipextractor", StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                    var extractFile = Path.Combine(exePath, item.FilenameInZip);
                    if (File.Exists(extractFile))
                    {
                        Console.WriteLine("-- Deleting File " + extractFile);
                        File.Delete(extractFile);
                    }
                    Console.WriteLine("-- Extracting File " + extractFile);
                    zip.ExtractFile(item, extractFile);
                    Console.WriteLine("-- Done Extracting File " + extractFile);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: " + ex.Message);
                    continue;
                }
            }
            zip.Close();
            // done extract, run exe file again
            var psi = new ProcessStartInfo();

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && RuntimeInformation.OSArchitecture == Architecture.X64)
            {
                psi.FileName = exeFile;
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && RuntimeInformation.OSArchitecture == Architecture.X86)
            {
                psi.FileName = exeFile;
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && RuntimeInformation.OSArchitecture == Architecture.Arm)
            {
                psi.FileName = exeFile;
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && RuntimeInformation.OSArchitecture == Architecture.X64)
            {
                psi.FileName  = "/usr/bin/dotnet";
                psi.Arguments = exeFile.Replace(".exe", ".dll");
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && RuntimeInformation.OSArchitecture == Architecture.Arm)
            {
                psi.FileName  = "/usr/bin/dotnet";
                psi.Arguments = exeFile.Replace(".exe", ".dll");
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && RuntimeInformation.OSArchitecture == Architecture.X64)
            {
                psi.FileName  = "/usr/bin/dotnet";
                psi.Arguments = exeFile.Replace(".exe", ".dll");
            }
            Console.WriteLine("-- Running Application --");
            Console.WriteLine("Filename : " + psi.FileName);
            Console.WriteLine("Args : " + psi.Arguments);
            Process.Start(psi).WaitForExit();
            File.Delete(zipFile);
            Console.WriteLine("-- Update Done --");
            return;
        }
示例#4
0
 static void Main(string[] args)
 {
     FlagParser.Parse(args);
     Console.WriteLine(FlagParser.StringFlag("stringtest", "none", false));
     Console.WriteLine(FlagParser.DecimalFlag("dectest", 0.45M, false));
 }