/// <summary>
        /// Remove telementry and only extract basic drivers
        /// </summary>
        private static void MakeInstaller()
        {
            Console.WriteLine();
            Console.Write("Making installer . . . ");

            LibaryFile libaryFile = LibaryHandler.EvaluateLibary();

            string[] filesToExtract = { "Display.Driver", "NVI2", "EULA.txt", "license.txt", "ListDevices.txt", "setup.cfg", "setup.exe" };

            File.WriteAllLines(savePath + @"\" + "inclList.txt", filesToExtract);

            string fullDriverPath = @"""" + savePath + @"\" + driverFileName + @"""";

            if (libaryFile.libary == LibaryHandler.Libary.WINRAR)
            {
                using (Process WinRAR = new Process())
                {
                    WinRAR.StartInfo.FileName         = libaryFile.InstallLocation + "winrar.exe";
                    WinRAR.StartInfo.WorkingDirectory = savePath;
                    WinRAR.StartInfo.Arguments        = "X " + fullDriverPath + @" -N@""inclList.txt""";
                    WinRAR.StartInfo.UseShellExecute  = false;
                    WinRAR.Start();
                    WinRAR.WaitForExit();
                }
            }
            else if (libaryFile.libary == LibaryHandler.Libary.SEVENZIP)
            {
                using (Process SevenZip = new Process()) {
                    SevenZip.StartInfo.FileName         = libaryFile.InstallLocation + "7zG.exe";
                    SevenZip.StartInfo.WorkingDirectory = savePath;
                    SevenZip.StartInfo.Arguments        = "x " + fullDriverPath + @" @inclList.txt";
                    SevenZip.StartInfo.UseShellExecute  = false;
                    SevenZip.Start();
                    SevenZip.WaitForExit();
                }
            }



            Console.Write("OK!");
            Console.WriteLine();
        }
        /// <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();
        }
        /// <summary>
        /// Remove telementry and only extract basic drivers
        /// </summary>
        private static void MakeInstaller(bool silent)
        {
            Console.WriteLine();
            Console.Write("Extracting drivers . . . ");

            var error      = false;
            var libaryFile = LibaryHandler.EvaluateLibary();

            string[] filesToExtract = { "Display.Driver", "NVI2", "EULA.txt", "license.txt", "ListDevices.txt", "setup.cfg", "setup.exe" };

            try {
                File.WriteAllLines(savePath + "inclList.txt", filesToExtract);
            } catch (Exception ex) {
                error = true;
                Console.Write("ERROR!");
                Console.WriteLine();
                Console.WriteLine(ex.ToString());
            }

            string fullDriverPath = @"""" + savePath + driverFileName + @"""";

            if (libaryFile.LibaryName() == LibaryHandler.Libary.WINRAR)
            {
                using (var WinRAR = new Process()) {
                    WinRAR.StartInfo.FileName         = libaryFile.GetInstallationDirectory() + "winrar.exe";
                    WinRAR.StartInfo.WorkingDirectory = savePath;
                    WinRAR.StartInfo.Arguments        = $@"X {fullDriverPath} -N@""inclList.txt""";
                    if (silent)
                    {
                        WinRAR.StartInfo.Arguments += " -ibck -y";
                    }
                    WinRAR.StartInfo.UseShellExecute = false;

                    try {
                        WinRAR.Start();
                        WinRAR.WaitForExit();
                    } catch (Exception ex) {
                        error = true;
                        Console.Write("ERROR!");
                        Console.WriteLine();
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
            else if (libaryFile.LibaryName() == LibaryHandler.Libary.SEVENZIP)
            {
                using (var SevenZip = new Process()) {
                    if (silent)
                    {
                        SevenZip.StartInfo.FileName = libaryFile.GetInstallationDirectory() + "7z.exe";
                    }
                    else
                    {
                        SevenZip.StartInfo.FileName = libaryFile.GetInstallationDirectory() + "7zG.exe";
                    }
                    SevenZip.StartInfo.WorkingDirectory = savePath;
                    SevenZip.StartInfo.Arguments        = $"x {fullDriverPath} @inclList.txt";
                    if (silent)
                    {
                        SevenZip.StartInfo.Arguments += " -y";
                    }
                    SevenZip.StartInfo.UseShellExecute = false;
                    SevenZip.StartInfo.CreateNoWindow  = true; // don't show the console in our console!

                    try {
                        Thread.Sleep(1000);
                        SevenZip.Start();
                        SevenZip.WaitForExit();
                    } catch (Exception ex) {
                        error = true;
                        Console.Write("ERROR!");
                        Console.WriteLine();
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
            else
            {
                Console.WriteLine("Could not identify a possible extractor! We should panic.");
                error = true;
            }

            // remove new EULA files from the installer config, or else the installer throws error codes
            // author https://github.com/cywq
            if (!error)
            {
                var      xmlDocument   = new XmlDocument();
                string   setupFile     = savePath + "setup.cfg";
                string[] linesToDelete = { "${{EulaHtmlFile}}", "${{FunctionalConsentFile}}", "${{PrivacyPolicyFile}}" };

                xmlDocument.Load(setupFile);

                foreach (var line in linesToDelete)
                {
                    var node = (XmlElement)xmlDocument.DocumentElement.SelectSingleNode($"/setup/manifest/file[@name=\"{line}\"]");

                    if (node != null)
                    {
                        node.ParentNode.RemoveChild(node);
                    }
                }

                xmlDocument.Save(setupFile);
            }

            if (!error)
            {
                Console.Write("OK!");
                Console.WriteLine();
            }
        }
        /// <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;
            }

            if (!File.Exists("HtmlAgilityPack.dll"))
            {
                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 (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 determinate itself");
                        if (showUI)
                        {
                            Console.ReadKey();
                        }
                        Environment.Exit(1);
                    }
                }
            }

            Console.WriteLine();
        }
        /// <summary>
        /// Remove telementry and only extract basic drivers
        /// </summary>
        private static void MakeInstaller(bool silent)
        {
            Console.WriteLine();
            Console.Write("Making installer . . . ");

            int        error      = 0;
            LibaryFile libaryFile = LibaryHandler.EvaluateLibary();

            string[] filesToExtract = { "Display.Driver", "NVI2", "EULA.txt", "license.txt", "ListDevices.txt", "setup.cfg", "setup.exe" };

            try {
                File.WriteAllLines(savePath + "inclList.txt", filesToExtract);
            } catch (Exception ex) {
                error++;
                Console.Write("ERROR!");
                Console.WriteLine();
                Console.WriteLine(ex.ToString());
            }

            string fullDriverPath = @"""" + savePath + driverFileName + @"""";

            if (libaryFile.libary == LibaryHandler.Libary.WINRAR)
            {
                using (Process WinRAR = new Process()) {
                    WinRAR.StartInfo.FileName         = libaryFile.InstallLocation + "winrar.exe";
                    WinRAR.StartInfo.WorkingDirectory = savePath;
                    WinRAR.StartInfo.Arguments        = "X " + fullDriverPath + @" -N@""inclList.txt""";
                    if (silent)
                    {
                        WinRAR.StartInfo.Arguments += " -ibck -y";
                    }
                    WinRAR.StartInfo.UseShellExecute = false;
                    try {
                        WinRAR.Start();
                        WinRAR.WaitForExit();
                    } catch (Exception ex) {
                        error++;
                        Console.Write("ERROR!");
                        Console.WriteLine();
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
            else if (libaryFile.libary == LibaryHandler.Libary.SEVENZIP)
            {
                using (Process SevenZip = new Process()) {
                    if (silent)
                    {
                        SevenZip.StartInfo.FileName = libaryFile.InstallLocation + "7z.exe";
                    }
                    else
                    {
                        SevenZip.StartInfo.FileName = libaryFile.InstallLocation + "7zG.exe";
                    }
                    SevenZip.StartInfo.WorkingDirectory = savePath;
                    SevenZip.StartInfo.Arguments        = "x " + fullDriverPath + @" @inclList.txt";
                    if (silent)
                    {
                        SevenZip.StartInfo.Arguments += " -y";
                    }
                    SevenZip.StartInfo.UseShellExecute = false;
                    SevenZip.StartInfo.CreateNoWindow  = true; // don't show the console in our console!
                    try {
                        Thread.Sleep(1000);
                        SevenZip.Start();
                        SevenZip.WaitForExit();
                    } catch (Exception ex) {
                        error++;
                        Console.Write("ERROR!");
                        Console.WriteLine();
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
            else
            {
                Console.WriteLine("Could not identify a possible extractor! We should panic.");
            }

            if (error == 0)
            {
                Console.Write("OK!");
                Console.WriteLine();
            }
        }
        /// <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();
        }
Beispiel #7
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();
        }
Beispiel #8
0
        /// <summary>
        /// Remove telementry and only extract basic drivers
        /// </summary>
        private static void MakeInstaller(bool silent)
        {
            Console.WriteLine();
            Console.Write("Making installer . . . ");

            bool          error          = false;
            LibaryFile    libaryFile     = LibaryHandler.EvaluateLibary();
            List <string> filesToExtract = new List <string> {
                "Display.Driver", "NVI2", "EULA.txt", "license.txt", "ListDevices.txt", "setup.cfg", "setup.exe"
            };

            if (driverComponentsToInstall != null && driverComponentsToInstall.Count > 0)
            {
                var lowerCaseEqualityComparer = new AnonymousEqualityComparer <string>((s1, s2) => s1.ToLower().Equals(s2.ToLower()), s => s.ToLower().GetHashCode());
                var collection = driverComponentsToInstall.Where(s => !filesToExtract.Contains(s, lowerCaseEqualityComparer));
                filesToExtract.AddRange(collection);
            }

            try {
                File.WriteAllLines(savePath + "inclList.txt", filesToExtract);
            } catch (Exception ex) {
                error = true;
                Console.Write("ERROR!");
                Console.WriteLine();
                Console.WriteLine(ex.ToString());
            }

            string fullDriverPath = @"""" + savePath + driverFileName + @"""";

            if (libaryFile.libary == LibaryHandler.Libary.WINRAR)
            {
                using (Process WinRAR = new Process()) {
                    WinRAR.StartInfo.FileName         = libaryFile.InstallLocation + "winrar.exe";
                    WinRAR.StartInfo.WorkingDirectory = savePath;
                    WinRAR.StartInfo.Arguments        = "X " + fullDriverPath + @" -N@""inclList.txt""";
                    if (silent)
                    {
                        WinRAR.StartInfo.Arguments += " -ibck -y";
                    }
                    WinRAR.StartInfo.UseShellExecute = false;
                    try {
                        WinRAR.Start();
                        WinRAR.WaitForExit();
                    } catch (Exception ex) {
                        error = true;
                        Console.Write("ERROR!");
                        Console.WriteLine();
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
            else if (libaryFile.libary == LibaryHandler.Libary.SEVENZIP)
            {
                using (Process SevenZip = new Process()) {
                    if (silent)
                    {
                        SevenZip.StartInfo.FileName = libaryFile.InstallLocation + "7z.exe";
                    }
                    else
                    {
                        SevenZip.StartInfo.FileName = libaryFile.InstallLocation + "7zG.exe";
                    }
                    SevenZip.StartInfo.WorkingDirectory = savePath;
                    SevenZip.StartInfo.Arguments        = "x " + fullDriverPath + @" @inclList.txt";
                    if (silent)
                    {
                        SevenZip.StartInfo.Arguments += " -y";
                    }
                    SevenZip.StartInfo.UseShellExecute = false;
                    SevenZip.StartInfo.CreateNoWindow  = true; // don't show the console in our console!
                    try {
                        Thread.Sleep(1000);
                        SevenZip.Start();
                        SevenZip.WaitForExit();
                    } catch (Exception ex) {
                        error = true;
                        Console.Write("ERROR!");
                        Console.WriteLine();
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
            else
            {
                Console.WriteLine("Could not identify a possible extractor! We should panic.");
                error = true;
            }

            // remove new EULA files from the installer config, or else the installer throws error codes
            // thanks to https://github.com/cywq
            if (!error)
            {
                XmlDocument xmlDocument = new XmlDocument();
                string      setupFile   = savePath + "setup.cfg";
                xmlDocument.Load(setupFile);

                string[] LinesToDelete = { "${{EulaHtmlFile}}", "${{FunctionalConsentFile}}", "${{PrivacyPolicyFile}}" };
                foreach (string line in LinesToDelete)
                {
                    XmlElement node = (XmlElement)xmlDocument.DocumentElement.SelectSingleNode("/setup/manifest/file[@name=\"" + line + "\"]");
                    if (node != null)
                    {
                        node.ParentNode.RemoveChild(node);
                    }
                }
                xmlDocument.Save(setupFile);
            }

            if (!error)
            {
                Console.Write("OK!");
                Console.WriteLine();
            }
        }