Skip to content

Commit

Permalink
Merge branch 'batch_mode' of https://github.com/NyagekiFumenProject/O…
Browse files Browse the repository at this point in the history
  • Loading branch information
MikiraSora committed Oct 26, 2024
2 parents a7e95cd + eb0958c commit 92a8866
Show file tree
Hide file tree
Showing 176 changed files with 7,538 additions and 3,223 deletions.
2 changes: 1 addition & 1 deletion Dependences/GLWpfControl/GLWpfControl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="OpenTK" Version="4.8.2" />
<PackageReference Include="OpenTK" Version="4.3.0" />
<PackageReference Include="Vortice.Direct2D1" Version="3.6.2" />
<PackageReference Include="Vortice.Direct3D11" Version="3.6.2" />
<PackageReference Include="Vortice.Direct3D12" Version="3.6.2" />
Expand Down
2 changes: 1 addition & 1 deletion Dependences/gemini
15 changes: 15 additions & 0 deletions OngekiFumenEditor/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
<setting name="SoundVolume" serializeAs="String">
<value>1</value>
</setting>
<setting name="EnableSoundMultiPlay" serializeAs="String">
<value>True</value>
</setting>
</OngekiFumenEditor.Properties.AudioSetting>
<OngekiFumenEditor.Properties.OptionGeneratorToolsSetting>
<setting name="LastLoadedGameFolder" serializeAs="String">
Expand Down Expand Up @@ -88,6 +91,18 @@
<setting name="IsFirstTimeOpenEditor" serializeAs="String">
<value>True</value>
</setting>
<setting name="WindowSizePositionLastTime" serializeAs="String">
<value />
</setting>
<setting name="UpdaterCheckMasterBranchOnly" serializeAs="String">
<value>True</value>
</setting>
<setting name="EnableUpdateCheck" serializeAs="String">
<value>True</value>
</setting>
<setting name="ShowConsoleWindowInGUIMode" serializeAs="String">
<value>False</value>
</setting>
</OngekiFumenEditor.Properties.ProgramSetting>
<OngekiFumenEditor.Properties.LogSetting>
<setting name="LogFileDirPath" serializeAs="String">
Expand Down
7 changes: 7 additions & 0 deletions OngekiFumenEditor/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@
</valueconverters:EnumToStringConverter>
<converters1:CultureInfoNameConverter x:Key="CultureInfoNameConverter">
</converters1:CultureInfoNameConverter>
<valueconverters:NullToVisibilityConverter x:Key="NullToVisibilityConverter">
</valueconverters:NullToVisibilityConverter>
<valueconverters:LocalizeConverter x:Key="LocalizeConverter">
</valueconverters:LocalizeConverter>
<valueconverters:AsyncImageLoadConverter x:Key="AsyncImageLoadConverter">
</valueconverters:AsyncImageLoadConverter>
<valueconverters:NullToZeroConverter x:Key="NullToZeroConverter" />
<valueconverters:DisplayFileSizeConverter x:Key="DisplayFileSizeConverter">
</valueconverters:DisplayFileSizeConverter>
<valueconverters:SelectionMovableItemsCheckConverter x:Key="SelectionMovableItemsCheckConverter" />
<valueconverters:SelectionFullLaneCheckConverter x:Key="SelectionFullLaneCheckConverter" />
<ResourceDictionary.MergedDictionaries>
Expand Down
5 changes: 4 additions & 1 deletion OngekiFumenEditor/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ namespace OngekiFumenEditor
/// </summary>
public partial class App : Application
{
public App()
public bool IsGUIMode { get; }

public App(bool isGUIMode = true)
{
AppDomain.CurrentDomain.AssemblyResolve += OnSatelliteAssemblyResolve;
// 设置工作目录为执行文件所在的目录
Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
IsGUIMode = isGUIMode;
}

private Assembly OnSatelliteAssemblyResolve(object sender, ResolveEventArgs args)
Expand Down
121 changes: 99 additions & 22 deletions OngekiFumenEditor/AppBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Security.Principal;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
Expand All @@ -19,7 +20,9 @@
using Gemini.Modules.Output;
using OngekiFumenEditor.Kernel.ArgProcesser;
using OngekiFumenEditor.Kernel.Audio;
using OngekiFumenEditor.Kernel.CommandExecutor;
using OngekiFumenEditor.Kernel.EditorLayout;
using OngekiFumenEditor.Kernel.ProgramUpdater;
using OngekiFumenEditor.Kernel.Scheduler;
using OngekiFumenEditor.Modules.AudioPlayerToolViewer;
using OngekiFumenEditor.Modules.FumenVisualEditor.Base;
Expand All @@ -29,6 +32,7 @@
using OngekiFumenEditor.Utils;
using OngekiFumenEditor.Utils.DeadHandler;
using OngekiFumenEditor.Utils.Logs.DefaultImpls;
using SevenZip.Compression.LZ;
#if !DEBUG
using System.Runtime.InteropServices;
using System.Threading;
Expand All @@ -52,6 +56,13 @@ public AppBootstrapper(bool useApplication = true) : base(useApplication)
{
}

private bool? isGUIMode = null;
public bool IsGUIMode
{
get => isGUIMode ?? ((App.Current as App)?.IsGUIMode ?? false);
set => isGUIMode = value;
}

protected override void BindServices(CompositionBatch batch)
{
base.BindServices(batch);
Expand Down Expand Up @@ -158,17 +169,63 @@ private bool CheckIfAdminPermission()
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}

protected override async void OnStartup(object sender, StartupEventArgs e)
protected override void OnStartup(object sender, StartupEventArgs e)
{
var isGUIMode = (App.Current as App)?.IsGUIMode ?? false;

if (isGUIMode)
{
OnStartupForGUI(sender, e);
}
else
{
OnStartupForCMD(sender, e);
}
}

public async void OnStartupForCMD(object sender, StartupEventArgs e)
{
IsGUIMode = false;
Log.Instance.RemoveOutput<ConsoleLogOutput>();

await IoC.Get<ISchedulerManager>().Init();

var executor = IoC.Get<ICommandExecutor>();

try
{
Application.Current.Shutdown(await executor.Execute(e.Args));
}
catch (Exception ex)
{
Log.LogError($"Unhandled exception processing arguments:\n{ex.Message}");
Application.Current.Shutdown(1);
}
}

public async void OnStartupForGUI(object sender, StartupEventArgs e)
{
IsGUIMode = true;

#if DEBUG
ConsoleWindowHelper.SetConsoleWindowVisible(true);
#else
ConsoleWindowHelper.SetConsoleWindowVisible(ProgramSetting.Default.ShowConsoleWindowInGUIMode);
#endif

InitExceptionCatcher();
LogBaseInfos();
InitIPCServer();

await IoC.Get<ISchedulerManager>().Init();

try {
try
{
//process command args
await IoC.Get<IProgramArgProcessManager>().ProcessArgs(e.Args);
} catch (Exception ex) {
}
catch (Exception ex)
{
await Console.Error.WriteLineAsync($"Unhandled exception processing arguments:\n{ex.Message}");
Application.Current.Shutdown(-1);
return;
Expand All @@ -186,11 +243,6 @@ protected override async void OnStartup(object sender, StartupEventArgs e)
curProc.PriorityBoostEnabled = true;
}

ShowStartupGUI();
}

private void OnStartupForGUI()
{
//overwrite ViewLocator
var locateForModel = ViewLocator.LocateForModel;
ViewLocator.LocateForModel = (model, hostControl, ctx) =>
Expand All @@ -205,12 +257,10 @@ private void OnStartupForGUI()
if (CheckIfAdminPermission())
{
Log.LogWarn("Program is within admin permission.");
IoC.Get<WindowTitleHelper>().TitleContent = "(以管理员权限运行)";
}
else
{
IoC.Get<WindowTitleHelper>().TitleContent = "";
var prevSuffix = IoC.Get<WindowTitleHelper>().TitleSuffix;
IoC.Get<WindowTitleHelper>().TitleSuffix = prevSuffix + "(以管理员权限运行)";
}
IoC.Get<WindowTitleHelper>().UpdateWindowTitle();

IoC.Get<IShell>().ToolBars.Visible = true;

Expand All @@ -222,18 +272,26 @@ private void OnStartupForGUI()

Log.LogInfo(IoC.Get<CommonStatusBar>().MainContentViewModel.Message = "Application is Ready.");

await DisplayRootViewForAsync<IMainWindow>();

if (Application.MainWindow is Window window)
{
window.AllowDrop = true;
window.Drop += MainWindow_Drop;
}
}

public async void ShowStartupGUI()
{
OnStartupForGUI();
//program will forget position/size when it has been called as commandline.
//so we have to remember and restore windows' position/size manually.
window.Closed += MainWindow_Closed;
if (!string.IsNullOrWhiteSpace(ProgramSetting.Default.WindowSizePositionLastTime))
{
var arr = ProgramSetting.Default.WindowSizePositionLastTime.Split(",").Select(x => double.Parse(x.Trim())).ToArray();
window.Left = arr[0];
window.Top = arr[1];
window.Width = arr[2];
window.Height = arr[3];
}
}

await DisplayRootViewForAsync<IMainWindow>();
var showSplashWindow = IoC.Get<IShell>().Documents.IsEmpty() &&
!ProgramSetting.Default.DisableShowSplashScreenAfterBoot;
if (showSplashWindow)
Expand All @@ -251,6 +309,25 @@ public async void ShowStartupGUI()
ProgramSetting.Default.IsFirstTimeOpenEditor = false;
ProgramSetting.Default.Save();
}

IoC.Get<IProgramUpdater>().CheckUpdatable().NoWait();
}

