Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Re-Encode feature and some Gui improvements #59

Merged
merged 16 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,6 @@ ModelManifest.xml

dist/windows/OKEGui*.exe
dist/windows/tools/

# Visual Studio Code config files
.vscode/
33 changes: 21 additions & 12 deletions OKEGui/OKEGui/Gui/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Closing="MainWindow_Closing"
Title="OKEGui" Height="700" Width="1100" WindowStartupLocation="CenterScreen" Icon="App.ico" FontFamily="Segoe UI, Microsoft YaHei">
Title="OKEGui" Height="700" Width="1200" WindowStartupLocation="CenterScreen" Icon="App.ico" FontFamily="Segoe UI, Microsoft YaHei">
<Window.Resources>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
Expand Down Expand Up @@ -52,7 +52,7 @@
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="状态" Width="75">
<GridViewColumn Header="状态" Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock TextAlignment="Center" TextTrimming="CharacterEllipsis" Text="{Binding Path=CurrentStatus}"></TextBlock>
Expand Down Expand Up @@ -90,6 +90,13 @@
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="任务类型" Width="75">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock TextAlignment="Center" TextTrimming="CharacterEllipsis" Text="{Binding Path=TaskType}"></TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="工作单元" Width="75">
<GridViewColumn.CellTemplate>
<DataTemplate>
Expand Down Expand Up @@ -131,20 +138,22 @@
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>

<Button Grid.Column="0" Grid.Row="0" Margin="0,0,6,0" x:Name="BtnNew" Click="BtnNew_Click" Content="新建任务" />
<Button Grid.Column="1" Grid.Row="0" Margin="0,0,6,0" x:Name="BtnRun" Click="BtnRun_Click" Content="运行" />
<Button Grid.Column="2" Grid.Row="0" Margin="0,0,6,0" x:Name="BtnPause" Click="BtnPause_Click" Content="暂停" />
<Button Grid.Column="3" Grid.Row="0" Margin="0,0,6,0" x:Name="BtnResume" Click="BtnResume_Click" Content="恢复" />
<Button Grid.Column="4" Grid.Row="0" Margin="0,0,6,0" x:Name="BtnChap" Click="BtnChap_Click" Content="检查章节" />
<Button Grid.Column="5" Grid.Row="0" Margin="0,0,6,0" x:Name="BtnMoveUp" Click="BtnMoveUp_Click" Content="上移" />
<Button Grid.Column="6" Grid.Row="0" Margin="0,0,6,0" x:Name="BtnMoveDown" Click="BtnMoveDown_Click" Content="下移" />
<Button Grid.Column="7" Grid.Row="0" Margin="0,0,6,0" x:Name="BtnMoveTop" Click="BtnMoveTop_Click" Content="置顶" />
<Button Grid.Column="8" Grid.Row="0" Margin="0,0,6,0" x:Name="BtnDelete" Click="BtnDelete_Click" Content="删除" />
<Button Grid.Column="9" Grid.Row="0" Margin="0,0,6,0" x:Name="BtnEmpty" Click="BtnEmpty_Click" Content="清空" />
<TextBlock Margin="0,0,6,0" VerticalAlignment="Center" Grid.Column="10" Grid.Row="0" Name="WorkerNumber"></TextBlock>
<Button Grid.Column="11" Grid.Row="0" Margin="0,0,0,0" x:Name="BtnNewWorker" Click="BtnNewWorker_Click" Content="新建工作单元" Width="100" />
<Button Grid.Column="2" Grid.Row="0" Margin="0,0,6,0" x:Name="BtnStop" Click="BtnStop_Click" Content="终止" />
<Button Grid.Column="3" Grid.Row="0" Margin="0,0,6,0" x:Name="BtnPause" Click="BtnPause_Click" Content="暂停" />
<Button Grid.Column="4" Grid.Row="0" Margin="0,0,6,0" x:Name="BtnResume" Click="BtnResume_Click" Content="恢复" />
<Button Grid.Column="5" Grid.Row="0" Margin="0,0,6,0" x:Name="BtnChap" Click="BtnChap_Click" Content="更新章节" />
<Button Grid.Column="6" Grid.Row="0" Margin="0,0,6,0" x:Name="BtnMoveUp" Click="BtnMoveUp_Click" Content="上移" />
<Button Grid.Column="7" Grid.Row="0" Margin="0,0,6,0" x:Name="BtnMoveDown" Click="BtnMoveDown_Click" Content="下移" />
<Button Grid.Column="8" Grid.Row="0" Margin="0,0,6,0" x:Name="BtnMoveTop" Click="BtnMoveTop_Click" Content="置顶" />
<Button Grid.Column="9" Grid.Row="0" Margin="0,0,6,0" x:Name="BtnDelete" Click="BtnDelete_Click" Content="删除" />
<Button Grid.Column="10" Grid.Row="0" Margin="0,0,6,0" x:Name="BtnEmpty" Click="BtnEmpty_Click" Content="清空" />
<TextBlock Margin="0,0,6,0" VerticalAlignment="Center" Grid.Column="11" Grid.Row="0" Name="WorkerNumber" Width="100"></TextBlock>
<Button Grid.Column="12" Grid.Row="0" Margin="0,0,0,0" x:Name="BtnNewWorker" Click="BtnNewWorker_Click" Content="新建工作单元" Width="100" />
</Grid>

