Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Initial commit
  • Loading branch information
ShyRed committed Sep 15, 2018
1 parent 31f0938 commit bb26f10
Show file tree
Hide file tree
Showing 13 changed files with 760 additions and 0 deletions.
6 changes: 6 additions & 0 deletions App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
53 changes: 53 additions & 0 deletions AssemblyHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.IO;
using System.Reflection;

namespace EmbeddedResourceExtractor
{
public class AssemblyHelper
{
public string FilePath { get; private set; }
public bool IsValid { get { return assembly != null; } }
public string ErrorDescription { get; private set; }

private readonly Assembly assembly;

public AssemblyHelper(string filePath)
{
FilePath = filePath;

try
{
assembly = Assembly.LoadFile(filePath);
}
catch(Exception ex)
{
ErrorDescription = ex.Message;
}
}

public string[] ListResourceNames()
{
if (!IsValid)
return new string[0];

return assembly.GetManifestResourceNames();
}

public void WriteResourceToFile(string resourceName, string folder)
{
if (!IsValid)
return;

var fileName = Path.Combine(folder, resourceName);

using (var resource = assembly.GetManifestResourceStream(resourceName))
{
using (var file = new FileStream(fileName, FileMode.Create, FileAccess.Write))
{
resource.CopyTo(file);
}
}
}
}
}
84 changes: 84 additions & 0 deletions EmbeddedResourceExtractor.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{4474A5EB-1AB6-4CA1-8F4F-C0F827E627FC}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>EmbeddedResourceExtractor</RootNamespace>
<AssemblyName>EmbeddedResourceExtractor</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyHelper.cs" />
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
25 changes: 25 additions & 0 deletions EmbeddedResourceExtractor.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2019
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmbeddedResourceExtractor", "EmbeddedResourceExtractor.csproj", "{4474A5EB-1AB6-4CA1-8F4F-C0F827E627FC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4474A5EB-1AB6-4CA1-8F4F-C0F827E627FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4474A5EB-1AB6-4CA1-8F4F-C0F827E627FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4474A5EB-1AB6-4CA1-8F4F-C0F827E627FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4474A5EB-1AB6-4CA1-8F4F-C0F827E627FC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {EBB58348-C540-4B22-B9D3-591B0BD38F84}
EndGlobalSection
EndGlobal
110 changes: 110 additions & 0 deletions MainForm.Designer.cs

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

73 changes: 73 additions & 0 deletions MainForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using System.Windows.Forms;

namespace EmbeddedResourceExtractor
{
public partial class MainForm : Form
{
private AssemblyHelper assemblyHelper;

public MainForm()
{
InitializeComponent();
}

private void ButtonLoad_Click(object sender, EventArgs e)
{
var assemblyPath = textBoxAssemblyFile.Text;
if (string.IsNullOrWhiteSpace(assemblyPath) || !System.IO.File.Exists(assemblyPath))
{
if (openFileDialogAssembly.ShowDialog() != DialogResult.OK)
return;
assemblyPath = openFileDialogAssembly.FileName;
textBoxAssemblyFile.Text = assemblyPath;
}

listBoxResourceNames.Items.Clear();
buttonExport.Enabled = false;
assemblyHelper = new AssemblyHelper(assemblyPath);
if (!assemblyHelper.IsValid)
{
MessageBox.Show(assemblyHelper.ErrorDescription,
"Not a valid Assembly",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
assemblyHelper = null;
return;
}

listBoxResourceNames.Items.AddRange(assemblyHelper.ListResourceNames());
}

private void ButtonExport_Click(object sender, EventArgs e)
{
if (assemblyHelper == null || !assemblyHelper.IsValid)
return;

if (folderBrowserDialogExportTarget.ShowDialog() != DialogResult.OK)
return;

var targetFolderPath = folderBrowserDialogExportTarget.SelectedPath;
foreach (var resourceName in listBoxResourceNames.SelectedItems)
{
try
{
assemblyHelper.WriteResourceToFile((string)resourceName, targetFolderPath);
}
catch (Exception ex)
{
MessageBox.Show("Failed to export",
string.Format("Failed to export \"{0}\":\n{1}", resourceName, ex.Message),
MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
}
}

private void ListBoxResourceNames_SelectedIndexChanged(object sender, EventArgs e)
{
buttonExport.Enabled = listBoxResourceNames.SelectedItems.Count > 0;
}
}
}
Loading

0 comments on commit bb26f10

Please sign in to comment.