Skip to content

Commit

Permalink
Allow extraction of icons for shortcuts (#1143)
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzaboxer committed Sep 27, 2024
1 parent 96ed476 commit 81c6512
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 8 deletions.
10 changes: 9 additions & 1 deletion Bloxstrap/Bloxstrap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
</PropertyGroup>

<ItemGroup>
<Resource Include="Bloxstrap.ico" />
<Resource Include="Resources\Fonts\NotoSansThai-VariableFont_wdth,wght.ttf" />
Expand All @@ -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" />
Expand Down
4 changes: 3 additions & 1 deletion Bloxstrap/Models/SettingTasks/Base/BaseTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public abstract class BaseTask

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;

Expand Down
2 changes: 2 additions & 0 deletions Bloxstrap/Models/SettingTasks/Base/BoolBaseTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ public virtual bool NewState
public override bool Changed => _newState != OriginalState;

public BoolBaseTask(string prefix, string name) : base(prefix, name) { }

public BoolBaseTask(string name) : base(name) { }
}
}
42 changes: 42 additions & 0 deletions Bloxstrap/Models/SettingTasks/ExtractIconsTask.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
2 changes: 1 addition & 1 deletion Bloxstrap/Models/SettingTasks/ModPresetTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override void Execute()

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());
Expand Down
8 changes: 3 additions & 5 deletions Bloxstrap/Models/SettingTasks/ShortcutTask.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Bloxstrap.Models.SettingTasks.Base;

namespace Bloxstrap.Models.SettingTasks
namespace Bloxstrap.Models.SettingTasks
{
public class ShortcutTask : BoolBaseTask
{
private string _shortcutPath;

private string _exeFlags;

public ShortcutTask(string name, string lnkFolder, string lnkName, string exeFlags = "") : base("Shortcut", name)
Expand All @@ -26,4 +24,4 @@ public override void Execute()
OriginalState = NewState;
}
}
}
}
2 changes: 2 additions & 0 deletions Bloxstrap/Paths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ static class Paths
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; } = "";

Expand All @@ -37,6 +38,7 @@ public static void Initialize(string baseDirectory)
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");
}
Expand Down
18 changes: 18 additions & 0 deletions Bloxstrap/Resources/Strings.Designer.cs

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

6 changes: 6 additions & 0 deletions Bloxstrap/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
7 changes: 7 additions & 0 deletions Bloxstrap/UI/Elements/Settings/Pages/ShortcutsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}" />

Expand Down
2 changes: 2 additions & 0 deletions Bloxstrap/UI/ViewModels/Settings/ShortcutsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public class ShortcutsViewModel : NotifyPropertyChangedViewModel
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();
}
}

0 comments on commit 81c6512

Please sign in to comment.