private void MainWindow_Closed(object sender, EventArgs e)
{
if (sender is not Window mainWindow)
return;

ProgramSetting.Default.WindowSizePositionLastTime = string.Join(", ", new[] {
mainWindow.Left,
mainWindow.Top,
mainWindow.Width,
mainWindow.Height
});
ProgramSetting.Default.Save();
Log.LogInfo($"WindowSizePositionLastTime = {ProgramSetting.Default.WindowSizePositionLastTime}");

App.Current.Shutdown();
}

private void InitIPCServer()
Expand All @@ -275,15 +352,15 @@ private void InitIPCServer()

try
{
var line = (await IPCHelper.ReadLineAsync(cancelToken))?.Trim();
var line = IPCHelper.ReadLine(cancelToken)?.Trim();
if (string.IsNullOrWhiteSpace(line))
continue;
Log.LogDebug($"Recv line by IPC:{line}");
if (line.StartsWith("CMD:"))
{
var args = JsonSerializer.Deserialize<IPCHelper.ArgsWrapper>(line[4..]).Args;
await Application.Current.Dispatcher.InvokeAsync(() =>
IoC.Get<IProgramArgProcessManager>().ProcessArgs(args));
Application.Current.Dispatcher.Invoke(() =>
IoC.Get<IProgramArgProcessManager>().ProcessArgs(args)).NoWait();
}
}
catch (Exception e)
Expand Down
2 changes: 1 addition & 1 deletion OngekiFumenEditor/Base/EditorObjects/Svg/SvgPrefabBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public bool IsForceColorful
set => Set(ref isForceColorful, value);
}

