Skip to content

Commit

Permalink
Update base
Browse files Browse the repository at this point in the history
  • Loading branch information
bagusnl committed Nov 12, 2024
2 parents 30ab4ae + 73db88d commit 6180077
Show file tree
Hide file tree
Showing 23 changed files with 205 additions and 587 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
Platform: ${{ matrix.platform }}
DOTNET_INSTALL_DIR: '.\.dotnet'
DOTNET_VERSION: '9.x'
DOTNET_QUALITY: 'preview'
DOTNET_QUALITY: 'ga'
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages

steps:
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
Platform: ${{ matrix.platform }}
DOTNET_INSTALL_DIR: '.\.dotnet'
DOTNET_VERSION: '9.x'
DOTNET_QUALITY: 'preview'
DOTNET_QUALITY: 'ga'
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages

steps:
Expand Down
54 changes: 52 additions & 2 deletions CollapseLauncher/Classes/Helper/TaskSchedulerHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Hi3Helper;
using CollapseLauncher.ShellLinkCOM;
using Hi3Helper;
using Hi3Helper.Data;
using Hi3Helper.Shared.Region;
using System;
using System.Diagnostics;
Expand Down Expand Up @@ -140,8 +142,11 @@ private static void AppendTaskNameAndPathArgument(StringBuilder argumentBuilder)
argumentBuilder.Append('"');
}

internal static async Task RecreateIconShortcuts()
internal static void RecreateIconShortcuts()
{
/* Invocation from Hi3Helper.TaskScheduler is no longer being user.
* Moving to Main App's ShellLink implementation instead!
// Build the argument and get the current executable path
StringBuilder argumentBuilder = new StringBuilder();
argumentBuilder.Append("RecreateIcons");
Expand All @@ -160,6 +165,51 @@ internal static async Task RecreateIconShortcuts()
// Print init determination
CheckInitDetermination(returnCode);
*/

// Get current executable path as its target.
string currentExecPath = LauncherConfig.AppExecutablePath;
string workingDirPath = Path.GetDirectoryName(currentExecPath);

// Get exe's description
FileVersionInfo currentExecVersionInfo = FileVersionInfo.GetVersionInfo(currentExecPath);
string currentExecDescription = currentExecVersionInfo.FileDescription ?? "";

// Create shell link instance and save the shortcut under Desktop and User's Start menu
using ShellLink shellLink = new ShellLink()
{
IconIndex = 0,
IconPath = currentExecPath,
DisplayMode = LinkDisplayMode.edmNormal,
WorkingDirectory = workingDirPath,
Target = currentExecPath,
Description = currentExecDescription
};

// Get paths
string shortcutFilename = currentExecVersionInfo.ProductName + ".lnk";
string startMenuLocation = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
string desktopLocation = Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory);
string iconLocationStartMenu = Path.Combine(
startMenuLocation,
"Programs",
currentExecVersionInfo.CompanyName,
shortcutFilename);
string iconLocationDesktop = Path.Combine(
desktopLocation,
shortcutFilename);

// Get icon location directory
string iconLocationStartMenuDir = Path.GetDirectoryName(iconLocationStartMenu);
string iconLocationDesktopDir = Path.GetDirectoryName(iconLocationDesktop);

// Try create directory
Directory.CreateDirectory(iconLocationStartMenuDir);
Directory.CreateDirectory(iconLocationDesktopDir);

// Save the icons
shellLink.Save(iconLocationStartMenu);
shellLink.Save(iconLocationDesktop);
}

private static async Task<int> GetInvokeCommandReturnCode(string argument)
Expand Down
7 changes: 7 additions & 0 deletions CollapseLauncher/Classes/ShellLinkCOM/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public enum SHGetFileInfoConstants : int
SHGFI_OVERLAYINDEX = 0x000000040 // Get the index of the overlay
}

public enum LinkDisplayMode : uint
{
edmNormal = EShowWindowFlags.SW_NORMAL,
edmMinimized = EShowWindowFlags.SW_SHOWMINNOACTIVE,
edmMaximized = EShowWindowFlags.SW_MAXIMIZE
}

