-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
96 changed files
with
14,638 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using System; | ||
using System.Drawing; | ||
using System.IO; | ||
|
||
namespace AA2CardEditor | ||
{ | ||
public class AA2Card | ||
{ | ||
private string filePath = ""; | ||
private MemoryStream faceImageStream = null; | ||
private MemoryStream editorFileStream = null; | ||
|
||
public AA2Card() | ||
{ | ||
IsDirty = false; | ||
} | ||
|
||
public string FileName | ||
{ | ||
get | ||
{ | ||
return Path.GetFileName(filePath); | ||
} | ||
} | ||
|
||
public Image FaceImage | ||
{ | ||
get | ||
{ | ||
if (faceImageStream == null) | ||
{ | ||
return null; | ||
} | ||
else | ||
{ | ||
faceImageStream.Seek(0, SeekOrigin.Begin); | ||
return Image.FromStream(faceImageStream); | ||
} | ||
} | ||
} | ||
|
||
public bool IsDirty { get; private set; } | ||
|
||
public void ReadCardFile(String filePath) | ||
{ | ||
// Load the file at the path into a memory stream. | ||
byte[] cardFile = File.ReadAllBytes(filePath); | ||
MemoryStream cardFileStream = new MemoryStream( | ||
cardFile, 0, cardFile.Length, false, true); | ||
|
||
// Try to read a PNG from the card file stream. | ||
MemoryStream faceImageStream = PngFileReader.Read(cardFileStream); | ||
|
||
// Try to read an editor file from the card file stream. | ||
MemoryStream editorFileStream = EditorFileReader.Read(cardFileStream); | ||
|
||
// Success. Update card state and mark card as clean. | ||
this.filePath = filePath; | ||
this.faceImageStream = faceImageStream; | ||
this.editorFileStream = editorFileStream; | ||
this.IsDirty = false; | ||
} | ||
|
||
public void ReplaceFaceImage(String filePath) | ||
{ | ||
// Load the file at the path into a memory stream. | ||
byte[] imageFile = File.ReadAllBytes(filePath); | ||
MemoryStream imageFileStream = new MemoryStream( | ||
imageFile, 0, imageFile.Length, false, true); | ||
|
||
// Try to read a PNG from the image file stream. | ||
MemoryStream faceImageStream = PngFileReader.Read(imageFileStream); | ||
|
||
// Success. Update card state and mark card as dirty. | ||
this.faceImageStream = faceImageStream; | ||
this.IsDirty = true; | ||
} | ||
|
||
public void Save() | ||
{ | ||
Save(filePath); | ||
} | ||
|
||
public void Save(String filePath) | ||
{ | ||
using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write)) | ||
{ | ||
// Copy the face image to the file stream. | ||
faceImageStream.Seek(0, SeekOrigin.Begin); | ||
faceImageStream.CopyTo(fs); | ||
|
||
// Copy the editor file to the file stream. | ||
editorFileStream.Seek(0, SeekOrigin.Begin); | ||
editorFileStream.CopyTo(fs); | ||
|
||
// Update card state and mark card as clean. | ||
this.filePath = filePath; | ||
IsDirty = false; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform> | ||
<ProductVersion>8.0.30703</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{82358432-2268-408F-871D-3664E2B76EEC}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>AA2CardEditor</RootNamespace> | ||
<AssemblyName>AA2CardEditor</AssemblyName> | ||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | ||
<TargetFrameworkProfile>Client</TargetFrameworkProfile> | ||
<FileAlignment>512</FileAlignment> | ||
<PublishUrl>publish\</PublishUrl> | ||
<Install>true</Install> | ||
<InstallFrom>Disk</InstallFrom> | ||
<UpdateEnabled>false</UpdateEnabled> | ||
<UpdateMode>Foreground</UpdateMode> | ||
<UpdateInterval>7</UpdateInterval> | ||
<UpdateIntervalUnits>Days</UpdateIntervalUnits> | ||
<UpdatePeriodically>false</UpdatePeriodically> | ||
<UpdateRequired>false</UpdateRequired> | ||
<MapFileExtensions>true</MapFileExtensions> | ||
<ApplicationRevision>0</ApplicationRevision> | ||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion> | ||
<IsWebBootstrapper>false</IsWebBootstrapper> | ||
<UseApplicationTrust>false</UseApplicationTrust> | ||
<BootstrapperEnabled>true</BootstrapperEnabled> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> | ||
<PlatformTarget>x86</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|x86' "> | ||
<PlatformTarget>x86</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<StartupObject /> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="PresentationCore" /> | ||
<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.Windows.Forms" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="AA2Card.cs" /> | ||
<Compile Include="EditorFileReader.cs" /> | ||
<Compile Include="Form1.cs"> | ||
<SubType>Form</SubType> | ||
</Compile> | ||
<Compile Include="Form1.Designer.cs"> | ||
<DependentUpon>Form1.cs</DependentUpon> | ||
</Compile> | ||
<Compile Include="PngFileReader.cs" /> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="WrappingStream.cs" /> | ||
<EmbeddedResource Include="Form1.resx"> | ||
<DependentUpon>Form1.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> | ||
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client"> | ||
<Visible>False</Visible> | ||
<ProductName>Microsoft .NET Framework 4 Client Profile %28x86 and x64%29</ProductName> | ||
<Install>true</Install> | ||
</BootstrapperPackage> | ||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5"> | ||
<Visible>False</Visible> | ||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName> | ||
<Install>false</Install> | ||
</BootstrapperPackage> | ||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> | ||
<Visible>False</Visible> | ||
<ProductName>.NET Framework 3.5 SP1</ProductName> | ||
<Install>false</Install> | ||
</BootstrapperPackage> | ||
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1"> | ||
<Visible>False</Visible> | ||
<ProductName>Windows Installer 3.1</ProductName> | ||
<Install>true</Install> | ||
</BootstrapperPackage> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Folder Include="NewFolder1\" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace AA2CardEditor | ||
{ | ||
class EditorFileReader | ||
{ | ||
private static readonly byte[] EditorFileSignature = { 0x81, 0x79, 0x83, 0x47, 0x83, 0x66, 0x83, 0x42, | ||
0x83, 0x62, 0x83, 0x67, 0x81, 0x7a, 0x00, 0x00}; | ||
|
||
public static MemoryStream Read(MemoryStream inputStream) | ||
{ | ||
byte[] inputBuffer = inputStream.GetBuffer(); | ||
MemoryStream outputStream = new MemoryStream(); | ||
|
||
using (WrappingStream wrappingStream = new WrappingStream(inputStream)) | ||
using (BinaryReader reader = new BinaryReader(inputStream)) | ||
{ | ||
int editorFileBeginPosition = (int)inputStream.Position; | ||
|
||
// Read the signature and verify that it's equal to the editor signature. | ||
byte[] fileSignature = reader.ReadBytes(EditorFileSignature.Length); | ||
|
||
if (!fileSignature.SequenceEqual(EditorFileSignature)) | ||
{ | ||
throw new Exception("The file does not appear to contain editor data."); | ||
} | ||
|
||
inputStream.Seek(0, SeekOrigin.End); | ||
int editorFileEndPosition = (int)inputStream.Position; | ||
|
||
// Copy the rest of the file. We're assuming it's a valid editor file. | ||
int editorFileLength = editorFileEndPosition - editorFileBeginPosition; | ||
outputStream.Write(inputBuffer, editorFileBeginPosition, editorFileLength); | ||
} | ||
|
||
return outputStream; | ||
} | ||
} | ||
} |
Oops, something went wrong.