Removed autoDedupFrames, cleanup, Servers.cs backport from Installer

This commit is contained in:
n00mkrad
2021-09-07 14:51:53 +02:00
parent f563b7cca3
commit 316adecefc
6 changed files with 28 additions and 94 deletions

View File

@@ -2,15 +2,16 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Flowframes.Data
{
class Servers
{
public static Server hetznerEu = new Server { host = "nmkd-hz.de", pattern = "https://dl.*" };
public static Server contaboUs = new Server { host = "nmkd-cb.de", pattern = "https://dl.*" };
public static Server hetznerEu = new Server { name = "Germany (Nürnberg)", host = "nmkd-hz.de", pattern = "https://dl.*" };
public static Server contaboUs = new Server { name = "USA (St. Louis)", host = "nmkd-cb.de", pattern = "https://dl.*" };
public static List<Server> serverList = new List<Server> { hetznerEu, contaboUs };
@@ -18,38 +19,48 @@ namespace Flowframes.Data
public class Server
{
public string name = "";
public string host = "";
public string pattern = "*";
public string GetUrl ()
public string GetUrl()
{
return pattern.Replace("*", host);
}
}
public static async Task Init ()
public static async Task Init(ComboBox comboBox = null)
{
Dictionary<string[], long> serversPings = new Dictionary<string[], long>();
foreach(Server server in serverList)
foreach (Server server in serverList)
{
try
{
Ping p = new Ping();
PingReply replyEur = p.Send(server.host, 2000);
serversPings[new string[] { server.host, server.pattern }] = replyEur.RoundtripTime;
serversPings[new string[] { server.name, server.host, server.pattern }] = replyEur.RoundtripTime;
Logger.Log($"[Servers] Ping to {server.host}: {replyEur.RoundtripTime} ms", true);
}
catch (Exception e)
{
Logger.Log($"[Servers] Failed to ping {server.host}: {e.Message}", true);
serversPings[new string[] { server.host, server.pattern }] = 10000;
serversPings[new string[] { server.name, server.host, server.pattern }] = 10000;
}
}
var closest = serversPings.Aggregate((l, r) => l.Value < r.Value ? l : r);
Logger.Log($"[Servers] Closest Server: {closest.Key[0]} ({closest.Value} ms)", true);
closestServer = new Server { host = closest.Key[0], pattern = closest.Key[1] };
closestServer = new Server { name = closest.Key[0], host = closest.Key[1], pattern = closest.Key[2] };
if (comboBox != null)
{
for (int i = 0; i < comboBox.Items.Count; i++)
{
if (comboBox.Items[i].ToString() == closestServer.name)
comboBox.SelectedIndex = i;
}
}
}
}
}

View File

