mirror of
https://gitlab.com/Syroot/Worms.git
synced 2025-05-05 11:19:29 +03:00
Add Shell project.
This commit is contained in:
parent
c7d7f5cb3e
commit
93f9481dc9
@ -39,6 +39,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Syroot.Worms.Mgame.GameServ
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Syroot.Worms.Mgame.Test", "test\Syroot.Worms.Mgame.Test\Syroot.Worms.Mgame.Test.csproj", "{212F8090-9775-4098-BD44-9ABC01FBE553}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Syroot.Worms.Mgame.Test", "test\Syroot.Worms.Mgame.Test\Syroot.Worms.Mgame.Test.csproj", "{212F8090-9775-4098-BD44-9ABC01FBE553}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Syroot.Worms.Shell", "tool\Syroot.Worms.Shell\Syroot.Worms.Shell.csproj", "{1FAB6B9F-2585-46DC-81C0-579DC808C389}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -105,6 +107,10 @@ Global
|
|||||||
{212F8090-9775-4098-BD44-9ABC01FBE553}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{212F8090-9775-4098-BD44-9ABC01FBE553}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{212F8090-9775-4098-BD44-9ABC01FBE553}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{212F8090-9775-4098-BD44-9ABC01FBE553}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{212F8090-9775-4098-BD44-9ABC01FBE553}.Release|Any CPU.Build.0 = Release|Any CPU
|
{212F8090-9775-4098-BD44-9ABC01FBE553}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{1FAB6B9F-2585-46DC-81C0-579DC808C389}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{1FAB6B9F-2585-46DC-81C0-579DC808C389}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{1FAB6B9F-2585-46DC-81C0-579DC808C389}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{1FAB6B9F-2585-46DC-81C0-579DC808C389}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@ -125,6 +131,7 @@ Global
|
|||||||
{351B93B0-301F-42E1-82A0-7FA217154F5D} = {99E56312-A064-4AD3-8443-0B56A5F76E6B}
|
{351B93B0-301F-42E1-82A0-7FA217154F5D} = {99E56312-A064-4AD3-8443-0B56A5F76E6B}
|
||||||
{392E4CA2-61D9-4BE1-B065-8801A9F102B8} = {0B9B0B74-3EB1-46A4-BCCC-F2D6AE59A9EE}
|
{392E4CA2-61D9-4BE1-B065-8801A9F102B8} = {0B9B0B74-3EB1-46A4-BCCC-F2D6AE59A9EE}
|
||||||
{212F8090-9775-4098-BD44-9ABC01FBE553} = {99E56312-A064-4AD3-8443-0B56A5F76E6B}
|
{212F8090-9775-4098-BD44-9ABC01FBE553} = {99E56312-A064-4AD3-8443-0B56A5F76E6B}
|
||||||
|
{1FAB6B9F-2585-46DC-81C0-579DC808C389} = {0B9B0B74-3EB1-46A4-BCCC-F2D6AE59A9EE}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {1CD4EDE2-A5FB-4A58-A850-3506AB7E7B69}
|
SolutionGuid = {1CD4EDE2-A5FB-4A58-A850-3506AB7E7B69}
|
||||||
|
19
src/tool/Syroot.Worms.Shell/AssemblyInfo.cs
Normal file
19
src/tool/Syroot.Worms.Shell/AssemblyInfo.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Syroot.Worms.Shell
|
||||||
|
{
|
||||||
|
internal static class AssemblyInfo
|
||||||
|
{
|
||||||
|
// ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static AssemblyInfo()
|
||||||
|
{
|
||||||
|
Assembly entryAssembly = Assembly.GetEntryAssembly();
|
||||||
|
Title = entryAssembly.GetCustomAttribute<AssemblyTitleAttribute>().Title;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
internal static string Title { get; }
|
||||||
|
}
|
||||||
|
}
|
112
src/tool/Syroot.Worms.Shell/ImgContextMenu.cs
Normal file
112
src/tool/Syroot.Worms.Shell/ImgContextMenu.cs
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Drawing.Imaging;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using SharpShell.Attributes;
|
||||||
|
using SharpShell.SharpContextMenu;
|
||||||
|
|
||||||
|
namespace Syroot.Worms.Shell
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a context menu extension for <see cref="Image"/> files.
|
||||||
|
/// </summary>
|
||||||
|
[ComVisible(true)]
|
||||||
|
[COMServerAssociation(AssociationType.ClassOfExtension, ".img")]
|
||||||
|
internal class ImgContextMenu : SharpContextMenu
|
||||||
|
{
|
||||||
|
// ---- METHODS (PROTECTED) ------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
protected override bool CanShowMenu()
|
||||||
|
{
|
||||||
|
// At least one image must be convertible.
|
||||||
|
foreach (string file in SelectedItemPaths)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Img img = new Img(file);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override ContextMenuStrip CreateMenu()
|
||||||
|
{
|
||||||
|
ToolStripMenuItem menuItem = new ToolStripMenuItem { Text = "Convert to PNG" };
|
||||||
|
menuItem.Click += (s, e) =>
|
||||||
|
{
|
||||||
|
// Convert all files.
|
||||||
|
var tasks = new List<(string file, ConversionResult result)>();
|
||||||
|
foreach (string file in SelectedItemPaths)
|
||||||
|
{
|
||||||
|
(string file, ConversionResult result) task = (file, ConversionResult.Success);
|
||||||
|
tasks.Add(task);
|
||||||
|
|
||||||
|
// If the file already exists, do nothing.
|
||||||
|
string newFile = Path.ChangeExtension(Path.GetFileNameWithoutExtension(file) + " {converted}", "png");
|
||||||
|
if (File.Exists(newFile))
|
||||||
|
{
|
||||||
|
task.result = ConversionResult.FileExists;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to convert to PNG.
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Img img = new Img(file);
|
||||||
|
using (Bitmap bitmap = img.ToBitmap())
|
||||||
|
bitmap.Save(newFile, ImageFormat.Png);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
task.result = ConversionResult.InvalidImg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show failed conversion results, if any.
|
||||||
|
var failedTasks = tasks.Where(x => x.result != ConversionResult.Success).ToList();
|
||||||
|
if (failedTasks.Count > 0)
|
||||||
|
{
|
||||||
|
StringBuilder stringBuilder = new StringBuilder("Conversion of the following files failed:");
|
||||||
|
stringBuilder.AppendLine();
|
||||||
|
foreach (var (file, result) in tasks)
|
||||||
|
stringBuilder.AppendLine($"{file} ({GetConversionResultMessage(result)}");
|
||||||
|
MessageBox.Show(stringBuilder.ToString(), AssemblyInfo.Title, MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Warning);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ContextMenuStrip menu = new ContextMenuStrip();
|
||||||
|
menu.Items.Add(menuItem);
|
||||||
|
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
private static string GetConversionResultMessage(ConversionResult result)
|
||||||
|
{
|
||||||
|
switch (result)
|
||||||
|
{
|
||||||
|
case ConversionResult.FileExists:
|
||||||
|
return "file already exists";
|
||||||
|
case ConversionResult.InvalidImg:
|
||||||
|
return "could not load image";
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ConversionResult
|
||||||
|
{
|
||||||
|
Success,
|
||||||
|
InvalidImg,
|
||||||
|
FileExists
|
||||||
|
}
|
||||||
|
}
|
38
src/tool/Syroot.Worms.Shell/ImgThumbnailHandler.cs
Normal file
38
src/tool/Syroot.Worms.Shell/ImgThumbnailHandler.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using SharpShell.Attributes;
|
||||||
|
using SharpShell.SharpThumbnailHandler;
|
||||||
|
|
||||||
|
namespace Syroot.Worms.Shell
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a thumbnail handler for <see cref="Img"/> files.
|
||||||
|
/// </summary>
|
||||||
|
[ComVisible(true)]
|
||||||
|
[COMServerAssociation(AssociationType.FileExtension, ".img")]
|
||||||
|
public class ImgThumbnailHandler : SharpThumbnailHandler
|
||||||
|
{
|
||||||
|
// ---- METHODS (PROTECTED) ------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
protected override Bitmap GetThumbnailImage(uint width)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Img img = new Img(SelectedItemStream);
|
||||||
|
using (Bitmap bitmap = img.ToBitmap())
|
||||||
|
{
|
||||||
|
// Calculate the thumbnail size and create the image buffer to return.
|
||||||
|
float scale = Math.Min(1, width / (float)bitmap.Width);
|
||||||
|
|
||||||
|
Size thumbnailSize = new Size((int)(scale * bitmap.Width), (int)(scale * bitmap.Height));
|
||||||
|
return new Bitmap(bitmap, thumbnailSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
2
src/tool/Syroot.Worms.Shell/Install.bat
Normal file
2
src/tool/Syroot.Worms.Shell/Install.bat
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm /codebase Syroot.Worms.Shell.dll
|
||||||
|
PAUSE
|
21
src/tool/Syroot.Worms.Shell/Syroot.Worms.Shell.csproj
Normal file
21
src/tool/Syroot.Worms.Shell/Syroot.Worms.Shell.csproj
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
<PropertyGroup>
|
||||||
|
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||||
|
<AssemblyOriginatorKeyFile>Syroot.Worms.Shell.snk</AssemblyOriginatorKeyFile>
|
||||||
|
<SignAssembly>true</SignAssembly>
|
||||||
|
<TargetFramework>net472</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="SharpShell" Version="2.7.1" />
|
||||||
|
<PackageReference Include="StrongNamer" Version="0.0.8" />
|
||||||
|
<ProjectReference Include="..\..\library\Syroot.Worms\Syroot.Worms.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="Install.bat">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="Uninstall.bat">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
BIN
src/tool/Syroot.Worms.Shell/Syroot.Worms.Shell.snk
Normal file
BIN
src/tool/Syroot.Worms.Shell/Syroot.Worms.Shell.snk
Normal file
Binary file not shown.
2
src/tool/Syroot.Worms.Shell/Uninstall.bat
Normal file
2
src/tool/Syroot.Worms.Shell/Uninstall.bat
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm /unregister Syroot.Worms.Shell.dll
|
||||||
|
PAUSE
|
Loading…
x
Reference in New Issue
Block a user