Check args to open model downloader, add checkboxes for AIs in mdl downloader

This commit is contained in:
N00MKRAD
2021-06-23 15:21:52 +02:00
parent 7949fbb40e
commit 8dd1e7072a
7 changed files with 118 additions and 18 deletions

View File

@@ -15,6 +15,7 @@ using Flowframes.Data;
using Microsoft.WindowsAPICodePack.Taskbar;
using Flowframes.MiscUtils;
using System.Threading.Tasks;
using System.Linq;
namespace Flowframes
{
@@ -49,8 +50,11 @@ namespace Flowframes
InterpolationProgress.preview = previewPicturebox;
UpdateStepByStepControls();
Initialized();
HandleArguments();
HandleFileArgs();
Text = $"Flowframes";
if (Program.args.Contains("show-model-downloader"))
new ModelDownloadForm().ShowDialog();
}
private async void Form1_Shown(object sender, EventArgs e)
@@ -83,14 +87,13 @@ namespace Flowframes
}
}
void HandleArguments()
void HandleFileArgs()
{
try
{
string[] args = Environment.GetCommandLineArgs();
List<string> files = new List<string>();
foreach (string arg in args)
foreach (string arg in Program.args)
if (Path.GetExtension(arg) != ".exe" && IOUtils.IsFileValid(arg))
files.Add(arg);
@@ -99,7 +102,7 @@ namespace Flowframes
}
catch (Exception e)
{
Logger.Log($"Failed to load input from given launch arguments.");
Logger.Log($"Failed to load input from given launch arguments.", true);
Logger.Log($"{e.Message}\n{e.StackTrace}", true);
}
}

View File

