Merge pull request #44 from fyr77/feature-autodownload
Feature autodownload
This commit is contained in:
commit
ee6489e090
8 changed files with 128 additions and 18 deletions
|
@ -210,6 +210,15 @@ namespace EnvyUpdate
|
|||
|
||||
if (skippedVer != onlineDriv)
|
||||
{
|
||||
if (GlobalVars.autoDownload)
|
||||
{
|
||||
if (buttonDownload.IsVisible)
|
||||
{
|
||||
Debug.LogToFile("INFO Auto-Downloading driver.");
|
||||
buttonDownload_Click(null, null);
|
||||
}
|
||||
}
|
||||
|
||||
Debug.LogToFile("INFO Showing update popup notification.");
|
||||
Notify.ShowDrivUpdatePopup();
|
||||
}
|
||||
|
@ -340,25 +349,34 @@ namespace EnvyUpdate
|
|||
|
||||
private void buttonDownload_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
progressbarDownload.Visibility = Visibility.Visible;
|
||||
buttonDownload.IsEnabled = false;
|
||||
|
||||
if (File.Exists(Path.Combine(GlobalVars.saveDirectory, onlineDriv + "-nvidia-installer.exe.downloading")))
|
||||
if (GlobalVars.isDownloading)
|
||||
{
|
||||
Debug.LogToFile("WARN Found previous unfinished download, retrying.");
|
||||
File.Delete(Path.Combine(GlobalVars.saveDirectory, onlineDriv + "-nvidia-installer.exe.downloading"));
|
||||
Debug.LogToFile("WARN A download is already running.");
|
||||
ShowSnackbar(Wpf.Ui.Common.ControlAppearance.Danger, Wpf.Ui.Common.SymbolRegular.ErrorCircle24, Properties.Resources.info_download_running, Properties.Resources.info_download_running_title);
|
||||
}
|
||||
Thread thread = new Thread(() => {
|
||||
using (WebClient client = new WebClient())
|
||||
else
|
||||
{
|
||||
progressbarDownload.Visibility = Visibility.Visible;
|
||||
buttonDownload.IsEnabled = false;
|
||||
GlobalVars.isDownloading = true;
|
||||
|
||||
if (File.Exists(Path.Combine(GlobalVars.saveDirectory, onlineDriv + "-nvidia-installer.exe.downloading")))
|
||||
{
|
||||
client.Headers["User-Agent"] = GlobalVars.useragent;
|
||||
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
|
||||
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
|
||||
client.DownloadFileAsync(new Uri(Util.GetDirectDownload(gpuURL)), Path.Combine(GlobalVars.saveDirectory, onlineDriv + "-nvidia-installer.exe.downloading"));
|
||||
Debug.LogToFile("WARN Found previous unfinished download, retrying.");
|
||||
File.Delete(Path.Combine(GlobalVars.saveDirectory, onlineDriv + "-nvidia-installer.exe.downloading"));
|
||||
}
|
||||
});
|
||||
thread.Start();
|
||||
Debug.LogToFile("INFO Started installer download.");
|
||||
Thread thread = new Thread(() => {
|
||||
using (WebClient client = new WebClient())
|
||||
{
|
||||
client.Headers["User-Agent"] = GlobalVars.useragent;
|
||||
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
|
||||
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
|
||||
client.DownloadFileAsync(new Uri(Util.GetDirectDownload(gpuURL)), Path.Combine(GlobalVars.saveDirectory, onlineDriv + "-nvidia-installer.exe.downloading"));
|
||||
}
|
||||
});
|
||||
thread.Start();
|
||||
Debug.LogToFile("INFO Started installer download.");
|
||||
}
|
||||
}
|
||||
|
||||
void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
|
||||
|
@ -376,6 +394,7 @@ namespace EnvyUpdate
|
|||
Application.Current.Dispatcher.Invoke(new Action(() => {
|
||||
buttonDownload.IsEnabled = true;
|
||||
progressbarDownload.Visibility = Visibility.Collapsed;
|
||||
GlobalVars.isDownloading = false;
|
||||
}));
|
||||
if (e.Error == null)
|
||||
{
|
||||
|
|
|
@ -19,5 +19,7 @@ namespace EnvyUpdate
|
|||
public static readonly string useragent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:115.0) Gecko/20100101 Firefox/115.0";
|
||||
public static bool useAppdata = false;
|
||||
public static bool hasWrite = true;
|
||||
public static bool autoDownload = false;
|
||||
public static bool isDownloading = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,6 +115,12 @@ namespace EnvyUpdate
|
|||
|
||||
GlobalVars.isMobile = Util.IsMobile();
|
||||
Debug.LogToFile("INFO Mobile: " + GlobalVars.isMobile);
|
||||
|
||||
if (File.Exists(Path.Combine(GlobalVars.saveDirectory, "autodl.envy")))
|
||||
{
|
||||
Debug.LogToFile("INFO Auto-download is enabled.");
|
||||
GlobalVars.autoDownload = true;
|
||||
}
|
||||
}
|
||||
private void Window_StateChanged(object sender, EventArgs e)
|
||||
{
|
||||
|
|
27
EnvyUpdate/Properties/Resources.Designer.cs
generated
27
EnvyUpdate/Properties/Resources.Designer.cs
generated
|
@ -105,6 +105,24 @@ namespace EnvyUpdate.Properties {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to A download process is already running!.
|
||||
/// </summary>
|
||||
public static string info_download_running {
|
||||
get {
|
||||
return ResourceManager.GetString("info_download_running", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Download running.
|
||||
/// </summary>
|
||||
public static string info_download_running_title {
|
||||
get {
|
||||
return ResourceManager.GetString("info_download_running_title", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Driver installer successfully downloaded..
|
||||
/// </summary>
|
||||
|
@ -267,6 +285,15 @@ namespace EnvyUpdate.Properties {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Download updates automatically.
|
||||
/// </summary>
|
||||
public static string ui_enable_autodownload {
|
||||
get {
|
||||
return ResourceManager.GetString("ui_enable_autodownload", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Enable logging to file.
|
||||
/// </summary>
|
||||
|
|
|
@ -132,6 +132,12 @@
|
|||
<data name="info_download_error_title" xml:space="preserve">
|
||||
<value>Fehler beim Herunterladen</value>
|
||||
</data>
|
||||
<data name="info_download_running" xml:space="preserve">
|
||||
<value>Ein Downloadvorgang läuft bereits!</value>
|
||||
</data>
|
||||
<data name="info_download_running_title" xml:space="preserve">
|
||||
<value>Download läuft</value>
|
||||
</data>
|
||||
<data name="info_download_success" xml:space="preserve">
|
||||
<value>Treiber-Installationsdatei erfolgreich heruntergeladen.</value>
|
||||
</data>
|
||||
|
@ -186,6 +192,9 @@
|
|||
<data name="ui_enable_appdata" xml:space="preserve">
|
||||
<value>Programmdaten in AppData speichern</value>
|
||||
</data>
|
||||
<data name="ui_enable_autodownload" xml:space="preserve">
|
||||
<value>Updates automatisch herunterladen</value>
|
||||
</data>
|
||||
<data name="ui_enable_logging" xml:space="preserve">
|
||||
<value>Programm-Log in Datei schreiben</value>
|
||||
</data>
|
||||
|
|
|
@ -132,6 +132,12 @@
|
|||
<data name="info_download_error_title" xml:space="preserve">
|
||||
<value>Error while downloading</value>
|
||||
</data>
|
||||
<data name="info_download_running" xml:space="preserve">
|
||||
<value>A download process is already running!</value>
|
||||
</data>
|
||||
<data name="info_download_running_title" xml:space="preserve">
|
||||
<value>Download running</value>
|
||||
</data>
|
||||
<data name="info_download_success" xml:space="preserve">
|
||||
<value>Driver installer successfully downloaded.</value>
|
||||
</data>
|
||||
|
@ -186,6 +192,9 @@
|
|||
<data name="ui_enable_appdata" xml:space="preserve">
|
||||
<value>Save files to AppData</value>
|
||||
</data>
|
||||
<data name="ui_enable_autodownload" xml:space="preserve">
|
||||
<value>Download updates automatically</value>
|
||||
</data>
|
||||
<data name="ui_enable_logging" xml:space="preserve">
|
||||
<value>Enable logging to file</value>
|
||||
</data>
|
||||
|
|
|
@ -35,9 +35,19 @@
|
|||
<ui:ToggleSwitch x:Name="chkLog" Checked="chkLog_Checked" Unchecked="chkLog_Unchecked"/>
|
||||
</ui:CardControl>
|
||||
|
||||
<ui:CardControl Grid.Row="3" Margin="0,12,0,0" Icon="Folder24" Header="{x:Static p:Resources.ui_enable_appdata}" >
|
||||
<ui:ToggleSwitch x:Name="chkAppdata" Checked="chkAppdata_Checked" Unchecked="chkAppdata_Unchecked"/>
|
||||
</ui:CardControl>
|
||||
<Grid Grid.Row="3">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="1*"/>
|
||||
<ColumnDefinition Width="5"/>
|
||||
<ColumnDefinition Width="1*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<ui:CardControl Grid.Column="0" Margin="0,12,0,0" Icon="Folder24" Header="{x:Static p:Resources.ui_enable_appdata}" VerticalAlignment="Top" >
|
||||
<ui:ToggleSwitch x:Name="chkAppdata" Checked="chkAppdata_Checked" Unchecked="chkAppdata_Unchecked"/>
|
||||
</ui:CardControl>
|
||||
<ui:CardControl Grid.Column="2" Margin="0,12,0,0" Icon="ArrowDownload24" Header="{x:Static p:Resources.ui_enable_autodownload}" VerticalAlignment="Top">
|
||||
<ui:ToggleSwitch x:Name="chkAutodl" Checked="chkAutodl_Checked" Unchecked="chkAutodl_Unchecked"/>
|
||||
</ui:CardControl>
|
||||
</Grid>
|
||||
|
||||
<Label Grid.Row="4" Content="{x:Static p:Resources.ui_licenses}" HorizontalAlignment="Left" VerticalAlignment="Top" FontWeight="Bold"/>
|
||||
<ScrollViewer Grid.Row="5" MaxHeight="700" HorizontalAlignment="Stretch">
|
||||
|
|
|
@ -30,6 +30,16 @@ namespace EnvyUpdate
|
|||
if (!GlobalVars.hasWrite)
|
||||
chkAppdata.IsEnabled = false;
|
||||
|
||||
if (GlobalVars.autoDownload)
|
||||
chkAutodl.IsChecked = true;
|
||||
|
||||
if (GlobalVars.isDownloading)
|
||||
{
|
||||
chkAppdata.IsEnabled = false;
|
||||
}
|
||||
else
|
||||
chkAppdata.IsEnabled = true;
|
||||
|
||||
textBoxLicEnvyupdate.Text = Properties.Licenses.EnvyUpdate;
|
||||
textBoxLicFody.Text = Properties.Licenses.Fody;
|
||||
textBoxLicCostura.Text = Properties.Licenses.CosturaFody;
|
||||
|
@ -91,5 +101,23 @@ namespace EnvyUpdate
|
|||
|
||||
Debug.LogToFile("INFO Switched to EXE directory.");
|
||||
}
|
||||
|
||||
private void chkAutodl_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
GlobalVars.autoDownload = true;
|
||||
if (!File.Exists(Path.Combine(GlobalVars.saveDirectory, "autodl.envy")))
|
||||
{
|
||||
File.Create(Path.Combine(GlobalVars.saveDirectory, "autodl.envy"));
|
||||
}
|
||||
}
|
||||
|
||||
private void chkAutodl_Unchecked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
GlobalVars.autoDownload = false;
|
||||
if (File.Exists(Path.Combine(GlobalVars.saveDirectory, "autodl.envy")))
|
||||
{
|
||||
File.Delete(Path.Combine(GlobalVars.saveDirectory, "autodl.envy"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue