Skip to content

Commit

Permalink
Moved some stuff around, added PSRunspace backport.
Browse files Browse the repository at this point in the history
Closes #7
  • Loading branch information
krisdb2009 committed Oct 18, 2020
1 parent 7679cf2 commit e142852
Show file tree
Hide file tree
Showing 15 changed files with 379 additions and 342 deletions.
File renamed without changes.
4 changes: 3 additions & 1 deletion SuperLTI/Copy.cs → SuperLTI/Classes/Copy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ public static void CopyTo(FileInfo file, FileInfo destination, Action<int> progr
const int bufferSize = 1024 * 1024;
byte[] buffer = new byte[bufferSize], buffer2 = new byte[bufferSize];
bool swap = false;
int progress = 0, reportedProgress = 0, read = 0;
int reportedProgress = 0;
long len = file.Length;
float flen = len;
Task writer = null;
using (var source = file.OpenRead())
using (var dest = destination.OpenWrite())
{
dest.SetLength(source.Length);
int read;
for (long size = 0; size < len; size += read)
{
int progress;
if ((progress = ((int)((size / flen) * 100))) != reportedProgress)
{
progressCallback(reportedProgress = progress);
Expand Down
20 changes: 20 additions & 0 deletions SuperLTI/Classes/Logger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Diagnostics;

namespace SuperLTI
{
public static class Logger
{
public static void WriteEventLog(string logText, EventLogEntryType messageType)
{
EventLog eventLog = new EventLog("Application")
{
Source = "SuperLTI"
};
if (!EventLog.SourceExists(eventLog.Source))
{
EventLog.CreateEventSource("SuperLTI", "Application");
}
eventLog.WriteEntry(logText, messageType);
}
}
}
55 changes: 55 additions & 0 deletions SuperLTI/Classes/PSRunspace.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Windows.Forms;

namespace SuperLTI
{
/// <summary>
/// The PowerShell runspace passed to the "install engine's" PowerShell instance.
/// This allows the PowerShell script to access these properties and methods from PowerShell.
/// </summary>
public class PSRunspace
{
/// <summary>
/// Get / set the title of the main window.
/// </summary>
public string WindowTitle
{
get
{
return Program.MainForm.ProgressDialog.Title;
}
set
{
Program.MainForm.BeginInvoke(new Action(() => {
Program.MainForm.ProgressDialog.Title = value;
}));
}
}
/// <summary>
/// Gets / sets the TopMost status of the main window. True means that the main window is always on top.
/// </summary>
public bool WindowTopMost
{
get
{
return Program.MainForm.TopMost;
}
set
{
Program.MainForm.Invoke(new Action(() => {
Program.MainForm.TopMost = value;
}));
}
}
/// <summary>
/// Gets the raw SuperLTI arguments that were passed to SuperLTI on launch.
/// </summary>
public string[] RawArguments
{
get
{
return Program.Arguments;
}
}
}
}
26 changes: 6 additions & 20 deletions SuperLTI/ProgressDialog.cs → SuperLTI/Classes/ProgressDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@ namespace SuperLTI
{
public class ProgressDialog
{
private IntPtr _parentHandle;

private Win32IProgressDialog pd = null;

private readonly IntPtr _parentHandle;
private IWin32IProgressDialog pd = null;
public ProgressDialog(IntPtr parentHandle)
{
_parentHandle = parentHandle;
}

public void ShowDialog(params PROGDLG[] flags)
{
if (pd == null)
{
pd = (Win32IProgressDialog)new Win32ProgressDialog();
pd = (IWin32IProgressDialog)new Win32ProgressDialog();
pd.SetTitle(_Title);
pd.SetCancelMsg(_CancelMessage, null);
pd.SetLine(1, _Line1, false, IntPtr.Zero);
Expand All @@ -31,14 +28,13 @@ public void ShowDialog(params PROGDLG[] flags)
dialogFlags = flags[0];
for (var i = 1; i < flags.Length; i++)
{
dialogFlags = dialogFlags | flags[i];
dialogFlags |= flags[i];
}
}
pd.Timer(PDTIMER.Reset, null);
pd.StartProgressDialog(_parentHandle, null, dialogFlags, IntPtr.Zero);
}
}

public void CloseDialog()
{
if (pd != null)
Expand All @@ -48,7 +44,6 @@ public void CloseDialog()
pd = null;
}
}

private string _Title = string.Empty;
public string Title
{
Expand All @@ -65,7 +60,6 @@ public string Title
}
}
}

private string _CancelMessage = string.Empty;
public string CancelMessage
{
Expand All @@ -82,7 +76,6 @@ public string CancelMessage
}
}
}

private string _Line1 = string.Empty;
public string Line1
{
Expand All @@ -99,7 +92,6 @@ public string Line1
}
}
}

private string _Line2 = string.Empty;
public string Line2
{
Expand All @@ -116,7 +108,6 @@ public string Line2
}
}
}

private string _Line3 = string.Empty;
public string Line3
{
Expand All @@ -133,7 +124,6 @@ public string Line3
}
}
}

private uint _value = 0;
public uint Value
{
Expand All @@ -150,7 +140,6 @@ public uint Value
}
}
}

private uint _maximum = 100;
public uint Maximum
{
Expand Down Expand Up @@ -186,19 +175,17 @@ public void ResetTimer()
}
#region "Win32 Stuff"
// The below was copied from: http://pinvoke.net/default.aspx/Interfaces/IProgressDialog.html

public static class shlwapi
public static class Shlwapi
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1060:MovePInvokesToNativeMethodsClass")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA2101:SpecifyMarshalingForPInvokeStringArguments", MessageId = "1")]
[DllImport("shlwapi.dll", CharSet = CharSet.Auto)]
static extern bool PathCompactPath(IntPtr hDC, [In, Out] StringBuilder pszPath, int dx);
}

[ComImport]
[Guid("EBBC7C04-315E-11d2-B62F-006097DF5BD4")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface Win32IProgressDialog
public interface IWin32IProgressDialog
{
/// <summary>
/// Starts the progress dialog box.
Expand Down Expand Up @@ -339,7 +326,6 @@ public enum PDTIMER : uint //DWORD
/// <summary>Progress has been resumed.</summary>
Resume = (0x03)
}

[Flags]
public enum PROGDLG : uint //DWORD
{
Expand Down
File renamed without changes.
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e142852

Please sign in to comment.