@@ -174,7 +174,6 @@
this.debugTab = new Cyotek.Windows.Forms.TabListPage();
this.ffEncArgs = new System.Windows.Forms.TextBox();
this.label56 = new System.Windows.Forms.Label();
this.label48 = new System.Windows.Forms.Label();
this.label54 = new System.Windows.Forms.Label();
this.ffEncPreset = new System.Windows.Forms.ComboBox();
this.label47 = new System.Windows.Forms.Label();
@@ -183,9 +182,6 @@
this.label38 = new System.Windows.Forms.Label();
this.ffEncThreads = new System.Windows.Forms.TextBox();
this.label37 = new System.Windows.Forms.Label();
this.panel9 = new System.Windows.Forms.Panel();
this.autoDedupFrames = new System.Windows.Forms.ComboBox();
this.label7 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.cmdDebugMode = new System.Windows.Forms.ComboBox();
this.titleLabel = new System.Windows.Forms.Label();
@@ -2028,7 +2024,6 @@
this.debugTab.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
this.debugTab.Controls.Add(this.ffEncArgs);
this.debugTab.Controls.Add(this.label56);
this.debugTab.Controls.Add(this.label48);
this.debugTab.Controls.Add(this.label54);
this.debugTab.Controls.Add(this.ffEncPreset);
this.debugTab.Controls.Add(this.label47);
@@ -2037,9 +2032,6 @@
this.debugTab.Controls.Add(this.label38);
this.debugTab.Controls.Add(this.ffEncThreads);
this.debugTab.Controls.Add(this.label37);
this.debugTab.Controls.Add(this.panel9);
this.debugTab.Controls.Add(this.autoDedupFrames);
this.debugTab.Controls.Add(this.label7);
this.debugTab.Controls.Add(this.label3);
this.debugTab.Controls.Add(this.cmdDebugMode);
this.debugTab.ForeColor = System.Drawing.Color.White;
@@ -2054,7 +2046,7 @@
this.ffEncArgs.Location = new System.Drawing.Point(280, 210);
this.ffEncArgs.MinimumSize = new System.Drawing.Size(4, 21);
this.ffEncArgs.Name = "ffEncArgs";
this.ffEncArgs.Size = new System.Drawing.Size(400, 21);
this.ffEncArgs.Size = new System.Drawing.Size(400, 20);
this.ffEncArgs.TabIndex = 85;
//
// label56
@@ -2067,17 +2059,6 @@
this.label56.TabIndex = 84;
this.label56.Text = "Additional (Output) Arguments";
//
// label48
//
this.label48.AutoSize = true;
this.label48.ForeColor = System.Drawing.Color.Silver;
this.label48.Location = new System.Drawing.Point(570, 71);
this.label48.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7);
this.label48.Name = "label48";
this.label48.Size = new System.Drawing.Size(169, 13);
this.label48.TabIndex = 83;
this.label48.Text = "Use 0 to disable (check all frames)";
//
// label54
//
this.label54.AutoSize = true;
@@ -2159,7 +2140,7 @@
this.ffEncThreads.Location = new System.Drawing.Point(280, 150);
this.ffEncThreads.MinimumSize = new System.Drawing.Size(4, 21);
this.ffEncThreads.Name = "ffEncThreads";
this.ffEncThreads.Size = new System.Drawing.Size(250, 21);
this.ffEncThreads.Size = new System.Drawing.Size(250, 20);
this.ffEncThreads.TabIndex = 70;
//
// label37
@@ -2172,44 +2153,6 @@
this.label37.TabIndex = 61;
this.label37.Text = "Override FFmpeg Encoding Thread Count";
//
// panel9
//
this.panel9.BackgroundImage = global::Flowframes.Properties.Resources.baseline_create_white_18dp_semiTransparent;
this.panel9.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.panel9.Location = new System.Drawing.Point(536, 67);
this.panel9.Name = "panel9";
this.panel9.Size = new System.Drawing.Size(21, 21);
this.panel9.TabIndex = 60;
this.toolTip1.SetToolTip(this.panel9, "Allows custom input.");
//
// autoDedupFrames
//
this.autoDedupFrames.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
this.autoDedupFrames.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.autoDedupFrames.ForeColor = System.Drawing.Color.White;
this.autoDedupFrames.FormattingEnabled = true;
this.autoDedupFrames.Items.AddRange(new object[] {
"0",
"25",
"50",
"100",
"250",
"500"});
this.autoDedupFrames.Location = new System.Drawing.Point(280, 67);
this.autoDedupFrames.Name = "autoDedupFrames";
this.autoDedupFrames.Size = new System.Drawing.Size(250, 21);
this.autoDedupFrames.TabIndex = 34;
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(10, 70);
this.label7.Margin = new System.Windows.Forms.Padding(10, 10, 10, 7);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(224, 13);
this.label7.TabIndex = 33;
this.label7.Text = "Amount Of Non-Dupe Frames Before Skipping";
//
// label3
//
this.label3.AutoSize = true;
@@ -2333,8 +2276,6 @@
private Cyotek.Windows.Forms.TabListPage vidExportTab;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.ComboBox autoDedupFrames;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label23;
private System.Windows.Forms.ComboBox maxFpsMode;
private System.Windows.Forms.Label label22;
@@ -2354,7 +2295,6 @@
private System.Windows.Forms.ToolTip toolTip1;
private System.Windows.Forms.Panel panel8;
private System.Windows.Forms.Panel panel7;
private System.Windows.Forms.Panel panel9;
private System.Windows.Forms.Label label34;
private System.Windows.Forms.Panel panel10;
private System.Windows.Forms.ComboBox maxVidHeight;
@@ -2389,7 +2329,6 @@
private System.Windows.Forms.Panel panel14;
private System.Windows.Forms.Label label49;
private System.Windows.Forms.ComboBox autoEncMode;
private System.Windows.Forms.Label label48;
private System.Windows.Forms.CheckBox sbsAllowAutoEnc;
private System.Windows.Forms.Label label53;
private System.Windows.Forms.Label label30;

View File

@@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace Flowframes.IO
{
internal class Config
class Config
{
private static string configPath;
public static Dictionary<string, string> cachedValues = new Dictionary<string, string>();
@@ -38,7 +38,7 @@ namespace Flowframes.IO
catch(Exception e)
{
retries -= 1;
Logger.Log($"Failed to reset config: {e.Message}. Retrying ({retries} attempts left).");
Logger.Log($"Failed to reset config: {e.Message}. Retrying ({retries} attempts left).", true);
await Task.Delay(500);
await Reset(retries, settingsForm);
}

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Flowframes.IO

View File

@@ -846,7 +846,7 @@ namespace Flowframes.IO
}
catch (Exception e)
{
Logger.Log($"Failed to create file at '{path}': {e.Message}");
Logger.Log($"Failed to create file at '{path}': {e.Message}", true);
return false;
}
}

View File

@@ -72,10 +72,6 @@ namespace Flowframes.Magick
int statsFramesKept = 0;
int statsFramesDeleted = 0;
int skipAfterNoDupesFrames = Config.GetInt(Config.Key.autoDedupFrames);
bool hasEncounteredAnyDupes = false;
bool skipped = false;
bool hasReachedEnd = false;
string fileContent = "";
@@ -114,8 +110,8 @@ namespace Flowframes.Magick
{
framesToDelete.Add(frame2);
if (debugLog) Logger.Log("Deduplication: Deleted " + Path.GetFileName(frame2));
hasEncounteredAnyDupes = true;
}
statsFramesDeleted++;
currentDupeCount++;
}
@@ -135,6 +131,7 @@ namespace Flowframes.Magick
sw.Restart();
Logger.Log($"Deduplication: Running de-duplication ({i}/{framePaths.Length}), deleted {statsFramesDeleted} ({(((float)statsFramesDeleted / framePaths.Length) * 100f).ToString("0")}%) duplicate frames so far...", false, true);
Program.mainForm.SetProgress((int)Math.Round(((float)i / framePaths.Length) * 100f));
if (imageCache.Count > bufferSize || (imageCache.Count > 50 && OsUtils.GetFreeRamMb() < 3500))
ClearCache();
}
@@ -150,12 +147,6 @@ namespace Flowframes.Magick
await Task.Delay(1);
if (Interpolate.canceled) return;
if (!testRun && skipIfNoDupes && !hasEncounteredAnyDupes && skipAfterNoDupesFrames > 0 && i >= skipAfterNoDupesFrames)
{
skipped = true;
break;
}
}
foreach (string frame in framesToDelete)
@@ -170,10 +161,7 @@ namespace Flowframes.Magick
float percentDeleted = ((float)framesDeleted / framePaths.Length) * 100f;
string keptPercent = $"{(100f - percentDeleted).ToString("0.0")}%";
if (skipped)
Logger.Log($"Deduplication: First {skipAfterNoDupesFrames} frames did not have any duplicates - Skipping the rest!", false, true);
else
Logger.Log($"[Deduplication]{testStr} Done. Kept {framesLeft} ({keptPercent}) frames, deleted {framesDeleted} frames.", false, true);
Logger.Log($"[Deduplication]{testStr} Done. Kept {framesLeft} ({keptPercent}) frames, deleted {framesDeleted} frames.", false, true);
if (statsFramesKept <= 0)
Interpolate.Cancel("No frames were left after de-duplication!\n\nTry decreasing the de-duplication threshold.");