Move texture packs and map files into their own sub-directories.

This commit is contained in:
UnknownShadow200 2015-12-30 13:54:33 +11:00
parent 750eeae6be
commit 1bb4b9d99b
10 changed files with 59 additions and 17 deletions

View File

@ -7,9 +7,9 @@ namespace ClassicalSharp {
public LoadLevelScreen( Game game ) : base( game ) {
titleText = "Select a level";
string dir = Program.AppDirectory;
string[] cwFiles = Directory.GetFiles( dir, "*.cw", SearchOption.AllDirectories );
string[] datFiles = Directory.GetFiles( dir, "*.dat", SearchOption.AllDirectories );
string dir = Path.Combine( Program.AppDirectory, "maps" );
string[] cwFiles = Directory.GetFiles( dir, "*.cw" );
string[] datFiles = Directory.GetFiles( dir, "*.dat" );
files = new string[cwFiles.Length + datFiles.Length];
Array.Copy( cwFiles, 0, files, 0, cwFiles.Length );
Array.Copy( datFiles, 0, files, cwFiles.Length, datFiles.Length );

View File

@ -118,6 +118,7 @@ namespace ClassicalSharp {
string textPath;
void SaveMap( string path ) {
path = Path.Combine( "maps", path );
path = Path.Combine( Program.AppDirectory, path );
try {
if( File.Exists( path ) )

View File

@ -9,8 +9,8 @@ namespace ClassicalSharp {
public TexturePackScreen( Game game ) : base( game ) {
titleText = "Select a texture pack zip";
string dir = Program.AppDirectory;
files = Directory.GetFiles( dir, "*.zip", SearchOption.AllDirectories );
string dir = Path.Combine( Program.AppDirectory, TexturePackExtractor.Dir );
files = Directory.GetFiles( dir, "*.zip" );
for( int i = 0; i < files.Length; i++ ) {
string absolutePath = files[i];

View File

@ -19,7 +19,7 @@ using OpenTK.Input;
namespace ClassicalSharp {
public partial class Game : GameWindow {
void LoadAtlas( Bitmap bmp ) {
TerrainAtlas1D.Dispose();
TerrainAtlas.Dispose();
@ -70,7 +70,7 @@ namespace ClassicalSharp {
Animations = new Animations( this );
defTexturePack = Options.Get( OptionsKey.DefaultTexturePack ) ?? "default.zip";
TexturePackExtractor extractor = new TexturePackExtractor();
extractor.Extract( "default.zip", this );
extractor.Extract( "default.zip", this );
// in case the user's default texture pack doesn't have all required textures
if( defTexturePack != "default.zip" )
extractor.Extract( DefaultTexturePack, this );
@ -137,7 +137,7 @@ namespace ClassicalSharp {
if( File.Exists( launcherPath ) ) {
Icon = Icon.ExtractAssociatedIcon( launcherPath );
return;
}
}
launcherPath = Path.Combine( Program.AppDirectory, "Launcher.exe" );
if( File.Exists( launcherPath ) ) {
Icon = Icon.ExtractAssociatedIcon( launcherPath );
@ -225,7 +225,7 @@ namespace ClassicalSharp {
const double ticksPeriod = 1.0 / ticksFrequency;
const double imageCheckPeriod = 30.0;
const double cameraPeriod = 1.0 / 120;
double ticksAccumulator, imageCheckAccumulator,
double ticksAccumulator, imageCheckAccumulator,
cameraAccumulator;
void CheckScheduledTasks( double time ) {
@ -384,7 +384,7 @@ namespace ClassicalSharp {
}
void PerformFpsElapsed( double elapsedMs ) {
limitAcc += elapsedMs;
limitAcc += elapsedMs;
if( limitAcc >= limitMilliseconds ) { // going slower than limit?
limitAcc -= limitMilliseconds;
} else { // going faster than limit
@ -441,7 +441,7 @@ namespace ClassicalSharp {
if( block == 0 ) return false;
if( !BlockInfo.IsLiquid[block] ) return true;
return !LiquidsBreakable ? false :
return !LiquidsBreakable ? false :
Inventory.CanPlace[block] && Inventory.CanDelete[block];
}

View File

@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Net;
using ClassicalSharp.TexturePack;
using OpenTK;
namespace ClassicalSharp {
@ -16,9 +17,11 @@ namespace ClassicalSharp {
AppDirectory = AppDomain.CurrentDomain.BaseDirectory;
string logPath = Path.Combine( AppDirectory, "client.log" );
ErrorHandler.InstallHandler( logPath );
CleanupMainDirectory();
Utils.LogDebug( "Starting " + AppName + ".." );
if( !File.Exists( Path.Combine( AppDirectory, "default.zip" ) ) ) {
string path = Path.Combine( Program.AppDirectory, TexturePackExtractor.Dir );
if( !File.Exists( Path.Combine( path, "default.zip" ) ) ) {
Utils.LogDebug( "default.zip not found. Cannot start." );
return;
}
@ -76,5 +79,33 @@ namespace ClassicalSharp {
game.Run();
}
}
internal static void CleanupMainDirectory() {
string mapPath = Path.Combine( Program.AppDirectory, "maps" );
if( !Directory.Exists( mapPath ) )
Directory.CreateDirectory( mapPath );
string texPath = Path.Combine( Program.AppDirectory, TexturePackExtractor.Dir );
if( !Directory.Exists( texPath ) )
Directory.CreateDirectory( texPath );
CopyFiles( "*.cw", mapPath );
CopyFiles( "*.dat", mapPath );
CopyFiles( "*.zip", texPath );
}
static void CopyFiles( string filter, string folder ) {
string[] files = Directory.GetFiles( AppDirectory, filter );
for( int i = 0; i < files.Length; i++ ) {
string name = Path.GetFileName( files[i] );
string dst = Path.Combine( folder, name );
if( File.Exists( dst ) )
continue;
try {
File.Copy( files[i], dst );
File.Delete( files[i] );
} catch( IOException ex ) {
}
}
}
}
}

View File

@ -9,8 +9,10 @@ namespace ClassicalSharp.TexturePack {
/// <summary> Extracts resources from a .zip texture pack. </summary>
public sealed class TexturePackExtractor {
public const string Dir = "texpacks";
Game game;
public void Extract( string path, Game game ) {
path = Path.Combine( Dir, path );
path = Path.Combine( Program.AppDirectory, path );
using( Stream fs = new FileStream( path, FileMode.Open, FileAccess.Read, FileShare.Read ) )
Extract( fs, game );

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using ClassicalSharp.TexturePack;
using OpenTK;
using OpenTK.Input;
@ -118,9 +119,13 @@ namespace ClassicalSharp {
}
public static bool Load() {
// i.e. when running from the launcher
// Both of these are from when running from the launcher
if( Program.AppDirectory == null )
Program.AppDirectory = AppDomain.CurrentDomain.BaseDirectory;
string defZip = Path.Combine( Program.AppDirectory, "default.zip" );
string texDir = Path.Combine( Program.AppDirectory, TexturePackExtractor.Dir );
if( File.Exists( defZip ) || !Directory.Exists( texDir ) )
Program.CleanupMainDirectory();
try {
string path = Path.Combine( Program.AppDirectory, OptionsFile );

View File

@ -11,11 +11,12 @@ namespace Launcher2 {
internal void TryLoadTexturePack() {
Options.Load();
LauncherSkin.LoadFromOptions();
string texDir = Path.Combine( Program.AppDirectory, "texpacks" );
string texPack = Options.Get( OptionsKey.DefaultTexturePack ) ?? "default.zip";
texPack = Path.Combine( Program.AppDirectory, texPack );
texPack = Path.Combine( texDir, texPack );
if( !File.Exists( texPack ) )
texPack = Path.Combine( Program.AppDirectory, "default.zip" );
texPack = Path.Combine( texDir, "default.zip" );
if( !File.Exists( texPack ) )
return;

View File

@ -112,7 +112,8 @@ namespace Launcher2 {
AllResourcesExist = File.Exists( digPath + ".bin" )
&& File.Exists( stepPath + ".bin" );
string zipPath = Path.Combine( Program.AppDirectory, "default.zip" );
string texDir = Path.Combine( Program.AppDirectory, "texpacks" );
string zipPath = Path.Combine( texDir, "default.zip" );
defaultZipExists = File.Exists( zipPath );
if( !defaultZipExists ) {
// classic.jar + 1.6.2.jar + terrain-patch.png + gui.png

View File

@ -21,7 +21,8 @@ namespace Launcher2 {
reader = new ZipReader();
reader.ShouldProcessZipEntry = ShouldProcessZipEntry_Classic;
reader.ProcessZipEntry = ProcessZipEntry_Classic;
string path = Path.Combine( Program.AppDirectory, "default.zip" );
string texDir = Path.Combine( Program.AppDirectory, "texpacks" );
string path = Path.Combine( texDir, "default.zip" );
using( Stream srcClassic = new MemoryStream( jarClassic ),
srcModern = new MemoryStream( jar162 ),