Skip to content

Commit

Permalink
Finished making installer code, requires WinRAR
Browse files Browse the repository at this point in the history
  • Loading branch information
ElPumpo committed Apr 28, 2017
1 parent 218256a commit 777dfde
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 29 deletions.
118 changes: 89 additions & 29 deletions TinyNvidiaUpdateChecker/MainConsole.cs
Expand Up @@ -12,6 +12,7 @@
using System.Threading;
using System.Configuration;
using System.Management;
using Microsoft.Win32;

namespace TinyNvidiaUpdateChecker
{
Expand Down Expand Up @@ -69,6 +70,7 @@ class MainConsole

private static string downloadURL;
private static string savePath;
private static string driverName;
private static string pdfURL;
private static DateTime releaseDate;
private static string releaseDesc;
Expand Down Expand Up @@ -546,6 +548,9 @@ private static void gpuInfo()
OfflineGPUVersion = obj["DriverVersion"].ToString().Replace(".", string.Empty).Substring(5);
OfflineGPUVersion = OfflineGPUVersion.Substring(0, 3) + "." + OfflineGPUVersion.Substring(3); // add dot
break;
} else
{
// gpu not found
}

}
Expand Down Expand Up @@ -742,6 +747,17 @@ private static void checkDll()
if (showUI == true) Console.ReadKey();
Environment.Exit(2);
}

try {
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\WinRAR archiver", false)) {
LogManager.log("WinRAR path: " + key.GetValue("InstallLocation").ToString(), LogManager.Level.INFO);
}
} catch (Exception ex) {
Console.WriteLine("Doesn't seem like WinRAR is installed, and is required! The application will now determinate itself - " + ex.ToString());
if (showUI == true) Console.ReadKey();
Environment.Exit(2);
}

}

/// <summary>
Expand Down Expand Up @@ -791,34 +807,29 @@ private static void downloadDriver()
// @todo error handling could be better:
// isolate saveFileDialog errors with accually downloading GPU driver

// @todo add status bar for download progress
// @todo do the saveFileDialog in a loop

bool error = false;
try
{
string driverName = downloadURL.Split('/').Last(); // retrives file name from url
driverName = downloadURL.Split('/').Last(); // retrives file name from url

DialogResult result;
try {

using (SaveFileDialog saveFileDialog = new SaveFileDialog()) {
saveFileDialog.Filter = "Executable|*.exe";
saveFileDialog.Title = "Choose save file for GPU driver";
saveFileDialog.FileName = driverName;
DialogResult result;
using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog()) {

result = saveFileDialog.ShowDialog(); // show dialog and get status (will wait for input)
folderBrowserDialog.Description = "Where do you want to save the drivers?";

switch (result)
{
result = folderBrowserDialog.ShowDialog(); // show dialog and get status (will wait for input)
switch (result) {
case DialogResult.OK:
savePath = saveFileDialog.FileName.ToString();
savePath = folderBrowserDialog.SelectedPath.ToString();
break;

default:
// savePath = Path.GetTempPath() + driverName;

// if something went wrong, fall back to downloads folder
savePath = getDownloadFolderPath() + driverName;
savePath = getDownloadFolderPath();
break;
}
}
Expand All @@ -827,25 +838,31 @@ private static void downloadDriver()
Console.WriteLine("savePath: " + savePath);
Console.WriteLine("result: " + result);
}


// don't download driver if it already exists
Console.Write("Downloading the driver . . . ");

using (WebClient webClient = new WebClient())
{
var notifier = new AutoResetEvent(false);
var progress = new ProgressBar();
if (!File.Exists(savePath + @"\" + driverName)) {


webClient.DownloadProgressChanged += delegate (object sender, DownloadProgressChangedEventArgs e)
using (WebClient webClient = new WebClient())
{
progress.Report((double)e.ProgressPercentage / 100);
var notifier = new AutoResetEvent(false);
var progress = new ProgressBar();

if (e.BytesReceived >= e.TotalBytesToReceive) notifier.Set();
};
webClient.DownloadProgressChanged += delegate (object sender, DownloadProgressChangedEventArgs e)
{
progress.Report((double)e.ProgressPercentage / 100);

webClient.DownloadFileAsync(new Uri(downloadURL), savePath);
if (e.BytesReceived >= e.TotalBytesToReceive) notifier.Set();
};

notifier.WaitOne(); // sync with the above
progress.Dispose(); // get rid of the progress bar
webClient.DownloadFileAsync(new Uri(downloadURL), savePath + @"\" + driverName);

notifier.WaitOne(); // sync with the above
progress.Dispose(); // get rid of the progress bar
}
} else {
LogManager.log("Driver is already downloaded", LogManager.Level.INFO);
}

}
Expand All @@ -867,7 +884,6 @@ private static void downloadDriver()


Console.WriteLine();
Console.WriteLine("The downloaded file has been saved at: " + savePath);

dialog = MessageBox.Show("Do you want view the release PDF?", "TinyNvidiaUpdateChecker", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dialog == DialogResult.Yes) {
Expand All @@ -879,10 +895,12 @@ private static void downloadDriver()
}
}

makeInstaller();

dialog = MessageBox.Show("Do you wish to run the driver installer?", "TinyNvidiaUpdateChecker", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dialog == DialogResult.Yes) {
try {
Process.Start(savePath);
Process.Start(savePath + @"\setup.exe");
} catch (Exception ex) {
Console.WriteLine(ex.StackTrace);
}
Expand All @@ -891,6 +909,48 @@ private static void downloadDriver()
}
}

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

// get winrar path
string rarPath = null;

try {
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\WinRAR archiver", false)) {
rarPath = key.GetValue("InstallLocation").ToString();
}
} catch (Exception ex) {
Console.Write("ERROR!");
Console.WriteLine();
Console.WriteLine(ex.StackTrace);
Console.WriteLine();
}

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

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

using (Process WinRAR = new Process()) {
WinRAR.StartInfo.FileName = rarPath + "winrar.exe";
WinRAR.StartInfo.WorkingDirectory = savePath;
WinRAR.StartInfo.Arguments = "X " + savePath + @"\" + driverName + @" -N@""inclList.txt""";
WinRAR.Start();
WinRAR.WaitForExit();
}

Console.Write("OK!");
Console.WriteLine();

if (debug) {
Console.WriteLine("rarPath: " + rarPath);
}

}

/// <summary>
/// Returnes the current user's download folder
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions TinyNvidiaUpdateChecker/TinyNvidiaUpdateChecker.csproj
Expand Up @@ -106,6 +106,7 @@
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
Expand Down
3 changes: 3 additions & 0 deletions TinyNvidiaUpdateChecker/app.config
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>

0 comments on commit 777dfde

Please sign in to comment.