<Grid Margin="10, 0, 10, 10" VerticalAlignment="Bottom">
Expand Down
150 changes: 110 additions & 40 deletions OKEGui/OKEGui/Gui/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Reflection;
Expand Down Expand Up @@ -42,12 +43,14 @@ public MainWindow()
Title += " + VS portable " + ver;
}
catch { /* it's ok if VERSION doesn't exist. */ }
Title += " [" + Initializer.Config.vspipePath + "]";

TaskList.ItemsSource = tm.taskStatus;

wm = new WorkerManager(this, tm);

BtnRun.IsEnabled = false;
BtnStop.IsEnabled = false;
BtnMoveDown.IsEnabled = false;
BtnMoveUp.IsEnabled = false;
BtnMoveTop.IsEnabled = false;
Expand All @@ -65,21 +68,34 @@ public MainWindow()
WorkerCount++;
wm.AddWorker("工作单元-" + WorkerCount.ToString());
}
WorkerNumber.Text = "工作单元:" + WorkerCount.ToString();
WorkerNumber.Text = "工作单元数量: " + WorkerCount.ToString();

if (Initializer.Config.memoryTotal == WmiUtils.GetTotalPhysicalMemory())
{
TxtFreeMemory.Text = Initializer.Config.memoryLimit.ToString();
}
}

private void UpdatedActiveRelatedButtons()
{
int activeTaskCount = tm.GetActiveTaskCount();
BtnRun.IsEnabled = activeTaskCount > 0 && !wm.IsRunning;
BtnChap.IsEnabled = activeTaskCount > 0;
BtnMoveDown.IsEnabled = activeTaskCount > 0;
BtnMoveUp.IsEnabled = activeTaskCount > 0;
BtnMoveTop.IsEnabled = activeTaskCount > 0;
}

private void UpdatedCountRelatedButtons()
{
int taskCount = tm.GetTaskCount();
BtnDelete.IsEnabled = taskCount > 0;
BtnEmpty.IsEnabled = taskCount > 0;
}

private void Checkbox_Changed(object sender, RoutedEventArgs e)
{
if (!wm.IsRunning)
{
BtnRun.IsEnabled = tm.HasNextTask();
BtnChap.IsEnabled = BtnRun.IsEnabled;
}
UpdatedActiveRelatedButtons();
}

