Skip to content

Commit

Permalink
First Release
Browse files Browse the repository at this point in the history
  • Loading branch information
electro-logic committed Jul 7, 2023
1 parent c3dc0d3 commit 0be2f3a
Show file tree
Hide file tree
Showing 6 changed files with 270 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.8" />
</startup>
</configuration>
54 changes: 54 additions & 0 deletions HoloArchiver.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?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>{C5541BC5-0598-468A-8AEE-CCC0474AC184}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>HoloArchiver</RootNamespace>
<AssemblyName>HoloArchiver</AssemblyName>
<TargetFrameworkVersion>v4.8</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.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SimpleArchive.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
25 changes: 25 additions & 0 deletions HoloArchiver.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 Version 17
VisualStudioVersion = 17.6.33815.320
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HoloArchiver", "HoloArchiver.csproj", "{C5541BC5-0598-468A-8AEE-CCC0474AC184}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C5541BC5-0598-468A-8AEE-CCC0474AC184}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C5541BC5-0598-468A-8AEE-CCC0474AC184}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C5541BC5-0598-468A-8AEE-CCC0474AC184}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C5541BC5-0598-468A-8AEE-CCC0474AC184}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {02631467-B18E-49AE-AB66-A77CA11187E6}
EndGlobalSection
EndGlobal
36 changes: 36 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.IO;
using System.Linq;

namespace HoloArchiver
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("HoloArchiver v1.0");
if (args.Length != 1)
{
Console.WriteLine("usage: h3d.exe file.h3d");
Console.ReadLine();
return;
}
string file = args[0];
string fileName = Path.GetFileNameWithoutExtension(file);
using (var archive = SimpleArchive.OpenOrCreate(file))
{
if (args.Length == 1)
{
Directory.CreateDirectory(fileName);
foreach (var entryName in archive.GetEntryNames())
{
Console.WriteLine(entryName);
File.WriteAllBytes(fileName + "\\" + entryName, archive.GetEntry(entryName));
}
Console.WriteLine("All files extracted.");
}
}
Console.ReadLine();
}
}
}
36 changes: 36 additions & 0 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("HoloArchiver")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HoloArchiver")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("c5541bc5-0598-468a-8aee-ccc0474ac184")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
113 changes: 113 additions & 0 deletions SimpleArchive.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.IO;

namespace HoloArchiver
{
public class SimpleArchive : IDisposable
{
Dictionary<string, long> _index = new Dictionary<string, long>();
Stream _fileStream;
BufferedStream _buffer;
BinaryWriter _fileWriter;
BinaryReader _fileReader;
bool _isDisposing;
private SimpleArchive() { }
public static SimpleArchive OpenOrCreate(Stream stream)
{
var instance = new SimpleArchive();
instance._fileStream = stream;
instance._buffer = new BufferedStream(instance._fileStream, 1024 * 1024);
instance._fileReader = new BinaryReader(instance._buffer);
if (stream.CanWrite)
{
instance._fileWriter = new BinaryWriter(instance._buffer);
}
return instance;
}
public static SimpleArchive OpenOrCreate(string fileName)
{
return OpenOrCreate(File.Open(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read));
}
// GetNextEntry will start again from zero
public void Flush()
{
lock (this)
{
_buffer.Flush();
_fileStream.Flush();
_buffer.Position = 0;
}
}
public byte[] GetEntry(string name)
{
lock (this)
{
if (_index.ContainsKey(name))
{
_buffer.Position = _index[name];
}
else
{
_buffer.Position = 0;
}
return GetNextEntry(name);
}
}
byte[] GetNextEntry(string name)
{
lock (this)
{
while (_buffer.Position < _buffer.Length)
{
string entryName = _fileReader.ReadString();
UInt32 lenght = _fileReader.ReadUInt32();
if (name == entryName)
{
return _fileReader.ReadBytes((int)lenght);
}
_buffer.Position += lenght;
}
return null;
//throw new Exception("Entry not found");
}
}
public IReadOnlyList<string> GetEntryNames()
{
lock (this)
{
var names = new List<string>();
_buffer.Position = 0;
while (_buffer.Position < _buffer.Length)
{
long offset = _buffer.Position;
string entryName = _fileReader.ReadString();
UInt32 lenght = _fileReader.ReadUInt32();
_index.Add(entryName, offset);
names.Add(entryName);
_buffer.Position += lenght;
}
return names;
}
}
protected virtual void Dispose(bool disposing)
{
if (!_isDisposing)
{
if (disposing)
{
_fileWriter?.Close();
_fileReader?.Close();
_buffer?.Close();
_fileStream?.Close();
}
_isDisposing = true;
}
}
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}

0 comments on commit 0be2f3a

Please sign in to comment.