private ColorId colorfulLaneColor = ColorIdConst.LaneGreen;
private ColorId colorfulLaneColor = ColorIdConst.Yuzu;
public ColorId ColorfulLaneColor
{
get => colorfulLaneColor;
Expand Down
25 changes: 0 additions & 25 deletions OngekiFumenEditor/Base/OngekiObjects/ColorIdConst.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,28 +145,6 @@ public static class ColorIdConst
Color = Color.FromArgb(255, 71, 145, 255)
};

public static ColorId LaneRed { get; } = new ColorId()
{
Id = 1020,
Name = nameof(LaneRed),
Color = Color.FromArgb(255, 255, 0, 0)
};

public static ColorId LaneGreen { get; } = new ColorId()
{
Id = 1021,
Name = nameof(LaneGreen),
Color = Color.FromArgb(255, 0, 255, 0)
};

public static ColorId LaneBlue { get; } = new ColorId()
{
Id = 1022,
Name = nameof(LaneBlue),
Color = Color.FromArgb(255, 0, 0, 255)
};


public static IEnumerable<ColorId> AllColors { get; } = new[]
{
Akari,
Expand All @@ -188,9 +166,6 @@ public static class ColorIdConst
Black,
Akane,
Aoi,
LaneRed,
LaneGreen,LaneG,
LaneBlue,
};
}
}
Loading

0 comments on commit 92a8866

Please sign in to comment.