/// <summary>
/// Flags determining how the links with missing
/// targets are resolved.
Expand Down
24 changes: 6 additions & 18 deletions CollapseLauncher/Classes/ShellLinkCOM/ShellLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,11 @@
#pragma warning disable CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type
namespace CollapseLauncher.ShellLinkCOM
{
unsafe delegate void ToDelegateInvoke(char* buffer, int length);
unsafe delegate void ToDelegateWithW32FindDataInvoke(char* buffer, nint findDataPtr, int length);

public class ShellLink : IDisposable
{
private unsafe delegate void ToDelegateInvoke(char* buffer, int length);
private unsafe delegate void ToDelegateWithW32FindDataInvoke(char* buffer, nint findDataPtr, int length);

public enum LinkDisplayMode : uint
{
edmNormal = EShowWindowFlags.SW_NORMAL,
edmMinimized = EShowWindowFlags.SW_SHOWMINNOACTIVE,
edmMaximized = EShowWindowFlags.SW_MAXIMIZE
}

// Use Unicode (W) under NT, otherwise use ANSI
IShellLinkW? linkW;
IPersistFile? persistFileW;
Expand Down Expand Up @@ -87,14 +80,9 @@ public IntPtr GetIcon(bool large)
SHGetFileInfoConstants flags =
SHGetFileInfoConstants.SHGFI_ICON |
SHGetFileInfoConstants.SHGFI_ATTRIBUTES;
if (large)
{
flags = flags | SHGetFileInfoConstants.SHGFI_LARGEICON;
}
else
{
flags = flags | SHGetFileInfoConstants.SHGFI_SMALLICON;
}

flags = flags | (large ? SHGetFileInfoConstants.SHGFI_LARGEICON : SHGetFileInfoConstants.SHGFI_SMALLICON);

FileIcon fileIcon = new FileIcon(Target, flags);
return fileIcon.ShellIcon;
}
Expand Down
18 changes: 11 additions & 7 deletions CollapseLauncher/CollapseLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<!-- Target Settings -->
<Platforms>x64</Platforms>
<TargetFramework>net9.0-windows10.0.22621.0</TargetFramework>
<WindowsSdkPackageVersion>10.0.22621.48</WindowsSdkPackageVersion>
<WindowsSdkPackageVersion>10.0.22621.57</WindowsSdkPackageVersion>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
Expand Down Expand Up @@ -140,6 +140,10 @@
-->
<PackageReference Include="Clowd.Squirrel" Version="2.11.1" Condition="!$(DefineConstants.Contains('USEVELOPACK'))" />
<PackageReference Include="Libsql.Client" Version="0.5.0" />
<!-- Velopacks' outdated dependencies, remove this once they switched to .NET 9 -->
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
<!-- Velopacks' outdated dependencies, remove this once they switched to .NET 9 -->
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
<PackageReference Include="Sentry" Version="4.13.0" />
<PackageReference Include="Velopack" Version="0.0.869" Condition="$(DefineConstants.Contains('USEVELOPACK'))" />

Expand All @@ -159,27 +163,27 @@
<PackageReference Include="FFmpegInteropX" Version="*-*" Condition="$(DefineConstants.Contains('USEFFMPEGFORVIDEOBG'))" />

<PackageReference Include="GitInfo" Version="3.5.0" PrivateAssets="all" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.70" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.71" />
<PackageReference Include="Markdig.Signed" Version="0.38.0" />
<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.3.0" />
<PackageReference Include="Microsoft.NETCore.Targets" Version="6.0.0-preview.4.21253.7" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2895-prerelease" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.6" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.2.0" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1742" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240923002" />
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
<PackageReference Include="PhotoSauce.MagicScaler" Version="0.14.2" />
<PackageReference Include="PhotoSauce.NativeCodecs.Libwebp" Version="*-*" />
<PackageReference Include="Roman-Numerals" Version="2.0.1" />
<PackageReference Include="runtime.win-x64.Microsoft.DotNet.ILCompiler" Version="9.0.0-rc.2.24473.5" />
<PackageReference Include="runtime.win-x64.Microsoft.DotNet.ILCompiler" Version="9.0.0" />
<PackageReference Include="SharpCompress" Version="0.38.0" Condition="$(DefineConstants.Contains('USENEWZIPDECOMPRESS'))" />
<PackageReference Include="SharpHDiffPatch.Core" Version="2.2.8" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="System.CommandLine.NamingConventionBinder" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="System.Security.AccessControl" Version="6.0.1" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="9.0.0-rc.2.24473.5" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="9.0.0-rc.2.24473.5" />
<PackageReference Include="System.Text.Json" Version="9.0.0-rc.2.24473.5" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="9.0.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="9.0.0" />
<PackageReference Include="System.Text.Json" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
44 changes: 39 additions & 5 deletions CollapseLauncher/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using CollapseLauncher.Helper;
using CollapseLauncher.Helper;
using CollapseLauncher.Helper.Update;
using CollapseLauncher.ShellLinkCOM;
using Hi3Helper;
using Hi3Helper.SentryHelper;
using Hi3Helper.Data;
using Hi3Helper.Http.Legacy;
using Hi3Helper.Shared.ClassStruct;
using InnoSetupHelper;
Expand All @@ -18,6 +20,7 @@
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
Expand Down Expand Up @@ -318,13 +321,17 @@ private static void StartUpdaterHook()
public static void TryCleanupFallbackUpdate(SemanticVersion newVersion)
{
string currentExecutedAppFolder = AppFolder.TrimEnd('\\');
string currentExecutedPath = AppExecutablePath;
string currentExecutedFilename = Path.GetFileName(currentExecutedPath);

// If the path is not actually running under "current" velopack folder, then return
#if !DEBUG
if (!currentExecutedAppFolder.EndsWith("current", StringComparison.OrdinalIgnoreCase)) // Expecting "current"
{
Logger.LogWriteLine("[TryCleanupFallbackUpdate] The launcher does not run from \"current\" folder");
return;
}
#endif

try
{
Expand Down Expand Up @@ -374,8 +381,35 @@ public static void TryCleanupFallbackUpdate(SemanticVersion newVersion)
}
}

// Try to delete all possible shortcuts on any users (since the shortcut used will be the global one)
string currentUsersDirPath = Path.Combine(currentWindowsPathDrive, "Users");
foreach (string userDirInfoPath in Directory
.EnumerateDirectories(currentUsersDirPath, "*", SearchOption.TopDirectoryOnly)
.Where(ConverterTool.IsUserHasPermission))
{
// Get the shortcut file
string thisUserStartMenuShortcut = Path.Combine(userDirInfoPath, @"AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Collapse.lnk");
if (File.Exists(thisUserStartMenuShortcut))
{
// Try open the shortcut and check whether this shortcut is actually pointing to
// CollapseLauncher.exe file
using (ShellLink shellLink = new ShellLink(thisUserStartMenuShortcut))
{
// Try get the target path and its filename
string shortcutTargetPath = shellLink.Target;
string shortcutTargetFilename = Path.GetFileName(shortcutTargetPath);

// Compare if the filename is equal, then delete it.
if (shortcutTargetFilename.Equals(currentExecutedFilename, StringComparison.OrdinalIgnoreCase))
File.Delete(thisUserStartMenuShortcut);

LogWriteLine($"[TryCleanupFallbackUpdate] Deleted old shortcut located at: {thisUserStartMenuShortcut} -> {shortcutTargetPath}", LogType.Default, true);
}
}
}

// Try to recreate shortcuts
TaskSchedulerHelper.RecreateIconShortcuts().GetAwaiter().GetResult();
TaskSchedulerHelper.RecreateIconShortcuts();
}
catch (Exception ex)
{
Expand Down Expand Up @@ -410,13 +444,13 @@ public static string FindCollapseStubPath()
LogType.Default, true);
return collapseMainPath;
}

