Skip to content

Commit

Permalink
zip
Browse files Browse the repository at this point in the history
  • Loading branch information
Max committed Apr 6, 2018
1 parent 5ae97dd commit ed0e246
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 22 deletions.
21 changes: 15 additions & 6 deletions EDEngineer/EDEngineer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Runtime">
<HintPath>Resources\Dll\System.Runtime.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -305,15 +306,24 @@
<Resource Include="Resources\Fonts\eurocaps.ttf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<EmbeddedResource Include="Resources\Data\entryData.json" />
<EmbeddedResource Include="Resources\Data\releaseNotes.json" />
<EmbeddedResource Include="Resources\Data\localization.json" />
<EmbeddedResource Include="Resources\Data\blueprints.json" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<None Include="Resources\Data\entryData.json" />
<None Include="Resources\Data\releaseNotes.json" />
<None Include="Resources\Data\localization.json" />
<None Include="Resources\Data\blueprints.json" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<EmbeddedResource Include="Resources\Data\entryData.json" />
<EmbeddedResource Include="Resources\Data\releaseNotes.json" />
<EmbeddedResource Include="Resources\Data\localization.json" />
<EmbeddedResource Include="Resources\Data\blueprints.json" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\Data.zip" />
<Resource Include="Resources\Images\common.png" />
<Resource Include="Resources\Images\standard.png" />
<Resource Include="Resources\Images\very-common.png" />
Expand Down Expand Up @@ -531,8 +541,7 @@
</PostBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PreBuildEvent>
</PreBuildEvent>
<PreBuildEvent>powershell Compress-Archive -Path '$(ProjectDir)\Resources\Data' -DestinationPath '$(ProjectDir)\Resources\Data.zip' -Force</PreBuildEvent>
</PropertyGroup>
<!-- 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.
Expand Down
69 changes: 53 additions & 16 deletions EDEngineer/Utils/System/IOUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,59 @@ public static string RetrieveLogDirectory(bool forcePickFolder, string currentLo
return logDirectory;
}

static IOUtils()
{
blueprintsJson = ReadResource("blueprints");
releaseNotesJson = ReadResource("releaseNotes");
localizationJson = ReadResource("localization");
entryDatasJson = ReadResource("entryData");
}

public static string ReadResource(string resource)
{
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"EDEngineer.Resources.Data.{resource}.json"))
using (var reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
#if !DEBUG
private static readonly string directory = Path.GetTempPath() + Guid.NewGuid();
#endif
static IOUtils()
{
#if !DEBUG
var zipFile = Path.GetTempPath() + Guid.NewGuid() + ".zip";
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("EDEngineer.Resources.Data.zip"))
{
using (var bw = new FileStream(zipFile, FileMode.Create))
{
while (stream.Position < stream.Length)
{
var bits = new byte[stream.Length];
stream.Read(bits, 0, (int)stream.Length);
bw.Write(bits, 0, (int)stream.Length);
}
}
stream.Close();
}


Directory.CreateDirectory(directory);
global::System.IO.Compression.ZipFile.ExtractToDirectory(zipFile, directory);
File.Delete(zipFile);


blueprintsJson = File.ReadAllText(Path.Combine(directory, "Data", "blueprints.json"));
releaseNotesJson = File.ReadAllText(Path.Combine(directory, "Data", "releaseNotes.json"));
localizationJson = File.ReadAllText(Path.Combine(directory, "Data", "localization.json"));
entryDatasJson = File.ReadAllText(Path.Combine(directory, "Data", "entryData.json"));


Directory.Delete(directory, true);
#else
blueprintsJson = ReadResource("blueprints");
releaseNotesJson = ReadResource("releaseNotes");
localizationJson = ReadResource("localization");
entryDatasJson = ReadResource("entryData");
#endif
}


#if DEBUG
public static string ReadResource(string resource)
{
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"EDEngineer.Resources.Data.{resource}.json"))
using (var reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
#endif

private static readonly string blueprintsJson;
private static readonly string releaseNotesJson;
Expand Down

0 comments on commit ed0e246

Please sign in to comment.