Пример #1
0
        /// <summary>
        /// Check if dependencies are all OK
        /// </summary>
        private static void CheckDependencies()
        {
            // Check internet connection
            Console.Write("Verifying internet connection . . . ");
            switch (NetworkInterface.GetIsNetworkAvailable())
            {
            case true:
                Console.Write("OK!");
                Console.WriteLine();
                break;

            default:
                Console.Write("ERROR!");
                Console.WriteLine();
                Console.WriteLine("No internet connection was found, the application will now terminate!");
                if (showUI)
                {
                    Console.ReadKey();
                }
                Environment.Exit(2);
                break;
            }

            var hap = "HtmlAgilityPack.dll";

            if (File.Exists(hap))
            {
                Console.WriteLine();
                Console.Write("Verifying HAP hash . . . ");
                var hash = HashHandler.CalculateMD5(hap);

                if (hash.md5 != HashHandler.HAP_HASH && hash.error == false)
                {
                    Console.Write("ERROR!");
                    Console.WriteLine();
                    Console.WriteLine("Deleting the invalid HAP file.");

                    try {
                        //fFile.Delete(hap);
                    } catch (Exception ex) {
                        Console.WriteLine(ex.ToString());
                    }

                    // delete HAP file as it couldn't be verified
                }
                else if (hash.error)
                {
                    try {
                        File.Delete(hap);
                    } catch (Exception ex) {
                        Console.WriteLine(ex.ToString());
                    }
                }
                else
                {
                    Console.Write("OK!");
                    Console.WriteLine();
                }

                if (debug)
                {
                    Console.WriteLine("Generated hash: " + hash.md5);
                    Console.WriteLine("Known hash:     " + HashHandler.HAP_HASH);
                }
            }

            if (!File.Exists(hap))
            {
                Console.WriteLine();
                Console.Write("Attempting to download HtmlAgilityPack.dll . . . ");

                try {
                    using (WebClient webClient = new WebClient()) {
                        webClient.DownloadFile($"https://github.com/ElPumpo/TinyNvidiaUpdateChecker/releases/download/v{offlineVer}/HtmlAgilityPack.dll", "HtmlAgilityPack.dll");
                    }
                    Console.Write("OK!");
                    Console.WriteLine();
                } catch (Exception ex) {
                    Console.Write("ERROR!");
                    Console.WriteLine();
                    Console.WriteLine(ex.ToString());
                    Console.WriteLine();
                }
            }
            var currentHapVersion = AssemblyName.GetAssemblyName(hap).Version.ToString();

            // compare HAP version too
            if (new Version(HashHandler.HAP_VERSION).CompareTo(new Version(currentHapVersion)) > 0)
            {
                Console.WriteLine("ERROR: The current HAP libary v{0} does not match the wanted v{1}", currentHapVersion, HashHandler.HAP_VERSION);
                Console.WriteLine("The application has been terminated to prevent a error message by .NET");
                if (showUI)
                {
                    Console.ReadKey();
                }
                Environment.Exit(1);
            }

            if (SettingManager.ReadSettingBool("Minimal install"))
            {
                if (LibaryHandler.EvaluateLibary() == null)
                {
                    Console.WriteLine("Doesn't seem like either WinRAR or 7-Zip is installed!");
                    DialogResult dialogUpdates = MessageBox.Show("Do you want to disable the minimal install feature and use the traditional way?", "TinyNvidiaUpdateChecker", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (dialogUpdates == DialogResult.Yes)
                    {
                        SettingManager.SetSetting("Minimal install", "false");
                    }
                    else
                    {
                        Console.WriteLine("The application will terminate itself");
                        if (showUI)
                        {
                            Console.ReadKey();
                        }
                        Environment.Exit(1);
                    }
                }
            }

            Console.WriteLine();
        }
Пример #2
0
        /// <summary>
        /// Check if dependencies are all OK
        /// </summary>
        private static void CheckDependencies()
        {
            // Check internet connection
            Console.Write("Verifying internet connection . . . ");
            if (NetworkInterface.GetIsNetworkAvailable())
            {
                Console.Write("OK!");
                Console.WriteLine();
            }
            else
            {
                Console.Write("ERROR!");
                Console.WriteLine();
                Console.WriteLine("You are not connected to the internet, the application cannot function without it!");
                if (showUI)
                {
                    Console.ReadKey();
                }
                Environment.Exit(2);
            }

            var hap = "HtmlAgilityPack.dll";

            if (File.Exists(hap))
            {
                Console.WriteLine();
                Console.Write("Verifying HAP MD5 hash . . . ");

                var hash = HashHandler.CalculateMD5(hap);

                if (hash.md5 != HashHandler.HAP_HASH && hash.error == false)
                {
                    Console.Write("ERROR!");
                    Console.WriteLine();
                    Console.WriteLine("Deleting the invalid HAP file.");

                    try {
                        File.Delete(hap);
                    } catch (Exception ex) {
                        Console.WriteLine(ex.ToString());
                    }

                    // delete HAP file as it couldn't be verified
                }
                else if (hash.error)
                {
                    try {
                        File.Delete(hap);
                    } catch (Exception ex) {
                        Console.WriteLine(ex.ToString());
                    }
                }
                else
                {
                    Console.Write("OK!");
                    Console.WriteLine();
                }

                if (debug)
                {
                    Console.WriteLine($"Generated hash: {hash.md5}");
                    Console.WriteLine($"Known hash:     {HashHandler.HAP_HASH}");
                }
            }

            if (!File.Exists(hap))
            {
                Console.WriteLine();
                Console.Write("Attempting to download HtmlAgilityPack.dll . . . ");

                try {
                    using (var webClient = new WebClient()) {
                        webClient.DownloadFile($"https://github.com/ElPumpo/TinyNvidiaUpdateChecker/releases/download/v{offlineVer}/HtmlAgilityPack.dll", "HtmlAgilityPack.dll");
                    }

                    Console.Write("OK!");
                    Console.WriteLine();
                } catch (Exception ex) {
                    Console.Write("ERROR!");
                    Console.WriteLine();
                    Console.WriteLine(ex.ToString());
                    Console.WriteLine();
                }
            }

            // compare HAP version, too
            var currentHapVersion = AssemblyName.GetAssemblyName(hap).Version.ToString();

            if (new Version(HashHandler.HAP_VERSION).CompareTo(new Version(currentHapVersion)) != 0)
            {
                Console.WriteLine($"ERROR: The current HAP libary v{currentHapVersion} does not match the required v{HashHandler.HAP_VERSION}");
                Console.WriteLine("The application will not continue to prevent further errors");
                if (showUI)
                {
                    Console.ReadKey();
                }
                Environment.Exit(1);
            }

            if (SettingManager.ReadSettingBool("Minimal install"))
            {
                if (LibaryHandler.EvaluateLibary() == null)
                {
                    Console.WriteLine("Doesn't seem like either WinRAR or 7-Zip is installed! We are disabling the minimal install feature for you.");
                    SettingManager.SetSetting("Minimal install", "false");
                }
            }

            Console.WriteLine();
        }
Пример #3
0
        /// <summary>
        /// Check if dependencies are all OK
        /// </summary>
        private static void CheckDependencies()
        {
            // Check internet connection
            Console.Write("Searching for a network connection . . . ");
            switch (NetworkInterface.GetIsNetworkAvailable())
            {
            case true:
                Console.Write("OK!");
                Console.WriteLine();
                break;

            default:
                Console.Write("ERROR!");
                Console.WriteLine();
                Console.WriteLine("No network connection was found, the application will now determinate!");
                if (showUI)
                {
                    Console.ReadKey();
                }
                Environment.Exit(2);
                break;
            }
            var hap = "HtmlAgilityPack.dll";

            if (File.Exists(hap))
            {
                Console.WriteLine();
                Console.Write("Verifying HAP hash . . . ");
                var hash = HashHandler.CalculateMD5(hap);

                if (hash.md5 != HashHandler.HASH_HAP && hash.error == false)
                {
                    Console.Write("ERROR!");
                    Console.WriteLine();
                    Console.WriteLine("Deleting the invalid HAP file.");

                    try {
                        File.Delete(hap);
                    } catch (Exception ex) {
                        Console.WriteLine(ex.ToString());
                    }

                    // delete HAP file as it couldn't be verified
                }
                else if (hash.error)
                {
                    try {
                        File.Delete(hap);
                    } catch (Exception ex) {
                        Console.WriteLine(ex.ToString());
                    }
                }
                else
                {
                    Console.Write("OK!");
                    Console.WriteLine();
                }

                if (debug)
                {
                    Console.WriteLine("Generated hash: " + hash.md5);
                    Console.WriteLine("Known hash:     " + HashHandler.HASH_HAP);
                }
            }

            if (!File.Exists(hap))
            {
                Console.WriteLine();
                Console.Write("Attempting to download HtmlAgilityPack.dll . . . ");

                try {
                    using (WebClient webClient = new WebClient()) {
                        webClient.DownloadFile("https://github.com/ElPumpo/TinyNvidiaUpdateChecker/releases/download/v" + offlineVer + "/HtmlAgilityPack.dll", "HtmlAgilityPack.dll");
                    }
                    Console.Write("OK!");
                    Console.WriteLine();
                } catch (Exception ex) {
                    Console.Write("ERROR!");
                    Console.WriteLine();
                    Console.WriteLine(ex.ToString());
                    Console.WriteLine();
                }
            }

            if (ShouldMakeInstaller)
            {
                if (LibaryHandler.EvaluateLibary() == null)
                {
                    Console.WriteLine("Doesn't seem like either WinRAR or 7-Zip is installed!");
                    DialogResult dialogUpdates = MessageBox.Show("Do you want to disable the minimal install feature and use the traditional way?", "TinyNvidiaUpdateChecker", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (dialogUpdates == DialogResult.Yes)
                    {
                        SettingManager.SetSetting("Minimal install", "false");
                    }
                    else
                    {
                        Console.WriteLine("The application will determinate itself");
                        if (showUI)
                        {
                            Console.ReadKey();
                        }
                        Environment.Exit(1);
                    }
                }
            }

            Console.WriteLine();
        }