mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-23 17:43:08 -05:00
Separate ResourceFetcher into ResourceFetcher and ResourceChecker.
This commit is contained in:
parent
f05fba36de
commit
a9172905cd
4 changed files with 137 additions and 105 deletions
|
@ -400,6 +400,7 @@ namespace ClassicalSharp.Network {
|
||||||
env.SetWeatherSpeed( value / 256f ); break;
|
env.SetWeatherSpeed( value / 256f ); break;
|
||||||
case 7:
|
case 7:
|
||||||
Utils.Clamp( ref value, byte.MinValue, byte.MaxValue );
|
Utils.Clamp( ref value, byte.MinValue, byte.MaxValue );
|
||||||
|
Console.WriteLine( value );
|
||||||
env.SetWeatherFade( value / 128f ); break;
|
env.SetWeatherFade( value / 128f ); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,6 +91,7 @@
|
||||||
<Compile Include="LauncherWindow.cs" />
|
<Compile Include="LauncherWindow.cs" />
|
||||||
<Compile Include="Patcher\Animations.cs" />
|
<Compile Include="Patcher\Animations.cs" />
|
||||||
<Compile Include="Patcher\BinUnpacker.cs" />
|
<Compile Include="Patcher\BinUnpacker.cs" />
|
||||||
|
<Compile Include="Patcher\ResourceChecker.cs" />
|
||||||
<Compile Include="Patcher\ResourceFetcher.cs" />
|
<Compile Include="Patcher\ResourceFetcher.cs" />
|
||||||
<Compile Include="Patcher\ResourcePatcher.cs" />
|
<Compile Include="Patcher\ResourcePatcher.cs" />
|
||||||
<Compile Include="Patcher\SoundPatcher.cs" />
|
<Compile Include="Patcher\SoundPatcher.cs" />
|
||||||
|
|
95
Launcher2/Patcher/ResourceChecker.cs
Normal file
95
Launcher2/Patcher/ResourceChecker.cs
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using ClassicalSharp.TexturePack;
|
||||||
|
|
||||||
|
namespace Launcher {
|
||||||
|
|
||||||
|
public sealed class ResourceChecker {
|
||||||
|
|
||||||
|
public void CheckResourceExistence() {
|
||||||
|
string audioPath = Path.Combine( Program.AppDirectory, "audio" );
|
||||||
|
if( !Directory.Exists( audioPath ) )
|
||||||
|
Directory.CreateDirectory( audioPath );
|
||||||
|
AllResourcesExist = CheckSoundsExist();
|
||||||
|
|
||||||
|
string texDir = Path.Combine( Program.AppDirectory, "texpacks" );
|
||||||
|
string zipPath = Path.Combine( texDir, "default.zip" );
|
||||||
|
defaultZipExists = File.Exists( zipPath );
|
||||||
|
if( defaultZipExists )
|
||||||
|
CheckClassicGuiPng( zipPath );
|
||||||
|
if( !defaultZipExists ) {
|
||||||
|
// classic.jar + 1.6.2.jar + terrain-patch.png + gui.png
|
||||||
|
DownloadSize += (291 + 4621 + 7 + 21) / 1024f;
|
||||||
|
ResourcesCount += 4;
|
||||||
|
AllResourcesExist = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for( int i = 0; i < musicFiles.Length; i++ ) {
|
||||||
|
string file = Path.Combine( audioPath, musicFiles[i] + ".ogg" );
|
||||||
|
musicExists[i] = File.Exists( file );
|
||||||
|
if( !musicExists[i] ) {
|
||||||
|
DownloadSize += musicSizes[i] / 1024f;
|
||||||
|
ResourcesCount++;
|
||||||
|
AllResourcesExist = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ResourcesCount += digSounds.Length;
|
||||||
|
DownloadSize += 173 / 1024f;
|
||||||
|
ResourcesCount += stepSounds.Length;
|
||||||
|
DownloadSize += 244 / 1024f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AllResourcesExist;
|
||||||
|
public float DownloadSize;
|
||||||
|
public int ResourcesCount;
|
||||||
|
internal bool[] musicExists = new bool[7];
|
||||||
|
internal bool classicGuiPngExists, defaultZipExists;
|
||||||
|
|
||||||
|
void CheckClassicGuiPng( string path ) {
|
||||||
|
ZipReader reader = new ZipReader();
|
||||||
|
reader.ShouldProcessZipEntry = ShouldProcessZipEntry;
|
||||||
|
reader.ProcessZipEntry = ProcessZipEntry;
|
||||||
|
|
||||||
|
using( Stream src = new FileStream( path, FileMode.Open, FileAccess.Read ) )
|
||||||
|
reader.Extract( src );
|
||||||
|
if( !classicGuiPngExists )
|
||||||
|
defaultZipExists = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ShouldProcessZipEntry( string filename ) {
|
||||||
|
if( filename == "gui_classic.png" )
|
||||||
|
classicGuiPngExists = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProcessZipEntry( string filename, byte[] data, ZipEntry entry ) { }
|
||||||
|
|
||||||
|
bool CheckSoundsExist() {
|
||||||
|
string path = Path.Combine( Program.AppDirectory, "audio" );
|
||||||
|
for( int i = 0; i < digSounds.Length; i++ ) {
|
||||||
|
string file = "dig_" + digSounds[i].Substring( 1 ) + ".wav";
|
||||||
|
if( !File.Exists( Path.Combine( path, file ) ) ) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for( int i = 0; i < stepSounds.Length; i++ ) {
|
||||||
|
string file = "step_" + stepSounds[i].Substring( 1 ) + ".wav";
|
||||||
|
if( !File.Exists( Path.Combine( path, file ) ) ) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static string[] digSounds = new [] { "Acloth1", "Acloth2", "Acloth3", "Acloth4", "Bglass1",
|
||||||
|
"Bglass2", "Bglass3", "Agrass1", "Agrass2", "Agrass3", "Agrass4", "Agravel1", "Agravel2",
|
||||||
|
"Agravel3", "Agravel4", "Asand1", "Asand2", "Asand3", "Asand4", "Asnow1", "Asnow2", "Asnow3",
|
||||||
|
"Asnow4", "Astone1", "Astone2", "Astone3", "Astone4", "Awood1", "Awood2", "Awood3", "Awood4" };
|
||||||
|
|
||||||
|
internal static string[] stepSounds = new [] { "Acloth1", "Acloth2", "Acloth3", "Acloth4", "Bgrass1",
|
||||||
|
"Bgrass2", "Bgrass3", "Bgrass4", "Agravel1", "Agravel2", "Agravel3", "Agravel4", "Asand1",
|
||||||
|
"Asand2", "Asand3", "Asand4", "Asnow1", "Asnow2", "Asnow3", "Asnow4", "Astone1", "Astone2",
|
||||||
|
"Astone3", "Astone4", "Awood1", "Awood2", "Awood3", "Awood4" };
|
||||||
|
|
||||||
|
internal static string[] musicFiles = new [] { "calm1", "calm2", "calm3", "hal1", "hal2", "hal3", "hal4" };
|
||||||
|
static int[] musicSizes = new [] { 2472, 1931, 2181, 1926, 1714, 1879, 2499 };
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,9 +26,9 @@ namespace Launcher {
|
||||||
public void DownloadItems( AsyncDownloader downloader, Action<string> setStatus ) {
|
public void DownloadItems( AsyncDownloader downloader, Action<string> setStatus ) {
|
||||||
this.downloader = downloader;
|
this.downloader = downloader;
|
||||||
DownloadMusicFiles();
|
DownloadMusicFiles();
|
||||||
digPatcher = new SoundPatcher( digSounds, "dig_", "step_cloth1" );
|
digPatcher = new SoundPatcher( ResourceChecker.digSounds, "dig_", "step_cloth1" );
|
||||||
digPatcher.FetchFiles( digSoundsUri, altDigSoundsUri, this );
|
digPatcher.FetchFiles( digSoundsUri, altDigSoundsUri, this );
|
||||||
stepPatcher = new SoundPatcher( stepSounds, "step_", "classic jar" );
|
stepPatcher = new SoundPatcher( ResourceChecker.stepSounds, "step_", "classic jar" );
|
||||||
stepPatcher.FetchFiles( stepSoundsUri, altStepSoundsUri, this );
|
stepPatcher.FetchFiles( stepSoundsUri, altStepSoundsUri, this );
|
||||||
if( !defaultZipExists ) {
|
if( !defaultZipExists ) {
|
||||||
downloader.DownloadData( jarClassicUri, false, "classic_jar" );
|
downloader.DownloadData( jarClassicUri, false, "classic_jar" );
|
||||||
|
@ -39,15 +39,26 @@ namespace Launcher {
|
||||||
SetFirstStatus( setStatus );
|
SetFirstStatus( setStatus );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DownloadMusicFiles() {
|
||||||
|
string[] files = ResourceChecker.musicFiles;
|
||||||
|
for( int i = 0; i < files.Length; i++ ) {
|
||||||
|
if( musicExists[i] ) continue;
|
||||||
|
string baseUri = i < 3 ? musicUri : newMusicUri;
|
||||||
|
string url = baseUri + files[i] + ".ogg";
|
||||||
|
downloader.DownloadData( url, false, files[i] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SetFirstStatus( Action<string> setStatus ) {
|
void SetFirstStatus( Action<string> setStatus ) {
|
||||||
for( int i = 0; i < musicExists.Length; i++ ) {
|
for( int i = 0; i < musicExists.Length; i++ ) {
|
||||||
if( musicExists[i] ) continue;
|
if( musicExists[i] ) continue;
|
||||||
setStatus( MakeNext( musicFiles[i] ) );
|
setStatus( MakeNext( ResourceChecker.musicFiles[i] ) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setStatus( MakeNext( "dig_cloth1" ) );
|
setStatus( MakeNext( "dig_cloth1" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal byte[] jarClassic, jar162, pngTerrainPatch, pngGuiPatch;
|
internal byte[] jarClassic, jar162, pngTerrainPatch, pngGuiPatch;
|
||||||
public bool Check( Action<string> setStatus ) {
|
public bool Check( Action<string> setStatus ) {
|
||||||
if( Done ) return true;
|
if( Done ) return true;
|
||||||
|
@ -59,17 +70,17 @@ namespace Launcher {
|
||||||
if( !stepPatcher.CheckDownloaded( this, setStatus ) )
|
if( !stepPatcher.CheckDownloaded( this, setStatus ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( !DownloadItem( "classic_jar", "classic jar",
|
if( !Download( "classic_jar", "classic jar",
|
||||||
"1.6.2 jar", ref jarClassic, setStatus ) )
|
"1.6.2 jar", ref jarClassic, setStatus ) )
|
||||||
return false;
|
return false;
|
||||||
if( !DownloadItem( "162_jar", "1.6.2 jar",
|
if( !Download( "162_jar", "1.6.2 jar",
|
||||||
"terrain patch", ref jar162, setStatus ) )
|
"terrain patch", ref jar162, setStatus ) )
|
||||||
return false;
|
return false;
|
||||||
if( !DownloadItem( "terrain_patch", "terrain.png patch",
|
if( !Download( "terrain_patch", "terrain.png patch",
|
||||||
"gui", ref pngTerrainPatch, setStatus ) )
|
"gui", ref pngTerrainPatch, setStatus ) )
|
||||||
return false;
|
return false;
|
||||||
if( !DownloadItem( "gui_patch", "gui.png patch",
|
if( !Download( "gui_patch", "gui.png patch",
|
||||||
null, ref pngGuiPatch, setStatus ) )
|
null, ref pngGuiPatch, setStatus ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool done = !defaultZipExists ? pngGuiPatch != null :
|
bool done = !defaultZipExists ? pngGuiPatch != null :
|
||||||
|
@ -81,8 +92,8 @@ namespace Launcher {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DownloadItem( string identifier, string name, string next,
|
bool Download( string identifier, string name, string next,
|
||||||
ref byte[] data, Action<string> setStatus ) {
|
ref byte[] data, Action<string> setStatus ) {
|
||||||
DownloadedItem item;
|
DownloadedItem item;
|
||||||
if( downloader.TryGetItem( identifier, out item ) ) {
|
if( downloader.TryGetItem( identifier, out item ) ) {
|
||||||
Console.WriteLine( "got resource " + identifier );
|
Console.WriteLine( "got resource " + identifier );
|
||||||
|
@ -101,42 +112,6 @@ namespace Launcher {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CheckResourceExistence() {
|
|
||||||
string audioPath = Path.Combine( Program.AppDirectory, "audio" );
|
|
||||||
if( !Directory.Exists( audioPath ) )
|
|
||||||
Directory.CreateDirectory( audioPath );
|
|
||||||
AllResourcesExist = CheckSoundsExist();
|
|
||||||
|
|
||||||
string texDir = Path.Combine( Program.AppDirectory, "texpacks" );
|
|
||||||
string zipPath = Path.Combine( texDir, "default.zip" );
|
|
||||||
defaultZipExists = File.Exists( zipPath );
|
|
||||||
if( defaultZipExists )
|
|
||||||
CheckClassicGuiPng( zipPath );
|
|
||||||
if( !defaultZipExists ) {
|
|
||||||
// classic.jar + 1.6.2.jar + terrain-patch.png + gui.png
|
|
||||||
DownloadSize += (291 + 4621 + 7 + 21) / 1024f;
|
|
||||||
ResourcesCount += 4;
|
|
||||||
AllResourcesExist = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for( int i = 0; i < musicFiles.Length; i++ ) {
|
|
||||||
string file = Path.Combine( audioPath, musicFiles[i] + ".ogg" );
|
|
||||||
musicExists[i] = File.Exists( file );
|
|
||||||
if( !musicExists[i] ) {
|
|
||||||
DownloadSize += musicSizes[i] / 1024f;
|
|
||||||
ResourcesCount++;
|
|
||||||
AllResourcesExist = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ResourcesCount += digSounds.Length;
|
|
||||||
DownloadSize += 173 / 1024f;
|
|
||||||
ResourcesCount += stepSounds.Length;
|
|
||||||
DownloadSize += 244 / 1024f;
|
|
||||||
}
|
|
||||||
public bool AllResourcesExist;
|
|
||||||
public float DownloadSize;
|
|
||||||
public int ResourcesCount, CurrentResource;
|
|
||||||
|
|
||||||
const string lineFormat = "&eFetching {0}.. ({1}/{2})";
|
const string lineFormat = "&eFetching {0}.. ({1}/{2})";
|
||||||
public string MakeNext( string next ) {
|
public string MakeNext( string next ) {
|
||||||
CurrentResource++;
|
CurrentResource++;
|
||||||
|
@ -144,32 +119,13 @@ namespace Launcher {
|
||||||
CurrentResource, ResourcesCount );
|
CurrentResource, ResourcesCount );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool classicGuiPngExists = false;
|
|
||||||
void CheckClassicGuiPng( string path ) {
|
|
||||||
ZipReader reader = new ZipReader();
|
|
||||||
reader.ShouldProcessZipEntry = ShouldProcessZipEntry;
|
|
||||||
reader.ProcessZipEntry = ProcessZipEntry;
|
|
||||||
|
|
||||||
using( Stream src = new FileStream( path, FileMode.Open, FileAccess.Read ) )
|
|
||||||
reader.Extract( src );
|
|
||||||
if( !classicGuiPngExists )
|
|
||||||
defaultZipExists = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ShouldProcessZipEntry( string filename ) {
|
|
||||||
if( filename == "gui_classic.png" )
|
|
||||||
classicGuiPngExists = true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProcessZipEntry( string filename, byte[] data, ZipEntry entry ) { }
|
|
||||||
|
|
||||||
bool CheckMusicFiles( Action<string> setStatus ) {
|
bool CheckMusicFiles( Action<string> setStatus ) {
|
||||||
for( int i = 0; i < musicFiles.Length; i++ ) {
|
string[] files = ResourceChecker.musicFiles;
|
||||||
string next = i < musicFiles.Length - 1 ? musicFiles[i + 1] : "dig_cloth1";
|
for( int i = 0; i < files.Length; i++ ) {
|
||||||
string name = musicFiles[i];
|
string next = i < files.Length - 1 ? files[i + 1] : "dig_cloth1";
|
||||||
|
string name = files[i];
|
||||||
byte[] data = null;
|
byte[] data = null;
|
||||||
if( !DownloadItem( name, name, next, ref data, setStatus ) )
|
if( !Download( name, name, next, ref data, setStatus ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( data == null ) continue;
|
if( data == null ) continue;
|
||||||
|
@ -180,41 +136,20 @@ namespace Launcher {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadMusicFiles() {
|
public void CheckResourceExistence() {
|
||||||
for( int i = 0; i < musicFiles.Length; i++ ) {
|
ResourceChecker checker = new ResourceChecker();
|
||||||
if( musicExists[i] ) continue;
|
checker.CheckResourceExistence();
|
||||||
string baseUri = i < 3 ? musicUri : newMusicUri;
|
|
||||||
string url = baseUri + musicFiles[i] + ".ogg";
|
|
||||||
downloader.DownloadData( url, false, musicFiles[i] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CheckSoundsExist() {
|
|
||||||
string path = Path.Combine( Program.AppDirectory, "audio" );
|
|
||||||
for( int i = 0; i < digSounds.Length; i++ ) {
|
|
||||||
string file = "dig_" + digSounds[i].Substring( 1 ) + ".wav";
|
|
||||||
if( !File.Exists( Path.Combine( path, file ) ) ) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for( int i = 0; i < stepSounds.Length; i++ ) {
|
AllResourcesExist = checker.AllResourcesExist;
|
||||||
string file = "step_" + stepSounds[i].Substring( 1 ) + ".wav";
|
DownloadSize = checker.DownloadSize;
|
||||||
if( !File.Exists( Path.Combine( path, file ) ) ) return false;
|
ResourcesCount = checker.ResourcesCount;
|
||||||
}
|
musicExists = checker.musicExists;
|
||||||
return true;
|
defaultZipExists = checker.defaultZipExists;
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] digSounds = new [] { "Acloth1", "Acloth2", "Acloth3", "Acloth4", "Bglass1",
|
public bool AllResourcesExist;
|
||||||
"Bglass2", "Bglass3", "Agrass1", "Agrass2", "Agrass3", "Agrass4", "Agravel1", "Agravel2",
|
public float DownloadSize;
|
||||||
"Agravel3", "Agravel4", "Asand1", "Asand2", "Asand3", "Asand4", "Asnow1", "Asnow2", "Asnow3",
|
public int ResourcesCount, CurrentResource;
|
||||||
"Asnow4", "Astone1", "Astone2", "Astone3", "Astone4", "Awood1", "Awood2", "Awood3", "Awood4" };
|
|
||||||
|
|
||||||
string[] stepSounds = new [] { "Acloth1", "Acloth2", "Acloth3", "Acloth4", "Bgrass1",
|
|
||||||
"Bgrass2", "Bgrass3", "Bgrass4", "Agravel1", "Agravel2", "Agravel3", "Agravel4", "Asand1",
|
|
||||||
"Asand2", "Asand3", "Asand4", "Asnow1", "Asnow2", "Asnow3", "Asnow4", "Astone1", "Astone2",
|
|
||||||
"Astone3", "Astone4", "Awood1", "Awood2", "Awood3", "Awood4" };
|
|
||||||
|
|
||||||
string[] musicFiles = new [] { "calm1", "calm2", "calm3", "hal1", "hal2", "hal3", "hal4" };
|
|
||||||
int[] musicSizes = new [] { 2472, 1931, 2181, 1926, 1714, 1879, 2499 };
|
|
||||||
bool[] musicExists = new bool[7];
|
bool[] musicExists = new bool[7];
|
||||||
internal bool defaultZipExists;
|
internal bool defaultZipExists;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue