Skip to content

Commit 5c1081d

Browse files
committed
av1an encodes (temp folders) can now be resumed and deleted from the GUI
1 parent cb2bb7f commit 5c1081d

File tree

11 files changed

+3623
-68
lines changed

11 files changed

+3623
-68
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using Nmkoder.Extensions;
2+
using Nmkoder.IO;
3+
using Nmkoder.UI.Tasks;
4+
using Nmkoder.Utils;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.IO;
8+
using System.Linq;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
12+
namespace Nmkoder.Data.Ui
13+
{
14+
public class Av1anFolderEntry
15+
{
16+
public Dictionary<string, string> jsonInfo { get; } = null;
17+
public DirectoryInfo DirInfo { get; }
18+
public FileInfo InputFile { get; }
19+
public FileInfo[] ChunkFiles { get; }
20+
public string InputFilename { get; } = "";
21+
public string TempFolderName { get; } = "";
22+
public string Args { get; } = "";
23+
public DateTime CreationDate { get; }
24+
public DateTime LastRunDate { get; }
25+
26+
public Av1anFolderEntry(string path)
27+
{
28+
DirInfo = new DirectoryInfo(path);
29+
jsonInfo = Av1an.LoadJson(DirInfo.Name);
30+
ChunkFiles = IoUtils.GetFileInfosSorted(Path.Combine(path, "encode"));
31+
32+
InputFilename = (jsonInfo.ContainsKey("fileName") ? jsonInfo["fileName"] : DirInfo.Name).Trunc(30);
33+
34+
if (jsonInfo.ContainsKey("filePath"))
35+
InputFile = File.Exists(jsonInfo["filePath"]) ? new FileInfo(jsonInfo["filePath"]) : null;
36+
37+
CreationDate = new DateTime(1970, 1, 1, 0, 0, 0, 0);
38+
39+
if (jsonInfo.ContainsKey("creationTimestamp"))
40+
CreationDate = CreationDate.AddMilliseconds(long.Parse(jsonInfo["creationTimestamp"]));
41+
42+
LastRunDate = new DateTime(1970, 1, 1, 0, 0, 0, 0);
43+
44+
if (jsonInfo.ContainsKey("lastRunTimestamp"))
45+
LastRunDate = LastRunDate.AddMilliseconds(long.Parse(jsonInfo["lastRunTimestamp"]));
46+
47+
if (jsonInfo.ContainsKey("tempFolderName"))
48+
TempFolderName = jsonInfo["tempFolderName"];
49+
50+
if (jsonInfo.ContainsKey("args"))
51+
Args = jsonInfo["args"];
52+
}
53+
54+
public override string ToString()
55+
{
56+
string created = "???";
57+
58+
if (CreationDate != new DateTime(1970, 1, 1, 0, 0, 0, 0))
59+
{
60+
TimeSpan delta = DateTime.Now - CreationDate;
61+
created = $"{delta.Hours:00}:{delta.Minutes:00}:{delta.Seconds:00} Ago";
62+
}
63+
64+
string lastRun = "???";
65+
66+
if (LastRunDate != new DateTime(1970, 1, 1, 0, 0, 0, 0))
67+
{
68+
TimeSpan delta = DateTime.Now - LastRunDate;
69+
lastRun = $"{delta.Hours:00}:{delta.Minutes:00}:{delta.Seconds:00} Ago";
70+
}
71+
72+
string chunks = $"{ChunkFiles.Length} Chunks - {FormatUtils.Bytes(ChunkFiles.Sum(x => x.Length))}";
73+
return $"{InputFilename} - {chunks} - Created: {created} - Last Run: {lastRun}";
74+
}
75+
}
76+
}

ff-utils-winforms/Forms/Av1anResumeForm.Designer.cs

Lines changed: 136 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
using Nmkoder.Data;
2+
using Nmkoder.Data.Ui;
3+
using Nmkoder.IO;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.ComponentModel;
7+
using System.Data;
8+
using System.Drawing;
9+
using System.IO;
10+
using System.Linq;
11+
using System.Text;
12+
using System.Threading.Tasks;
13+
using System.Windows.Forms;
14+
15+
namespace Nmkoder.Forms
16+
{
17+
public partial class Av1anResumeForm : Form
18+
{
19+
20+
public Av1anFolderEntry ChosenEntry { get; set; } = null;
21+
public bool Resume { get; set; }
22+
public bool UseSavedCommand { get; set; }
23+
24+
public Av1anResumeForm()
25+
{
26+
InitializeComponent();
27+
}
28+
29+
private void Av1anResumeForm_Load(object sender, EventArgs e)
30+
{
31+
32+
}
33+
34+
private void Av1anResumeForm_Shown(object sender, EventArgs e)
35+
{
36+
ReloadList();
37+
}
38+
39+
private void ReloadList ()
40+
{
41+
folderList.Items.Clear();
42+
string av1anDir = Paths.GetAv1anTempPath();
43+
folderList.Items.AddRange(new DirectoryInfo(av1anDir).GetDirectories().Select(x => new Av1anFolderEntry(x.FullName)).ToArray());
44+
45+
if(folderList.Items.Count > 0)
46+
folderList.SelectedIndex = 0;
47+
else
48+
folderList.SelectedIndex = -1;
49+
}
50+
51+
private void Done()
52+
{
53+
ChosenEntry = (Av1anFolderEntry)folderList.SelectedItem;
54+
DialogResult = DialogResult.OK;
55+
Close();
56+
Program.mainForm.BringToFront();
57+
}
58+
59+
private void resumeWithSavedSettings_Click(object sender, EventArgs e)
60+
{
61+
Resume = true;
62+
UseSavedCommand = true;
63+
Done();
64+
}
65+
66+
private void resumeWithNewSettings_Click(object sender, EventArgs e)
67+
{
68+
Resume = true;
69+
UseSavedCommand = false;
70+
Done();
71+
}
72+
73+
private void DeleteFull_Click(object sender, EventArgs e)
74+
{
75+
try
76+
{
77+
if (folderList.SelectedItem == null)
78+
return;
79+
80+
Av1anFolderEntry entry = (Av1anFolderEntry)folderList.SelectedItem;
81+
IoUtils.DeleteIfExists(entry.DirInfo.FullName);
82+
IoUtils.DeleteIfExists(entry.DirInfo.FullName + ".json");
83+
}
84+
catch(Exception ex)
85+
{
86+
Logger.Log($"Failed to delete av1an folder: {ex.Message}");
87+
}
88+
89+
ReloadList();
90+
}
91+
92+
private void DeleteChunks_Click(object sender, EventArgs e)
93+
{
94+
try
95+
{
96+
if (folderList.SelectedItem == null)
97+
return;
98+
99+
Av1anFolderEntry entry = (Av1anFolderEntry)folderList.SelectedItem;
100+
IoUtils.DeleteIfExists(Path.Combine(entry.DirInfo.FullName, "encode"));
101+
}
102+
catch (Exception ex)
103+
{
104+
Logger.Log($"Failed to delete av1an encode folder: {ex.Message}");
105+
}
106+
107+
ReloadList();
108+
}
109+
}
110+
}

0 commit comments

Comments
 (0)