-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64d6afa
commit f4fadf5
Showing
14 changed files
with
207 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
OngekiFumenEditor/Kernel/EditorLayout/EditorLayoutManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using Caliburn.Micro; | ||
using Gemini.Framework.Services; | ||
using Gemini.Modules.Shell.Services; | ||
using Gemini.Modules.Shell.ViewModels; | ||
using Gemini.Modules.Shell.Views; | ||
using OngekiFumenEditor.Utils; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.Composition; | ||
using System.IO; | ||
using System.IO.Pipelines; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace OngekiFumenEditor.Kernel.EditorLayout | ||
{ | ||
[Export(typeof(IEditorLayoutManager))] | ||
public class EditorLayoutManager : IEditorLayoutManager | ||
{ | ||
[Import] | ||
private ILayoutItemStatePersister layoutItemStatePersister; | ||
|
||
public bool TryGetDependices(out IShell shell, out IShellView shellView) | ||
{ | ||
shell = IoC.Get<IShell>(); | ||
shellView = default; | ||
|
||
if (shell is ShellViewModel) | ||
{ | ||
if (shell.GetType().GetField("_shellView", BindingFlags.NonPublic | BindingFlags.Instance) | ||
is FieldInfo fieldInfo) | ||
shellView = fieldInfo.GetValue(shell) as IShellView; | ||
else | ||
Log.LogError($"shell object is ShellViewModel but can not locate IShellView object"); | ||
} | ||
|
||
return shell != null && shellView != null; | ||
} | ||
|
||
public async Task<bool> LoadLayout(Stream intputLayoutDataStream) | ||
{ | ||
var tempFilePath = TempFileHelper.GetTempFilePath("layout", "layout"); | ||
{ | ||
using var fs = File.OpenWrite(tempFilePath); | ||
await intputLayoutDataStream.CopyToAsync(fs); | ||
} | ||
|
||
try | ||
{ | ||
if (!TryGetDependices(out var shell, out var shellView)) | ||
return false; | ||
|
||
return layoutItemStatePersister.LoadState(shell, shellView, tempFilePath); | ||
} | ||
catch (Exception e) | ||
{ | ||
Log.LogError($"Can't load and apply program layout:{e.Message}", e); | ||
return false; | ||
} | ||
} | ||
|
||
public async Task<bool> SaveLayout(Stream outputLayoutDataStream) | ||
{ | ||
var tempFilePath = TempFileHelper.GetTempFilePath("layout", "layout"); | ||
|
||
try | ||
{ | ||
if (!TryGetDependices(out var shell, out var shellView)) | ||
return false; | ||
|
||
var r = layoutItemStatePersister.SaveState(shell, shellView, tempFilePath); | ||
if (!r) | ||
return false; | ||
using var fs = File.OpenRead(tempFilePath); | ||
await fs.CopyToAsync(outputLayoutDataStream); | ||
return true; | ||
} | ||
catch (Exception e) | ||
{ | ||
Log.LogError($"Can't save current program layout:{e.Message}", e); | ||
return false; | ||
} | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
OngekiFumenEditor/Kernel/EditorLayout/IEditorLayoutManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace OngekiFumenEditor.Kernel.EditorLayout | ||
{ | ||
public interface IEditorLayoutManager | ||
{ | ||
Task<bool> SaveLayout(Stream outputLayoutDataStream); | ||
Task<bool> LoadLayout(Stream intputLayoutDataStream); | ||
|
||
//Task CheckAndNotifyUserUseSuggestLayout(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters