-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from Diaskhan/dev/Lister_plugins
Dev/lister plugins (Core functionalyti)
- Loading branch information
Showing
9 changed files
with
242 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace SmartCommander.Plugins; | ||
|
||
public class ListerPluginWrapper : IDisposable | ||
{ | ||
private IntPtr _pluginHandle; | ||
|
||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | ||
private delegate IntPtr ListLoadDelegate(IntPtr parentWin, string fileToLoad, int showFlags); | ||
|
||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | ||
private delegate void ListCloseWindowDelegate(IntPtr listWin); | ||
|
||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | ||
private delegate void ListSendCommandDelegate(IntPtr listWin, int command, int parameter); | ||
|
||
[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Ansi)] | ||
public delegate void ListGetDetectStringDelegate(IntPtr detectString, int maxlen); | ||
|
||
private ListLoadDelegate ListLoad; | ||
private ListCloseWindowDelegate ListCloseWindow; | ||
private ListSendCommandDelegate ListSendCommand; | ||
private ListGetDetectStringDelegate ListGetDetectString; | ||
|
||
public ListerPluginWrapper(string pluginPath) | ||
{ | ||
_pluginHandle = NativeLibrary.Load(pluginPath); | ||
|
||
ListLoad = Marshal.GetDelegateForFunctionPointer<ListLoadDelegate>(NativeLibrary.GetExport(_pluginHandle, nameof(ListLoad))); | ||
ListCloseWindow = Marshal.GetDelegateForFunctionPointer<ListCloseWindowDelegate>(NativeLibrary.GetExport(_pluginHandle, nameof(ListCloseWindow))); | ||
ListSendCommand = Marshal.GetDelegateForFunctionPointer<ListSendCommandDelegate>(NativeLibrary.GetExport(_pluginHandle, nameof(ListSendCommand))); | ||
ListGetDetectString = Marshal.GetDelegateForFunctionPointer<ListGetDetectStringDelegate>(NativeLibrary.GetExport(_pluginHandle, nameof(ListGetDetectString))); | ||
} | ||
|
||
public IntPtr LoadFile(IntPtr parentWindowHandle, string filePath, int showFlags) | ||
{ | ||
return ListLoad!(parentWindowHandle, filePath, showFlags); | ||
} | ||
|
||
public void CloseWindow(IntPtr listerWindowHandle) | ||
{ | ||
ListCloseWindow!(listerWindowHandle); | ||
} | ||
|
||
public void SendCommand(IntPtr listerWindowHandle, int command, int parameter) | ||
{ | ||
ListSendCommand!(listerWindowHandle, command, parameter); | ||
} | ||
|
||
public string? DetectString(int maxlen = 2000) | ||
{ | ||
IntPtr detectStringPtr = Marshal.AllocHGlobal(maxlen); | ||
ListGetDetectString(detectStringPtr, maxlen); | ||
string? detectString = Marshal.PtrToStringAnsi(detectStringPtr); | ||
Marshal.FreeHGlobal(detectStringPtr); | ||
return detectString; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
if (_pluginHandle != IntPtr.Zero) | ||
{ | ||
NativeLibrary.Free(_pluginHandle); | ||
_pluginHandle = IntPtr.Zero; | ||
} | ||
} | ||
} | ||
|
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,21 @@ | ||
using System; | ||
|
||
namespace SmartCommander.Plugins; | ||
|
||
public static class PluginManager | ||
{ | ||
public static ListerPluginWrapper CreateListerWrapper() | ||
{ | ||
//string pluginPath = "C:\\totalcmd\\plugins\\CodeViewer\\CodeViewer.wlx64"; | ||
string pluginPath = "C:\\totalcmd\\plugins\\wlx\\CodeViewer\\CodeViewer.wlx64"; | ||
return new ListerPluginWrapper(pluginPath); | ||
} | ||
|
||
public static IntPtr CreateListerWindow(this ListerPluginWrapper listerWrapper, IntPtr parentWindowHandle, string fileToLoad) | ||
{ | ||
int showFlags = 1; | ||
return listerWrapper.LoadFile(parentWindowHandle, fileToLoad, showFlags); | ||
} | ||
|
||
} | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
using System.IO; | ||
using Avalonia.Controls; | ||
using System; | ||
using System.IO; | ||
|
||
namespace SmartCommander.ViewModels | ||
{ | ||
public class ViewerViewModel : ViewModelBase | ||
{ | ||
|
||
public ViewerViewModel(string filename) | ||
{ | ||
try | ||
{ | ||
Text = File.ReadAllText(filename); | ||
} | ||
catch { Text = ""; } | ||
Filename= filename; | ||
} | ||
|
||
public string Text { get; set; } | ||
public string Filename { get; set; } | ||
} | ||
} |
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
Oops, something went wrong.