Allow extraction of icons for shortcuts (#1143)

This commit is contained in:
pizzaboxer 2024-09-27 23:08:57 +01:00
parent 96ed47635e
commit 81c6512055
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
11 changed files with 95 additions and 8 deletions

View File

@ -27,6 +27,14 @@
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\Icon2008.ico" />
<EmbeddedResource Include="Resources\Icon2011.ico" />
<EmbeddedResource Include="Resources\Icon2017.ico" />
<EmbeddedResource Include="Resources\Icon2019.ico" />
<EmbeddedResource Include="Resources\Icon2022.ico" />
<EmbeddedResource Include="Resources\IconBloxstrap.ico" />
<EmbeddedResource Include="Resources\IconEarly2015.ico" />
<EmbeddedResource Include="Resources\IconLate2015.ico" />
<EmbeddedResource Include="Resources\Mods\Cursor\From2006\ArrowCursor.png" />
<EmbeddedResource Include="Resources\Mods\Cursor\From2006\ArrowFarCursor.png" />
<EmbeddedResource Include="Resources\Mods\Cursor\From2013\ArrowCursor.png" />

View File

@ -12,7 +12,9 @@ namespace Bloxstrap.Models.SettingTasks.Base
public abstract bool Changed { get; }
public BaseTask(string prefix, string name) => Name = $"{prefix}.{name}";
public BaseTask(string prefix, string name) : this($"{prefix}.{name}") { }
public BaseTask(string name) => Name = name;
public override string ToString() => Name;

View File

@ -41,5 +41,7 @@ namespace Bloxstrap.Models.SettingTasks.Base
public override bool Changed => _newState != OriginalState;
public BoolBaseTask(string prefix, string name) : base(prefix, name) { }
public BoolBaseTask(string name) : base(name) { }
}
}

View File

@ -0,0 +1,42 @@
using System.Reflection;
using System.Windows.Markup;
namespace Bloxstrap.Models.SettingTasks
{
public class ExtractIconsTask : BoolBaseTask
{
public ExtractIconsTask() : base("ExtractIcons")
{
OriginalState = Directory.Exists(Paths.Icons);
}
public override void Execute()
{
if (NewState)
{
Directory.CreateDirectory(Paths.Icons);
var assembly = Assembly.GetExecutingAssembly();
var resourceNames = assembly.GetManifestResourceNames().Where(x => x.EndsWith(".ico"));
foreach (string name in resourceNames)
{
string path = Path.Combine(Paths.Icons, name.Replace("Bloxstrap.Resources.", ""));
var stream = assembly.GetManifestResourceStream(name)!;
using var memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
Filesystem.AssertReadOnly(path);
File.WriteAllBytes(path, memoryStream.ToArray());
}
}
else if (Directory.Exists(Paths.Icons))
{
Directory.Delete(Paths.Icons, true);
}
OriginalState = NewState;
}
}
}

View File

@ -42,7 +42,7 @@ namespace Bloxstrap.Models.SettingTasks
using var resourceStream = data.ResourceStream;
using var memoryStream = new MemoryStream();
data.ResourceStream.CopyTo(memoryStream);
resourceStream.CopyTo(memoryStream);
Filesystem.AssertReadOnly(data.FullFilePath);
File.WriteAllBytes(data.FullFilePath, memoryStream.ToArray());

View File

@ -1,6 +1,4 @@
using Bloxstrap.Models.SettingTasks.Base;
namespace Bloxstrap.Models.SettingTasks
namespace Bloxstrap.Models.SettingTasks
{
public class ShortcutTask : BoolBaseTask
{

View File

@ -22,6 +22,7 @@
public static string Integrations { get; private set; } = "";
public static string Modifications { get; private set; } = "";
public static string Roblox { get; private set; } = "";
public static string Icons { get; private set; } = "";
public static string Application { get; private set; } = "";
@ -37,6 +38,7 @@
Integrations = Path.Combine(Base, "Integrations");
Modifications = Path.Combine(Base, "Modifications");
Roblox = Path.Combine(Base, "Roblox");
Icons = Path.Combine(Base, "Icons");
Application = Path.Combine(Base, $"{App.ProjectName}.exe");
}

View File

@ -3088,6 +3088,24 @@ namespace Bloxstrap.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to To use for your shortcuts, right-click it, open properties, change icon, browse, and pick from the Icons folder..
/// </summary>
public static string Menu_Shortcuts_ExtractIcons_Description {
get {
return ResourceManager.GetString("Menu.Shortcuts.ExtractIcons.Description", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Extract Roblox icons to folder.
/// </summary>
public static string Menu_Shortcuts_ExtractIcons_Title {
get {
return ResourceManager.GetString("Menu.Shortcuts.ExtractIcons.Title", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Create shortcuts for quick access to specific functions. These will all be placed on the Desktop..
/// </summary>

View File

@ -1198,4 +1198,10 @@ Please manually delete Bloxstrap.exe from the install location or try restarting
{0}</value>
</data>
<data name="Menu.Shortcuts.ExtractIcons.Title" xml:space="preserve">
<value>Extract Roblox icons to folder</value>
</data>
<data name="Menu.Shortcuts.ExtractIcons.Description" xml:space="preserve">
<value>To use for your shortcuts, right-click it, open properties, change icon, browse, and pick from the Icons folder.</value>
</data>
</root>

View File

@ -17,6 +17,13 @@
<StackPanel Margin="0,0,14,14">
<TextBlock Margin="0,0,0,16" Text="{x:Static resources:Strings.Menu_Shortcuts_Description}" FontSize="14" Foreground="{DynamicResource TextFillColorSecondaryBrush}" />
<controls:OptionControl
Header="{x:Static resources:Strings.Menu_Shortcuts_ExtractIcons_Title}"
Description="{x:Static resources:Strings.Menu_Shortcuts_ExtractIcons_Description}"
Margin="0,0,0,16">
<ui:ToggleSwitch IsChecked="{Binding ExtractIconsTask.NewState, Mode=TwoWay}" />
</controls:OptionControl>
<TextBlock Text="{x:Static resources:Strings.Menu_Shortcuts_General_Title}" FontSize="20" FontWeight="Medium" />
<TextBlock Text="{x:Static resources:Strings.Menu_Shortcuts_General_Description}" Foreground="{DynamicResource TextFillColorSecondaryBrush}" />

View File

@ -12,5 +12,7 @@ namespace Bloxstrap.UI.ViewModels.Settings
public ShortcutTask PlayerIconTask { get; } = new("RobloxPlayer", Paths.Desktop, $"{Strings.LaunchMenu_LaunchRoblox}.lnk", "-player");
public ShortcutTask SettingsIconTask { get; } = new("Settings", Paths.Desktop, $"{Strings.Menu_Title}.lnk", "-settings");
public ExtractIconsTask ExtractIconsTask { get; } = new();
}
}