Skip to content

Commit

Permalink
Disable trimming on Windows + bring back the COM stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
maddie480 committed Feb 10, 2025
1 parent e97ff0f commit 69a6f67
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 2 deletions.
3 changes: 1 addition & 2 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ and only contains the latest changes.
Its purpose is to be shown in Olympus when updating.

#changelog#
∙ Reintegrated the Windows uninstaller in Olympus.Sharp instead of having a separate uninstall.exe
∙ Fixed log.txt file not getting written on Windows if the username contains non-Latin characters
∙ Disabled trimming on Windows to attempt appeasing antiviruses and bring back minor features (desktop shortcut, progress in taskbar)
56 changes: 56 additions & 0 deletions sharp/CmdWin32CreateShortcuts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#if WIN32
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Text;

namespace Olympus {
public class CmdWin32CreateShortcuts : Cmd<string, string> {

public override string Run(string exepath) {
CreateShortcut(exepath, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "Olympus.lnk"));
CreateShortcut(exepath, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Olympus.lnk"));
return null;
}

public static void CreateShortcut(string exepath, string lnkpath) {
IShellLink link = (IShellLink) new ShellLink();
link.SetDescription("Launch Olympus");
link.SetPath(exepath);
link.SetWorkingDirectory(Directory.GetParent(exepath).FullName);
((IPersistFile) link).Save(lnkpath, false);
}

[ComImport]
[Guid("00021401-0000-0000-C000-000000000046")]
internal class ShellLink {
}

[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("000214F9-0000-0000-C000-000000000046")]
internal interface IShellLink {
void GetPath([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile, int cchMaxPath, out IntPtr pfd, int fFlags);
void GetIDList(out IntPtr ppidl);
void SetIDList(IntPtr pidl);
void GetDescription([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszName, int cchMaxName);
void SetDescription([MarshalAs(UnmanagedType.LPWStr)] string pszName);
void GetWorkingDirectory([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszDir, int cchMaxPath);
void SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] string pszDir);
void GetArguments([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszArgs, int cchMaxPath);
void SetArguments([MarshalAs(UnmanagedType.LPWStr)] string pszArgs);
void GetHotkey(out short pwHotkey);
void SetHotkey(short wHotkey);
void GetShowCmd(out int piShowCmd);
void SetShowCmd(int iShowCmd);
void GetIconLocation([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszIconPath, int cchIconPath, out int piIcon);
void SetIconLocation([MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIcon);
void SetRelativePath([MarshalAs(UnmanagedType.LPWStr)] string pszPathRel, int dwReserved);
void Resolve(IntPtr hwnd, int fFlags);
void SetPath([MarshalAs(UnmanagedType.LPWStr)] string pszFile);
}

}
}
#endif
168 changes: 168 additions & 0 deletions sharp/CmdWin32SetProgress.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
#if WIN32
using System;
using System.Drawing;
using System.Globalization;
using System.Runtime.InteropServices;

namespace Olympus {
public class CmdWin32SetProgress : Cmd<string, string, float, object> {

public override bool LogRun => false;

public override object Run(string ptrStr, string state, float progress) {
if (!IsSupported)
return null;

if (Instance == null)
Instance = (ITaskbarList3) new TaskbarInstance();

IntPtr ptr = (IntPtr) long.Parse(ptrStr, NumberStyles.HexNumber, CultureInfo.InvariantCulture);

ulong prog = (ulong) Math.Round(progress * 10000);
ulong max = 10000;

if (prog < 0) {
prog = 0;
max = 1;
} else if (prog >= max) {
prog = 1;
max = 1;
}

switch (state) {
case "":
case "none":
Instance.SetProgressState(ptr, TBPF.TBPF_NOPROGRESS);
prog = 0;
max = 1;
break;

case "indeterminate":
Instance.SetProgressValue(ptr, 0, 1);
Instance.SetProgressState(ptr, TBPF.TBPF_INDETERMINATE);
return null;

case "normal":
Instance.SetProgressState(ptr, TBPF.TBPF_NORMAL);
break;

case "error":
Instance.SetProgressState(ptr, TBPF.TBPF_ERROR);
break;

case "paused":
Instance.SetProgressState(ptr, TBPF.TBPF_PAUSED);
break;
}

Instance.SetProgressValue(ptr, prog, max);

return null;
}

// Taken from the old Everest.Installer, which took it from http://stackoverflow.com/a/24187171

public enum TBPF {
TBPF_NOPROGRESS = 0,
TBPF_INDETERMINATE = 0x1,
TBPF_NORMAL = 0x2,
TBPF_ERROR = 0x4,
TBPF_PAUSED = 0x8
}

public enum TBATF {
TBATF_USEMDITHUMBNAIL = 0x1,
TBATF_USEMDILIVEPREVIEW = 0x2
}

public enum THB : uint {
THB_BITMAP = 0x1,
THB_ICON = 0x2,
THB_TOOLTIP = 0x4,
THB_FLAGS = 0x8
}

public enum THBF : uint {
THBF_ENABLED = 0,
THBF_DISABLED = 0x1,
THBF_DISMISSONCLICK = 0x2,
THBF_NOBACKGROUND = 0x4,
THBF_HIDDEN = 0x8
}

[StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Auto)]
public struct THUMBBUTTON {
public THB dwMask;
public uint iId;
public uint iBitmap;
public IntPtr hIcon;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] // MAX_PATH
public string szTip;
public THBF dwFlags;
}

[ComImport]
[Guid("ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface ITaskbarList3 {
// ITaskbarList
void HrInit();
void AddTab(IntPtr hwnd);
void DeleteTab(IntPtr hwnd);
void ActivateTab(IntPtr hwnd);
void SetActiveAlt(IntPtr hwnd);

// ITaskbarList2
void MarkFullscreenWindow(
IntPtr hwnd,
[MarshalAs(UnmanagedType.Bool)] bool fFullscreen);

// ITaskbarList3
void SetProgressValue(IntPtr hwnd, ulong ullCompleted, ulong ullTotal);
void SetProgressState(IntPtr hwnd, TBPF tbpFlags);
void RegisterTab(IntPtr hwndTab, IntPtr hwndMDI);
void UnregisterTab(IntPtr hwndTab);
void SetTabOrder(IntPtr hwndTab, IntPtr hwndInsertBefore);
void SetTabActive(IntPtr hwndTab, IntPtr hwndMDI, TBATF tbatFlags);

void ThumbBarAddButtons(
IntPtr hwnd,
uint cButtons,
[MarshalAs(UnmanagedType.LPArray)] THUMBBUTTON[] pButtons);

void ThumbBarUpdateButtons(
IntPtr hwnd,
uint cButtons,
[MarshalAs(UnmanagedType.LPArray)] THUMBBUTTON[] pButtons);

void ThumbBarSetImageList(IntPtr hwnd, IntPtr himl);

void SetOverlayIcon(
IntPtr hwnd,
IntPtr hIcon,
[MarshalAs(UnmanagedType.LPWStr)] string pszDescription);

void SetThumbnailTooltip(
IntPtr hwnd,
[MarshalAs(UnmanagedType.LPWStr)] string pszTip);

void SetThumbnailClip(
IntPtr hwnd,
[MarshalAs(UnmanagedType.LPStruct)] Rectangle prcClip);
}

[ComImport()]
[Guid("56fdf344-fd6d-11d0-958a-006097c9a090")]
[ClassInterface(ClassInterfaceType.None)]
private class TaskbarInstance {
}

private static ITaskbarList3 Instance;
private readonly static bool IsSupported =
Type.GetType("Mono.Runtime") == null &&
Environment.OSVersion.Platform == PlatformID.Win32NT &&
Environment.OSVersion.Version >= new Version(6, 1);

}
}
#endif
2 changes: 2 additions & 0 deletions sharp/Cmds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ public static void Init() {
#if WIN32
new CmdGetUWPPackagePath(),
new CmdWin32AppAdd(),
new CmdWin32CreateShortcuts(),
new CmdWin32RegGet(),
new CmdWin32RegSet(),
new CmdWin32SetProgress(),
#endif
};

Expand Down
1 change: 1 addition & 0 deletions sharp/Olympus.Sharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith('win'))">
<OutputType>WinExe</OutputType>
<DefineConstants>WIN32</DefineConstants>
<PublishTrimmed>false</PublishTrimmed>
</PropertyGroup>

<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith('osx'))">
Expand Down
7 changes: 7 additions & 0 deletions src/modinstaller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ function modinstaller.register()
print("updating installed application listing")
sharp.win32AppAdd(exepath, utils.trim(utils.load("version.txt") or "?"))

-- While we're here, might as well create some helpful .lnks
-- INTRODUCED AFTER BUILD 1531
if config.lastrun < 0 or config.lastrun <= 1531 then
print("creating shortcuts", exepath)
sharp.win32CreateShortcuts(exepath)
end

return true
end

Expand Down
9 changes: 9 additions & 0 deletions src/native.lua
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,15 @@ function native.prepareWindow()
end
end

function native.setProgress(state, progress)
local sdlWindow = native.getCurrentWindow()
local sdlWMinfo = ffi.new("SDL_SysWMinfo[1]")
sdl.SDL_GetWindowWMInfo(sdlWindow, sdlWMinfo)
if ffi.os == "Windows" then
sharp.win32SetProgress(tostring(sdlWMinfo[0].info.win.window):sub(#"cdata<void *>: 0x" + 1), state, progress)
end
end

function native.flashWindow()
local sdlWindow = native.getCurrentWindow()
local sdlWMinfo = ffi.new("SDL_SysWMinfo[1]")
Expand Down
2 changes: 2 additions & 0 deletions src/scenes/installer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ function scene.update(status, progress, shape, replace)
end

if progress ~= nil then
native.setProgress(shape == "error" and "error" or not progress and "indeterminate" or "normal", progress or 0)
scene.progressNext = progress
end

Expand Down Expand Up @@ -457,6 +458,7 @@ end

function scene.leave()
scener.unlock()
native.setProgress("none", 0)
if scene.onLeave then
scene.onLeave()
end
Expand Down

0 comments on commit 69a6f67

Please sign in to comment.