Skip to content

Commit

Permalink
Refactor using IEditorFile
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchLeaders committed Jan 14, 2024
1 parent 75aca9a commit fd29ce6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/Models/TotkActionsMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ private static async Task CallActionMethod(string methodName, Func<Task<bool>>?
IEditor? current = Frontend.Locate<IEditorManager>().Current;
if (current?.GetType() is Type type && type.Name == "RestblEditorViewModel") {
if (condition == null || condition.Invoke() is Task<bool> task && await task == true) {
type.GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance)?.Invoke(current, new object[] {
new FileHandle(_vanillaRestblPath)
});
type.GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance)?.Invoke(current, [
EditorFile.FromFile(_vanillaRestblPath)
]);
}

return;
Expand Down
38 changes: 24 additions & 14 deletions src/TotkZstd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,37 @@ public static void ChangeCompressionLevel(int level)
_packCompressor = new(level);
}

public IFileHandle Process(IFileHandle handle)
public void Process(IEditorFile handle)
{
handle.Data = (handle.Name.EndsWith(".bcett.byml.zs")
? _bcettDecompressor.Unwrap(handle.Data) : handle.Name.EndsWith(".pack.zs")
? _packDecompressor.Unwrap(handle.Data) : handle.Name.EndsWith(".rsizetable.zs")
? _defaultDecompressor.Unwrap(handle.Data) : _commonDecompressor.Unwrap(handle.Data)).ToArray();

return handle;
handle.Source = (
handle.Name.EndsWith(".bcett.byml.zs")
? _bcettDecompressor.Unwrap(handle.Source) : handle.Name.EndsWith(".pack.zs")
? _packDecompressor.Unwrap(handle.Source) : _commonDecompressor.Unwrap(handle.Source)
).ToArray();
}

public IFileHandle Reprocess(IFileHandle handle)
public void Reprocess(IEditorFile handle)
{
handle.Data = (handle.Name.EndsWith(".bcett.byml.zs")
? _bcettCompressor.Wrap(handle.Data) : handle.Name.EndsWith(".pack.zs")
? _packCompressor.Wrap(handle.Data) : handle.Name.EndsWith(".rsizetable.zs")
? _defaultCompressor.Wrap(handle.Data) : _commonCompressor.Wrap(handle.Data)).ToArray();
WriteEditorFile baseWrite = handle.Write;
handle.Write = (data) => {
if (handle.Name.EndsWith(".bcett.byml.zs")) {
data = _bcettCompressor.Wrap(data);
}
else if (handle.Name.EndsWith(".pack.zs")) {
data = _packCompressor.Wrap(data);
}
else if (handle.Name.EndsWith(".rsizetable.zs")) {
data = _defaultCompressor.Wrap(data);
}
else {
data = _commonCompressor.Wrap(data);
}
return handle;
baseWrite(data);
};
}

public bool IsValid(IFileHandle handle)
public bool IsValid(IEditorFile handle)
{
return handle.Name.EndsWith(".zs");
}
Expand Down

0 comments on commit fd29ce6

Please sign in to comment.