@@ -38,28 +38,34 @@ namespace Flowframes.Forms
this.closeBtn = new HTAlt.WinForms.HTButton();
this.cancelBtn = new HTAlt.WinForms.HTButton();
this.statusLabel = new System.Windows.Forms.Label();
this.rifeCuda = new System.Windows.Forms.CheckBox();
this.rifeNcnn = new System.Windows.Forms.CheckBox();
this.dainNcnn = new System.Windows.Forms.CheckBox();
this.flavrCuda = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// longProgBar
//
this.longProgBar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.longProgBar.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.longProgBar.BorderThickness = 0;
this.longProgBar.Location = new System.Drawing.Point(12, 254);
this.longProgBar.Location = new System.Drawing.Point(12, 274);
this.longProgBar.Name = "longProgBar";
this.longProgBar.Size = new System.Drawing.Size(600, 15);
this.longProgBar.TabIndex = 34;
//
// downloadModelsBtn
//
this.downloadModelsBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.downloadModelsBtn.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.downloadModelsBtn.FlatAppearance.BorderSize = 0;
this.downloadModelsBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.downloadModelsBtn.ForeColor = System.Drawing.Color.White;
this.downloadModelsBtn.Location = new System.Drawing.Point(12, 219);
this.downloadModelsBtn.Location = new System.Drawing.Point(12, 239);
this.downloadModelsBtn.Name = "downloadModelsBtn";
this.downloadModelsBtn.Size = new System.Drawing.Size(150, 23);
this.downloadModelsBtn.TabIndex = 87;
this.downloadModelsBtn.Text = "Download All Model Files";
this.downloadModelsBtn.Text = "Download Model Files";
this.downloadModelsBtn.UseVisualStyleBackColor = false;
this.downloadModelsBtn.Click += new System.EventHandler(this.downloadModelsBtn_Click);
//
@@ -119,11 +125,12 @@ namespace Flowframes.Forms
//
// closeBtn
//
this.closeBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.closeBtn.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.closeBtn.FlatAppearance.BorderSize = 0;
this.closeBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.closeBtn.ForeColor = System.Drawing.Color.White;
this.closeBtn.Location = new System.Drawing.Point(168, 219);
this.closeBtn.Location = new System.Drawing.Point(168, 239);
this.closeBtn.Name = "closeBtn";
this.closeBtn.Size = new System.Drawing.Size(150, 23);
this.closeBtn.TabIndex = 92;
@@ -133,11 +140,12 @@ namespace Flowframes.Forms
//
// cancelBtn
//
this.cancelBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.cancelBtn.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.cancelBtn.FlatAppearance.BorderSize = 0;
this.cancelBtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.cancelBtn.ForeColor = System.Drawing.Color.White;
this.cancelBtn.Location = new System.Drawing.Point(168, 219);
this.cancelBtn.Location = new System.Drawing.Point(168, 239);
this.cancelBtn.Name = "cancelBtn";
this.cancelBtn.Size = new System.Drawing.Size(150, 23);
this.cancelBtn.TabIndex = 93;
@@ -155,12 +163,68 @@ namespace Flowframes.Forms
this.statusLabel.Size = new System.Drawing.Size(0, 13);
this.statusLabel.TabIndex = 94;
//
// rifeCuda
//
this.rifeCuda.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.rifeCuda.AutoSize = true;
this.rifeCuda.Checked = true;
this.rifeCuda.CheckState = System.Windows.Forms.CheckState.Checked;
this.rifeCuda.Location = new System.Drawing.Point(12, 203);
this.rifeCuda.Name = "rifeCuda";
this.rifeCuda.Size = new System.Drawing.Size(83, 17);
this.rifeCuda.TabIndex = 95;
this.rifeCuda.Text = "RIFE CUDA";
this.rifeCuda.UseVisualStyleBackColor = true;
//
// rifeNcnn
//
this.rifeNcnn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.rifeNcnn.AutoSize = true;
this.rifeNcnn.Checked = true;
this.rifeNcnn.CheckState = System.Windows.Forms.CheckState.Checked;
this.rifeNcnn.Location = new System.Drawing.Point(101, 203);
this.rifeNcnn.Name = "rifeNcnn";
this.rifeNcnn.Size = new System.Drawing.Size(84, 17);
this.rifeNcnn.TabIndex = 96;
this.rifeNcnn.Text = "RIFE NCNN";
this.rifeNcnn.UseVisualStyleBackColor = true;
//
// dainNcnn
//
this.dainNcnn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.dainNcnn.AutoSize = true;
this.dainNcnn.Checked = true;
this.dainNcnn.CheckState = System.Windows.Forms.CheckState.Checked;
this.dainNcnn.Location = new System.Drawing.Point(191, 203);
this.dainNcnn.Name = "dainNcnn";
this.dainNcnn.Size = new System.Drawing.Size(86, 17);
this.dainNcnn.TabIndex = 97;
this.dainNcnn.Text = "DAIN NCNN";
this.dainNcnn.UseVisualStyleBackColor = true;
//
// flavrCuda
//
this.flavrCuda.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.flavrCuda.AutoSize = true;
this.flavrCuda.Checked = true;
this.flavrCuda.CheckState = System.Windows.Forms.CheckState.Checked;
this.flavrCuda.Location = new System.Drawing.Point(283, 203);
this.flavrCuda.Name = "flavrCuda";
this.flavrCuda.Size = new System.Drawing.Size(93, 17);
this.flavrCuda.TabIndex = 98;
this.flavrCuda.Text = "FLAVR CUDA";
this.flavrCuda.UseVisualStyleBackColor = true;
//
// ModelDownloadForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(32)))), ((int)(((byte)(32)))), ((int)(((byte)(32)))));
this.ClientSize = new System.Drawing.Size(624, 281);
this.ClientSize = new System.Drawing.Size(624, 301);
this.Controls.Add(this.flavrCuda);
this.Controls.Add(this.dainNcnn);
this.Controls.Add(this.rifeNcnn);
this.Controls.Add(this.rifeCuda);
this.Controls.Add(this.statusLabel);
this.Controls.Add(this.closeBtn);
this.Controls.Add(this.cancelBtn);
@@ -191,5 +255,9 @@ namespace Flowframes.Forms
private HTAlt.WinForms.HTButton closeBtn;
private HTAlt.WinForms.HTButton cancelBtn;
private System.Windows.Forms.Label statusLabel;
private System.Windows.Forms.CheckBox rifeCuda;
private System.Windows.Forms.CheckBox rifeNcnn;
private System.Windows.Forms.CheckBox dainNcnn;
private System.Windows.Forms.CheckBox flavrCuda;
}
}

