diff --git a/CHANGELOG.md b/CHANGELOG.md index 58b9f12..23dd698 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +## 1.0.0-beta.1.3.1 + +- Fix classic (`.lnk`) shortcuts for games whose executable, folder or name has Japanese (or other non-ANSI) characters. They were written through `WScript.Shell`, which turned those characters into `?`, so the icon pointed to a file that does not exist and Windows showed VNAR's icon instead of the game's, making the shortcut look like a modern one. Classic shortcuts are now written with the Unicode Shell Link API. Shortcuts created with Beta 1.3 for those games need to be created again. +- `VNAR.ShellTests` reads shortcuts back through the Unicode Shell Link API and covers a game with Japanese name, folder and icon path. + ## 1.0.0-beta.1.3 - Data files (`library.json`, `developers.json`, `settings.json`) are written atomically, keeping the previous version as `.bak`. diff --git a/Directory.Build.props b/Directory.Build.props index 9a9b46c..7c286ef 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -7,7 +7,7 @@ GitHub release tag all derive from this value. --> - 1.0.0-beta.1.3 + 1.0.0-beta.1.3.1 false diff --git a/LocaleGameHub/Services/ShortcutService.cs b/LocaleGameHub/Services/ShortcutService.cs index ad0cb1a..289b749 100644 --- a/LocaleGameHub/Services/ShortcutService.cs +++ b/LocaleGameHub/Services/ShortcutService.cs @@ -84,7 +84,8 @@ private interface IUniformResourceLocatorW [PreserveSig] int InvokeCommand(IntPtr commandInfo); } - // Full vtable order of IShellLinkW; only SetIconLocation is called. + // Full vtable order of IShellLinkW. Used for classic .lnk shortcuts and for the + // icon of modern .url shortcuts (the Internet Shortcut object implements it too). [ComImport] [Guid("000214F9-0000-0000-C000-000000000046")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] @@ -132,42 +133,43 @@ public static string CreateShortcut(GameEntry game, string shortcutName, string var shortcutPath = Path.Combine(destinationFolder, safeName + ".lnk"); var target = ResolveVnarExecutable(); - var shellType = Type.GetTypeFromProgID("WScript.Shell") - ?? throw new InvalidOperationException(LocalizationService.Bi("Windows Script Host no está disponible para crear el acceso directo.", "Windows Script Host is not available to create the shortcut.")); - object? shellObject = null; - object? shortcutObject = null; + // Use the Shell Link object directly instead of WScript.Shell: WshShortcut + // converts every string to the ANSI code page, so a game .exe (or a name or + // folder) with Japanese characters ended up as "???.exe". The icon location + // then pointed nowhere and Explorer fell back to VNAR.exe's own icon, which + // made the classic shortcut look like a modern one. + var linkType = Type.GetTypeFromCLSID(new Guid("00021401-0000-0000-C000-000000000046"), true)!; + var link = Activator.CreateInstance(linkType) + ?? throw new InvalidOperationException(LocalizationService.Bi( + "No se pudo iniciar el creador de accesos directos de Windows.", "Could not start the Windows shortcut creator.")); try { - shellObject = Activator.CreateInstance(shellType) - ?? throw new InvalidOperationException(LocalizationService.Bi("No se pudo iniciar el creador de accesos directos de Windows.", "Could not start the Windows shortcut creator.")); - - dynamic shell = shellObject; - dynamic shortcut = shell.CreateShortcut(shortcutPath); - shortcutObject = shortcut; - - shortcut.TargetPath = target; - shortcut.Arguments = $"--launch {game.Id:D}"; - shortcut.WorkingDirectory = AppContext.BaseDirectory; - shortcut.Description = $"VNAR · {game.Name}"; - shortcut.IconLocation = BuildIconLocation(iconPath); - shortcut.Save(); + var shellLink = (IShellLinkW)link; + Marshal.ThrowExceptionForHR(shellLink.SetPath(target)); + Marshal.ThrowExceptionForHR(shellLink.SetArguments($"--launch {game.Id:D}")); + Marshal.ThrowExceptionForHR(shellLink.SetWorkingDirectory(AppContext.BaseDirectory)); + Marshal.ThrowExceptionForHR(shellLink.SetDescription(BuildDescription(game.Name))); + Marshal.ThrowExceptionForHR(shellLink.SetIconLocation(ResolveIconPath(iconPath), 0)); + ((System.Runtime.InteropServices.ComTypes.IPersistFile)link).Save(shortcutPath, true); } finally { - ReleaseCom(shortcutObject); - ReleaseCom(shellObject); + ReleaseCom(link); } TaskbarIdentityService.SetShortcutIdentity(shortcutPath, game.Id); return shortcutPath; } - private static string BuildIconLocation(string iconPath) + private static string ResolveIconPath(string iconPath) + => string.IsNullOrWhiteSpace(iconPath) || !File.Exists(iconPath) ? GetGenericIconPath() : iconPath; + + // IShellLink limits the comment (INFOTIPSIZE) to 1024 characters. + private static string BuildDescription(string gameName) { - if (string.IsNullOrWhiteSpace(iconPath) || !File.Exists(iconPath)) - iconPath = GetGenericIconPath(); - return iconPath + ",0"; + var description = $"VNAR · {gameName}"; + return description.Length <= 1023 ? description : description[..1023]; } public static string ResolveVnarExecutable() diff --git a/README.es.md b/README.es.md index c481b97..d79645d 100644 --- a/README.es.md +++ b/README.es.md @@ -7,7 +7,7 @@ Un launcher ligero para Windows enfocado en visual novels, con integración con Locale Emulator, metadatos de VNDB, edición de portadas, navegación por desarrolladores, favoritos, soporte WebP y accesos directos inteligentes. -[English](README.md) · [Descargar Beta 1.3](https://github.com/JAVCIF/vnar/releases/tag/v1.0.0-beta.1.3) +[English](README.md) · [Descargar Beta 1.3.1](https://github.com/JAVCIF/vnar/releases/tag/v1.0.0-beta.1.3.1) ## Descargas @@ -16,8 +16,8 @@ Un launcher ligero para Windows enfocado en visual novels, con integración con | Paquete | Descripción | Descarga | | --- | --- | --- | -| Instalador | Instalación autocontenida, acceso en el menú Inicio y acceso de escritorio opcional | [VNAR-Setup.exe](https://github.com/JAVCIF/vnar/releases/download/v1.0.0-beta.1.3/VNAR-Setup.exe) | -| Portable | Versión autocontenida; descomprime y ejecuta `VNAR.exe` | [VNAR-Portable-win-x64.zip](https://github.com/JAVCIF/vnar/releases/download/v1.0.0-beta.1.3/VNAR-Portable-win-x64.zip) | +| Instalador | Instalación autocontenida, acceso en el menú Inicio y acceso de escritorio opcional | [VNAR-Setup.exe](https://github.com/JAVCIF/vnar/releases/download/v1.0.0-beta.1.3.1/VNAR-Setup.exe) | +| Portable | Versión autocontenida; descomprime y ejecuta `VNAR.exe` | [VNAR-Portable-win-x64.zip](https://github.com/JAVCIF/vnar/releases/download/v1.0.0-beta.1.3.1/VNAR-Portable-win-x64.zip) | Locale Emulator **no viene incluido** dentro de VNAR. En el primer arranque puedes seleccionar un `LEProc.exe` existente o dejar que VNAR descargue la versión oficial de Locale Emulator. @@ -102,7 +102,7 @@ del protocolo `vnar://`. ## Estado del proyecto -Versión pública actual: **Beta 1.3 (`1.0.0-beta.1.3`)**. +Versión pública actual: **Beta 1.3.1 (`1.0.0-beta.1.3.1`)**. Puedes usar GitHub Issues para reportar errores o proponer mejoras. diff --git a/README.md b/README.md index 8a9f5f0..89d1b03 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ A lightweight Windows launcher for visual novels with Locale Emulator integration, VNDB metadata, cover editing, developer browsing, favorites, WebP support, and smart desktop shortcuts. -[Español](README.es.md) · [Download Beta 1.3](https://github.com/JAVCIF/vnar/releases/tag/v1.0.0-beta.1.3) +[Español](README.es.md) · [Download Beta 1.3.1](https://github.com/JAVCIF/vnar/releases/tag/v1.0.0-beta.1.3.1) ## Downloads @@ -16,8 +16,8 @@ A lightweight Windows launcher for visual novels with Locale Emulator integratio | Package | Description | Download | | --- | --- | --- | -| Installer | Self-contained installation with Start Menu integration and optional desktop shortcut | [VNAR-Setup.exe](https://github.com/JAVCIF/vnar/releases/download/v1.0.0-beta.1.3/VNAR-Setup.exe) | -| Portable | Self-contained portable build; extract and run `VNAR.exe` | [VNAR-Portable-win-x64.zip](https://github.com/JAVCIF/vnar/releases/download/v1.0.0-beta.1.3/VNAR-Portable-win-x64.zip) | +| Installer | Self-contained installation with Start Menu integration and optional desktop shortcut | [VNAR-Setup.exe](https://github.com/JAVCIF/vnar/releases/download/v1.0.0-beta.1.3.1/VNAR-Setup.exe) | +| Portable | Self-contained portable build; extract and run `VNAR.exe` | [VNAR-Portable-win-x64.zip](https://github.com/JAVCIF/vnar/releases/download/v1.0.0-beta.1.3.1/VNAR-Portable-win-x64.zip) | Locale Emulator is **not bundled** with VNAR. On first launch, VNAR can use an existing `LEProc.exe` or download the official Locale Emulator release for you. @@ -113,7 +113,7 @@ dotnet run --project .\tests\VNAR.ShellTests\VNAR.ShellTests.csproj -c Release ## Project status -Current public build: **Beta 1.3 (`1.0.0-beta.1.3`)**. +Current public build: **Beta 1.3.1 (`1.0.0-beta.1.3.1`)**. Bug reports and suggestions are welcome through GitHub Issues. diff --git a/tests/VNAR.ShellTests/Program.cs b/tests/VNAR.ShellTests/Program.cs index c76c1ce..89a5f50 100644 --- a/tests/VNAR.ShellTests/Program.cs +++ b/tests/VNAR.ShellTests/Program.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Runtime.InteropServices; +using System.Text; using LocaleGameHub.Models; using LocaleGameHub.Services; @@ -41,7 +42,6 @@ private static int Main(string[] args) Equal(TaskbarIdentityService.LauncherAppId, ReadProcessIdentity(), "launcher after second game"); Console.WriteLine("PASS: explicit process identities remain separate."); - // Keep fixture filenames independent of WScript.Shell ANSI code-page limitations. var normalLink = ShortcutService.CreateShortcut(first, "Normal shortcut", root, icon); var adminLink = ShortcutService.CreateShortcut(second, "Admin shortcut", root, icon); VerifyShortcut(normalLink, first, icon); @@ -67,6 +67,19 @@ private static int Main(string[] args) VerifyShortcut(replacement, first, icon); Console.WriteLine("PASS: shortcut replacement preserves target, arguments, description and icon."); + // Games whose .exe (and therefore the chosen icon) has Japanese characters: + // the link must keep the exact Unicode path, not an ANSI "???.exe" that + // makes Explorer fall back to VNAR.exe's icon. + var japaneseFolder = Path.Combine(root, "ゲーム フォルダ"); + Directory.CreateDirectory(japaneseFolder); + var japaneseIcon = Path.Combine(japaneseFolder, "蒼の彼方のフォーリズム.ico"); + File.Copy(icon, japaneseIcon); + var japaneseGame = new GameEntry { Name = "蒼の彼方のフォーリズム" }; + var japaneseLink = ShortcutService.CreateShortcut(japaneseGame, japaneseGame.Name, japaneseFolder, japaneseIcon); + Equal(Path.Combine(japaneseFolder, "蒼の彼方のフォーリズム.lnk"), japaneseLink, "Unicode shortcut path"); + VerifyShortcut(japaneseLink, japaneseGame, japaneseIcon); + Console.WriteLine("PASS: classic shortcuts keep Japanese names and icon paths intact."); + ModernShortcutTests.Run(root, icon); return 0; } @@ -86,27 +99,57 @@ private static void VerifyShortcut(string path, GameEntry game, string icon) { Equal(TaskbarIdentityService.GetGameAppId(game.Id), ReadShortcutIdentity(path), "persisted AppUserModelID"); - object? shellObject = null; - object? linkObject = null; + // Read through IShellLinkW: WScript.Shell would turn non-ANSI characters into "?". + var link = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("00021401-0000-0000-C000-000000000046"), true)!)!; try { - shellObject = Activator.CreateInstance(Type.GetTypeFromProgID("WScript.Shell")!); - dynamic shell = shellObject!; - linkObject = shell.CreateShortcut(path); - dynamic link = linkObject; - Equal(ShortcutService.ResolveVnarExecutable().ToUpperInvariant(), - ((string)link.TargetPath).ToUpperInvariant(), "shortcut target"); - Equal($"--launch {game.Id:D}", (string)link.Arguments, "shortcut arguments"); - Equal(icon.ToUpperInvariant() + ",0", ((string)link.IconLocation).ToUpperInvariant(), "chosen icon"); - Equal($"VNAR · {game.Name}", (string)link.Description, "shortcut description"); + ((System.Runtime.InteropServices.ComTypes.IPersistFile)link).Load(path, 0); + var shellLink = (IShellLinkWReader)link; + var buffer = new StringBuilder(1024); + + Marshal.ThrowExceptionForHR(shellLink.GetPath(buffer, buffer.Capacity, IntPtr.Zero, 0)); + Equal(ShortcutService.ResolveVnarExecutable().ToUpperInvariant(), buffer.ToString().ToUpperInvariant(), "shortcut target"); + + buffer.Clear(); + Marshal.ThrowExceptionForHR(shellLink.GetArguments(buffer, buffer.Capacity)); + Equal($"--launch {game.Id:D}", buffer.ToString(), "shortcut arguments"); + + buffer.Clear(); + Marshal.ThrowExceptionForHR(shellLink.GetIconLocation(buffer, buffer.Capacity, out var iconIndex)); + Equal(icon.ToUpperInvariant() + ",0", buffer.ToString().ToUpperInvariant() + "," + iconIndex, "chosen icon"); + + buffer.Clear(); + Marshal.ThrowExceptionForHR(shellLink.GetDescription(buffer, buffer.Capacity)); + Equal($"VNAR · {game.Name}", buffer.ToString(), "shortcut description"); } finally { - Release(linkObject); - Release(shellObject); + Release(link); } } + // Vtable order of IShellLinkW up to GetIconLocation; only getters are used here. + [ComImport] + [Guid("000214F9-0000-0000-C000-000000000046")] + [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] + private interface IShellLinkWReader + { + [PreserveSig] int GetPath([MarshalAs(UnmanagedType.LPWStr)] StringBuilder file, int maxPath, IntPtr findData, uint flags); + [PreserveSig] int GetIDList(out IntPtr idList); + [PreserveSig] int SetIDList(IntPtr idList); + [PreserveSig] int GetDescription([MarshalAs(UnmanagedType.LPWStr)] StringBuilder name, int maxName); + [PreserveSig] int SetDescription([MarshalAs(UnmanagedType.LPWStr)] string name); + [PreserveSig] int GetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] StringBuilder dir, int maxPath); + [PreserveSig] int SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] string dir); + [PreserveSig] int GetArguments([MarshalAs(UnmanagedType.LPWStr)] StringBuilder args, int maxPath); + [PreserveSig] int SetArguments([MarshalAs(UnmanagedType.LPWStr)] string args); + [PreserveSig] int GetHotkey(out short hotkey); + [PreserveSig] int SetHotkey(short hotkey); + [PreserveSig] int GetShowCmd(out int showCmd); + [PreserveSig] int SetShowCmd(int showCmd); + [PreserveSig] int GetIconLocation([MarshalAs(UnmanagedType.LPWStr)] StringBuilder iconPath, int maxIconPath, out int iconIndex); + } + private static string ReadShortcutIdentity(string path) { // Read through Explorer's canonical property name, independently of the