private static async Task CheckRuntimeFeatures()
{
try
{
await Task.Run(() =>
{
{
// RuntimeFeature docs https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.runtimefeature?view=net-9.0
LogWriteLine($"Available Runtime Features:\r\n\t" +
$"PortablePdb: {RuntimeFeature.IsSupported(RuntimeFeature.PortablePdb)}\r\n\t" +
Expand Down Expand Up @@ -506,7 +540,7 @@ public static string GetVersionString()
return $"Windows 11 (build: {version.Build}.{version.Revision})";
return $"Windows {version.Major} (build: {version.Build}.{version.Revision})";
}

public static string MD5Hash(string path)
{
if (!File.Exists(path))
Expand Down
14 changes: 7 additions & 7 deletions CollapseLauncher/XAMLs/MainApp/Pages/HomePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@
PointerExited="ElementScaleInHoveredPointerExited"
Shadow="{ThemeResource SharedShadow}"
Style="{ThemeResource AcrylicSemiButtonStyle}"
Tag="{x:Bind Url, Mode=OneWay}"
Tag="{x:Bind Url}"
Translation="0,0,8">
<Grid Margin="0,0,0,0"
HorizontalAlignment="Stretch">
Expand All @@ -532,7 +532,7 @@
VerticalAlignment="Center"
FontWeight="Medium"
HorizontalTextAlignment="Left"
Text="{x:Bind Title, Mode=OneWay}" />
Text="{x:Bind Title}" />
</Grid>
<Grid Grid.Column="1"
Margin="4,0,0,0"
Expand Down Expand Up @@ -579,10 +579,10 @@
</Button.Flyout>
<Grid>
<imageex:ImageEx x:Name="Icon"
Source="{x:Bind IconImg, Mode=OneWay}" />
Source="{x:Bind IconImg}" />
<imageex:ImageEx x:Name="IconHover"
Opacity="0"
Source="{x:Bind IconImgHover, Mode=OneWay}" />
Source="{x:Bind IconImgHover}" />
</Grid>
</Button>
</Grid>
Expand Down Expand Up @@ -707,7 +707,7 @@
HorizontalAlignment="Right"
Visibility="{x:Bind IsPostEventPanelEmpty}">
<StackPanel Orientation="Horizontal">
<TextBlock Width="{x:Bind PostEmptyMascotTextWidth, Mode=OneWay}"
<TextBlock Width="{x:Bind PostEmptyMascotTextWidth}"
Margin="{x:Bind localWindowSize:WindowSize.CurrentWindowSize.PostPanelPaimonTextMargin}"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Expand Down Expand Up @@ -782,7 +782,7 @@
HorizontalAlignment="Right"
Visibility="{x:Bind IsPostNoticePanelEmpty}">
<StackPanel Orientation="Horizontal">
<TextBlock Width="{x:Bind PostEmptyMascotTextWidth, Mode=OneWay}"
<TextBlock Width="{x:Bind PostEmptyMascotTextWidth}"
Margin="{x:Bind localWindowSize:WindowSize.CurrentWindowSize.PostPanelPaimonTextMargin}"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Expand Down Expand Up @@ -857,7 +857,7 @@
HorizontalAlignment="Right"
Visibility="{x:Bind IsPostInfoPanelEmpty}">
<StackPanel Orientation="Horizontal">
<TextBlock Width="{x:Bind PostEmptyMascotTextWidth, Mode=OneWay}"
<TextBlock Width="{x:Bind PostEmptyMascotTextWidth}"
Margin="{x:Bind localWindowSize:WindowSize.CurrentWindowSize.PostPanelPaimonTextMargin}"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
<ScrollViewer>
<Grid>
<markdown:MarkdownTextBlock Margin="24"
Config="{x:Bind markdownConfig, Mode=OneWay}"
Config="{x:Bind markdownConfig}"
TabNavigation="Once"
Text="{x:Bind text, Mode=OneWay}" />
Text="{x:Bind text}" />
</Grid>
</ScrollViewer>
</Grid>
Expand Down
Loading

0 comments on commit 6180077

Please sign in to comment.