private void BtnRpc_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -117,14 +133,8 @@ private void BtnNew_Click(object sender, RoutedEventArgs e)
{
var wizard = new WizardWindow(wm);
wizard.ShowDialog();
int activeTaskCount = tm.GetActiveTaskCount();
BtnRun.IsEnabled = activeTaskCount > 0;
BtnDelete.IsEnabled = activeTaskCount > 0;
BtnEmpty.IsEnabled = activeTaskCount > 0;
BtnMoveDown.IsEnabled = activeTaskCount > 1;
BtnMoveUp.IsEnabled = activeTaskCount > 1;
BtnMoveTop.IsEnabled = activeTaskCount > 2;
BtnChap.IsEnabled = activeTaskCount > 0;
UpdatedActiveRelatedButtons();
UpdatedCountRelatedButtons();
}
catch (Exception ex)
{
Expand All @@ -141,13 +151,33 @@ private void BtnNew_Click(object sender, RoutedEventArgs e)
private void BtnPause_Click(object sender, RoutedEventArgs e)
{
BtnPause.IsEnabled = false;
SubProcessService.PauseAll();
try
{
SubProcessService.PauseAll();
}
catch (Exception ex)
{
Logger.Error(ex.StackTrace);
MessageBox.Show("无法暂停任务,请重试或者终止任务", "OKEGui", MessageBoxButton.OK, MessageBoxImage.Error);
BtnPause.IsEnabled = true;
return;
}
BtnResume.IsEnabled = true;
}
private void BtnResume_Click(object sender, RoutedEventArgs e)
{
BtnResume.IsEnabled = false;
SubProcessService.ResumeAll();
try
{
SubProcessService.ResumeAll();
}
catch (Exception ex)
{
Logger.Error(ex.StackTrace);
MessageBox.Show("无法恢复任务,请重试或者终止任务", "OKEGui", MessageBoxButton.OK, MessageBoxImage.Error);
BtnResume.IsEnabled = true;
return;
}
BtnPause.IsEnabled = true;
}

Expand All @@ -156,9 +186,8 @@ private void BtnRun_Click(object sender, RoutedEventArgs e)
try
{
wm.Start();
BtnDeleteWorker.IsEnabled = false;
BtnEmpty.IsEnabled = false;
BtnRun.IsEnabled = false;
BtnStop.IsEnabled = true;
BtnPause.IsEnabled = true;
}
catch (Exception ex)
Expand All @@ -168,10 +197,44 @@ private void BtnRun_Click(object sender, RoutedEventArgs e)
}
}

private void BtnStop_Click(object sender, RoutedEventArgs e)
{
BtnStop.IsEnabled = false;
BtnPause.IsEnabled = false;
BtnResume.IsEnabled = false;
List<TaskDetail> runningTasks = tm.GetRunningTasks();
if (runningTasks.Count == 0)
{
MessageBox.Show("没有正在运行的任务", "OKEGui", MessageBoxButton.OK, MessageBoxImage.Information);
BtnStop.IsEnabled = true;
return;
}
try
{
wm.Stop();
SubProcessService.KillAll();
}
catch (Exception ex)
{
Logger.Error(ex.StackTrace);
MessageBox.Show("无法终止任务!", "OKEGui", MessageBoxButton.OK, MessageBoxImage.Error);
BtnStop.IsEnabled = true;
return;
}

foreach (var task in runningTasks)
{
task.Progress = TaskStatus.TaskProgress.ERROR;
task.CurrentStatus = "已终止";
}
BtnRun.IsEnabled = tm.HasNextTask();
}

private void BtnChap_Click(object sender, RoutedEventArgs e)
{
BtnChap.IsEnabled = false;
tm.UpdateChapterStatus();
MessageBox.Show("更新章节完成", "OKEGui", MessageBoxButton.OK, MessageBoxImage.Information);
BtnChap.IsEnabled = true;
}

Expand Down Expand Up @@ -243,36 +306,43 @@ private void BtnDelete_Click(object sender, RoutedEventArgs e)

