upgrade download bugfix
This commit is contained in:
parent
491aa67a81
commit
e61418c677
@ -13,7 +13,7 @@
|
||||
<!-- <PublishSingleFile>true</PublishSingleFile> -->
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
|
||||
<Version>5.1.9.13</Version>
|
||||
<Version>5.1.10.1</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@ -277,8 +277,8 @@ namespace LibationLauncher
|
||||
|
||||
{ // appsettings.json
|
||||
var appSettingsKey = UNSAFE_MigrationHelper.LIBATION_FILES_KEY;
|
||||
if (UNSAFE_MigrationHelper.AppSettings_TryGet(appSettingsKey, out var value))
|
||||
UNSAFE_MigrationHelper.AppSettings_Update(appSettingsKey, translatePath(value));
|
||||
if (UNSAFE_MigrationHelper.APPSETTINGS_TryGet(appSettingsKey, out var value))
|
||||
UNSAFE_MigrationHelper.APPSETTINGS_Update(appSettingsKey, translatePath(value));
|
||||
}
|
||||
}
|
||||
|
||||
@ -421,8 +421,7 @@ namespace LibationLauncher
|
||||
|
||||
try
|
||||
{
|
||||
LibationWinForms.BookLiberation.ProcessorAutomationController.DownloadFileAsync(zipUrl, selectedPath).GetAwaiter().GetResult();
|
||||
MessageBox.Show("File downloaded");
|
||||
LibationWinForms.BookLiberation.ProcessorAutomationController.DownloadFile(zipUrl, selectedPath, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@ -12,44 +12,44 @@ namespace LibationLauncher
|
||||
internal static class UNSAFE_MigrationHelper
|
||||
{
|
||||
#region appsettings.json
|
||||
public const string APPSETTINGS_JSON = "appsettings.json";
|
||||
private const string APPSETTINGS_JSON = "appsettings.json";
|
||||
|
||||
public static bool AppSettingsJson_Exists => File.Exists(APPSETTINGS_JSON);
|
||||
public static bool APPSETTINGS_Json_Exists => File.Exists(APPSETTINGS_JSON);
|
||||
|
||||
public static bool AppSettings_TryGet(string key, out string value)
|
||||
public static bool APPSETTINGS_TryGet(string key, out string value)
|
||||
{
|
||||
bool success = false;
|
||||
JToken val = null;
|
||||
|
||||
process_AppSettingsJson(jObj => success = jObj.TryGetValue(key, out val), false);
|
||||
process_APPSETTINGS_Json(jObj => success = jObj.TryGetValue(key, out val), false);
|
||||
|
||||
value = success ? val.Value<string>() : null;
|
||||
return success;
|
||||
}
|
||||
|
||||
/// <summary>only insert if not exists</summary>
|
||||
public static void AppSettings_Insert(string key, string value)
|
||||
=> process_AppSettingsJson(jObj => jObj.TryAdd(key, value));
|
||||
public static void APPSETTINGS_Insert(string key, string value)
|
||||
=> process_APPSETTINGS_Json(jObj => jObj.TryAdd(key, value));
|
||||
|
||||
/// <summary>only update if exists</summary>
|
||||
public static void AppSettings_Update(string key, string value)
|
||||
=> process_AppSettingsJson(jObj => {
|
||||
public static void APPSETTINGS_Update(string key, string value)
|
||||
=> process_APPSETTINGS_Json(jObj => {
|
||||
if (jObj.ContainsKey(key))
|
||||
jObj[key] = value;
|
||||
});
|
||||
|
||||
/// <summary>only delete if exists</summary>
|
||||
public static void AppSettings_Delete(string key)
|
||||
=> process_AppSettingsJson(jObj => {
|
||||
public static void APPSETTINGS_Delete(string key)
|
||||
=> process_APPSETTINGS_Json(jObj => {
|
||||
if (jObj.ContainsKey(key))
|
||||
jObj.Remove(key);
|
||||
});
|
||||
|
||||
/// <param name="save">True: save if contents changed. False: no not attempt save</param>
|
||||
private static void process_AppSettingsJson(Action<JObject> action, bool save = true)
|
||||
private static void process_APPSETTINGS_Json(Action<JObject> action, bool save = true)
|
||||
{
|
||||
// only insert if not exists
|
||||
if (!AppSettingsJson_Exists)
|
||||
if (!APPSETTINGS_Json_Exists)
|
||||
return;
|
||||
|
||||
var startingContents = File.ReadAllText(APPSETTINGS_JSON);
|
||||
@ -73,13 +73,13 @@ namespace LibationLauncher
|
||||
|
||||
#region Settings.json
|
||||
public const string LIBATION_FILES_KEY = "LibationFiles";
|
||||
public const string SETTINGS_JSON = "Settings.json";
|
||||
private const string SETTINGS_JSON = "Settings.json";
|
||||
|
||||
public static string SettingsJsonPath
|
||||
{
|
||||
get
|
||||
{
|
||||
var success = AppSettings_TryGet(LIBATION_FILES_KEY, out var value);
|
||||
var success = APPSETTINGS_TryGet(LIBATION_FILES_KEY, out var value);
|
||||
return !success || value is null ? null : Path.Combine(value, SETTINGS_JSON);
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ namespace LibationWinForms.BookLiberation
|
||||
lastUpdateLbl.UIThread(() => lastUpdateLbl.Visible = lastDownloadProgress.AddSeconds(30) < DateTime.Now);
|
||||
if (lastUpdateLbl.Visible)
|
||||
{
|
||||
var diff = lastDownloadProgress - DateTime.Now;
|
||||
var diff = DateTime.Now - lastDownloadProgress;
|
||||
var min = (int)diff.TotalMinutes;
|
||||
var minText = min > 0 ? $"{min}min " : "";
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using DataLayer;
|
||||
using Dinah.Core.ErrorHandling;
|
||||
using Dinah.Core.Windows.Forms;
|
||||
using FileLiberator;
|
||||
|
||||
namespace LibationWinForms.BookLiberation
|
||||
@ -168,21 +169,27 @@ namespace LibationWinForms.BookLiberation
|
||||
return downloadPdf;
|
||||
}
|
||||
|
||||
public static async Task DownloadFileAsync(string url, string destination)
|
||||
public static void DownloadFile(string url, string destination, bool showDownloadCompletedDialog = false)
|
||||
{
|
||||
var downloadDialog = new DownloadForm();
|
||||
downloadDialog.UpdateFilename(destination);
|
||||
downloadDialog.Show();
|
||||
|
||||
new System.Threading.Thread(() => {
|
||||
var downloadFile = new DownloadFile();
|
||||
|
||||
// frustratingly copy pasta from wireUpEvents(IDownloadable downloadable) due to Completed being EventHandler<LibraryBook>
|
||||
var downloadDialog = new DownloadForm();
|
||||
downloadFile.DownloadBegin += (_, str) =>
|
||||
downloadFile.DownloadProgressChanged += (_, progress) => downloadDialog.UIThread(() =>
|
||||
downloadDialog.DownloadProgressChanged(progress.BytesReceived, progress.TotalBytesToReceive)
|
||||
);
|
||||
downloadFile.DownloadCompleted += (_, __) => downloadDialog.UIThread(() =>
|
||||
{
|
||||
downloadDialog.UpdateFilename(str);
|
||||
downloadDialog.Show();
|
||||
};
|
||||
downloadFile.DownloadProgressChanged += (_, progress) => downloadDialog.DownloadProgressChanged(progress.BytesReceived, progress.TotalBytesToReceive);
|
||||
downloadFile.DownloadCompleted += (_, __) => downloadDialog.Close();
|
||||
downloadDialog.Close();
|
||||
if (showDownloadCompletedDialog)
|
||||
MessageBox.Show("File downloaded");
|
||||
});
|
||||
|
||||
await downloadFile.PerformDownloadFileAsync(url, destination);
|
||||
downloadFile.PerformDownloadFileAsync(url, destination).GetAwaiter().GetResult();
|
||||
}).Start();
|
||||
}
|
||||
|
||||
// subscribed to Begin event because a new form should be created+processed+closed on each iteration
|
||||
|
||||
@ -37,6 +37,9 @@ namespace LibationWinForms
|
||||
|
||||
private void Form1_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (this.DesignMode)
|
||||
return;
|
||||
|
||||
// load default/missing cover images. this will also initiate the background image downloader
|
||||
var format = System.Drawing.Imaging.ImageFormat.Jpeg;
|
||||
PictureStorage.SetDefaultImage(PictureSize._80x80, Properties.Resources.default_cover_80x80.ToBytes(format));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user