View File

@@ -58,7 +58,11 @@ namespace Flowframes.Forms
private void downloadModelsBtn_Click(object sender, EventArgs e)
{
ModelDownloadFormUtils.form = this;
ModelDownloadFormUtils.DownloadAll();
bool rifeC = rifeCuda.Checked;
bool rifeN = rifeNcnn.Checked;
bool dainN = dainNcnn.Checked;
bool flavrC = flavrCuda.Checked;
ModelDownloadFormUtils.DownloadModels(rifeC, rifeN, dainN, flavrC);
}
private void cancelBtn_Click(object sender, EventArgs e)

View File

@@ -123,7 +123,7 @@ This means that each model gets downloaded if you use it for the first time - af
However, if you want to use all models offline (or if you are going to copy Flowframes to a machine without internet connection), you can pre-download all model files here.
Download model files now (3 GB)? </value>
Download model files now?</value>
</data>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">

View File

@@ -39,10 +39,15 @@ namespace Flowframes.Forms
modelFoldersBytes += IOUtils.GetDirSize(modelFolder, true);
if (modelFoldersBytes > 1024 * 1024)
{
clearModelCacheBtn.Enabled = true;
clearModelCacheBtn.Text = $"Clear Model Cache ({FormatUtils.Bytes(modelFoldersBytes)})";
}
else
{
clearModelCacheBtn.Enabled = false;
}
}
private void SettingsForm_FormClosing(object sender, FormClosingEventArgs e)
{
@@ -233,6 +238,7 @@ namespace Flowframes.Forms
private void modelDownloaderBtn_Click(object sender, EventArgs e)
{
new ModelDownloadForm().ShowDialog();
CheckModelCacheSize();
}
}
}

View File

@@ -15,10 +15,19 @@ namespace Flowframes.MiscUtils
static int tasksToDo = 0;
static bool canceled = false;
public static async Task DownloadAll ()
public static async Task DownloadModels (bool rifeC, bool rifeN, bool dainN, bool flavrC)
{
canceled = false;
AI[] ais = new AI[] { Networks.rifeCuda, Networks.rifeNcnn, Networks.dainNcnn, Networks.flavrCuda };
List<AI> ais = new List<AI>();
if (rifeC) ais.Add(Networks.rifeCuda);
if (rifeN) ais.Add(Networks.rifeNcnn);
if (dainN) ais.Add(Networks.dainNcnn);
if (flavrC) ais.Add(Networks.flavrCuda);
if (ais.Count < 1)
return;
taskCounter = 0;
tasksToDo = GetTaskCount(ais);
form.SetWorking(true);
@@ -54,7 +63,7 @@ namespace Flowframes.MiscUtils
ModelDownloader.canceled = true;
}
public static int GetTaskCount (AI[] ais)
public static int GetTaskCount (List<AI> ais)
{
int count = 0;

View File

@@ -1,9 +1,11 @@
using Flowframes.Data;
using Flowframes.Forms;
using Flowframes.IO;
using Flowframes.MiscUtils;
using Flowframes.OS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
@@ -15,6 +17,7 @@ namespace Flowframes
{
static class Program
{
public static string[] args = new string[0];
public static Form1 mainForm;
public static bool busy = false;
@@ -37,7 +40,14 @@ namespace Flowframes
Networks.Init();
Task.Run(() => DiskSpaceCheckLoop());
args = Environment.GetCommandLineArgs().Where(a => a[0] == '-').Select(x => x.Trim().Substring(1).ToLowerInvariant()).ToArray();
Logger.Log($"Args: {(args.Length > 0 ? string.Join(", -", args) : "None")}", false);
LaunchMainForm();
}
static void LaunchMainForm()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
@@ -64,13 +74,13 @@ namespace Flowframes
ShowUnhandledError(text);
}
static void ShowUnhandledError (string text)
static void ShowUnhandledError(string text)
{
MessageBox.Show(text, "Unhandled Error");
Clipboard.SetText(text);
}
static async Task DiskSpaceCheckLoop ()
static async Task DiskSpaceCheckLoop()
{
while (true)
{