if (!tm.DeleteTask(item))
{
MessageBox.Show("无法删除任务!", "OKEGui", MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show("无法删除正在运行的任务!", "OKEGui", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

int activeTaskCount = tm.GetActiveTaskCount();
BtnRun.IsEnabled = activeTaskCount > 0;
BtnDelete.IsEnabled = activeTaskCount > 0;
BtnEmpty.IsEnabled = activeTaskCount > 0;
BtnMoveDown.IsEnabled = activeTaskCount > 1;
BtnMoveUp.IsEnabled = activeTaskCount > 1;
BtnMoveTop.IsEnabled = activeTaskCount > 2;
BtnChap.IsEnabled = activeTaskCount > 0;
UpdatedActiveRelatedButtons();
UpdatedCountRelatedButtons();
}

private void BtnEmpty_Click(object sender, RoutedEventArgs e)
{
tm.taskStatus.Clear();
BtnRun.IsEnabled = false;
BtnDelete.IsEnabled = false;
BtnEmpty.IsEnabled = false;
BtnMoveDown.IsEnabled = false;
BtnMoveUp.IsEnabled = false;
BtnMoveTop.IsEnabled = false;
BtnChap.IsEnabled = false;
int enabledTaskCount = tm.GetEnabledTaskCount();
if (enabledTaskCount == 0)
{
MessageBox.Show("请勾选需要清除的任务", "OKEGui", MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
List<TaskDetail> notRunningTasks = tm.GetNotRunningTasks();
foreach (var task in notRunningTasks)
{
if (!tm.DeleteTask(task))
{
MessageBox.Show("无法删除正在运行的任务!", "OKEGui", MessageBoxButton.OK, MessageBoxImage.Error);
break;
}
}

UpdatedActiveRelatedButtons();
UpdatedCountRelatedButtons();
}

private void BtnNewWorker_Click(object sender, RoutedEventArgs e)
{
WorkerCount++;
wm.AddWorker("工作单元-" + WorkerCount.ToString());
WorkerNumber.Text = "工作单元:" + WorkerCount.ToString();
if (wm.AddWorker("工作单元-" + (WorkerCount + 1).ToString()))
{
WorkerCount++;
WorkerNumber.Text = "工作单元数量: " + WorkerCount.ToString();
}
}

private void BtnDeleteWorker_Click(object sender, RoutedEventArgs e)
Expand All @@ -285,11 +355,11 @@ private void BtnDeleteWorker_Click(object sender, RoutedEventArgs e)
if (wm.DeleteWorker("工作单元-" + WorkerCount.ToString()))
{
WorkerCount--;
WorkerNumber.Text = "工作单元:" + WorkerCount.ToString();
WorkerNumber.Text = "工作单元数量: " + WorkerCount.ToString();
}
else
{
MessageBox.Show("工作单元删除失败!", "全部被占用中", MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show("工作单元删除失败!", $"工作单元-{WorkerCount}正在运行中", MessageBoxButton.OK, MessageBoxImage.Error);
}
}

Expand Down
51 changes: 39 additions & 12 deletions OKEGui/OKEGui/Gui/WizardWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,19 +239,24 @@ private void WizardFinish(object sender, RoutedEventArgs e)
// 清理文件
cleaner.Clean(inputFile, new List<string> { json.InputScript, inputFile + ".lwi" });

EpisodeConfig config = null;
string cfgPath = inputFile + ".json";
FileInfo cfgFile = new FileInfo(cfgPath);
if (cfgFile.Exists)
EpisodeConfig epConfig = null;
string cfgPath = null;
string[] cfgSuffixList = {".json", ".yaml", ".yml"};

foreach (string suffix in cfgSuffixList)
{
try
FileInfo cfgFile = new FileInfo(inputFile + suffix);
if (cfgFile.Exists)
{
string configStr = File.ReadAllText(cfgPath);
config = JsonConvert.DeserializeObject<EpisodeConfig>(configStr);
cfgPath = inputFile + suffix;
break;
}
catch (Exception ex)
}
if (cfgPath != null)
{
epConfig = AddEpProfileService.LoadJsonAsProfile(cfgPath);
if (epConfig == null)
{
System.Windows.MessageBox.Show(ex.ToString(), cfgFile.Name + "文件写错了诶", MessageBoxButton.OK, MessageBoxImage.Error);
continue;
}
}
Expand Down Expand Up @@ -289,14 +294,36 @@ private void WizardFinish(object sender, RoutedEventArgs e)

// 更新输入脚本和输出文件拓展名
td.Taskfile.InputScript = fileName;
if (config != null)
td.UpdateOutputFileName();

if (epConfig != null)
{
td.Taskfile.Config = epConfig.Clone() as EpisodeConfig;
td.Taskfile.IsReEncode = epConfig.EnableReEncode;
if (td.Taskfile.IsReEncode)
{
Logger.Debug("Processed epConfig: " + td.Taskfile.Config.ToString());
if (td.Taskfile.ContainerFormat != "MKV")
{
System.Windows.MessageBox.Show($"ReEncode项目暂时只支持mkv格式输出,{td.Taskfile.ContainerFormat}格式暂不支持", "封装格式不支持", MessageBoxButton.OK, MessageBoxImage.Error);
continue;
}
}
}
else
{
td.Taskfile.Config = config.Clone() as EpisodeConfig;
td.Taskfile.IsReEncode = false;
}
td.UpdateOutputFileName();

// 寻找章节
td.ChapterStatus = ChapterService.UpdateChapterStatus(td);

// 任务类型
if (td.Taskfile.IsReEncode)
td.TaskType = TaskStatus.TaskTypeEnum.ReEncode;
else
td.TaskType = TaskStatus.TaskTypeEnum.Normal;

workerManager.AddTask(td);
}
}
Expand Down
Loading