mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -04:00
Move texture packs and map files into their own sub-directories.
This commit is contained in:
parent
750eeae6be
commit
1bb4b9d99b
@ -7,9 +7,9 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
public LoadLevelScreen( Game game ) : base( game ) {
|
public LoadLevelScreen( Game game ) : base( game ) {
|
||||||
titleText = "Select a level";
|
titleText = "Select a level";
|
||||||
string dir = Program.AppDirectory;
|
string dir = Path.Combine( Program.AppDirectory, "maps" );
|
||||||
string[] cwFiles = Directory.GetFiles( dir, "*.cw", SearchOption.AllDirectories );
|
string[] cwFiles = Directory.GetFiles( dir, "*.cw" );
|
||||||
string[] datFiles = Directory.GetFiles( dir, "*.dat", SearchOption.AllDirectories );
|
string[] datFiles = Directory.GetFiles( dir, "*.dat" );
|
||||||
files = new string[cwFiles.Length + datFiles.Length];
|
files = new string[cwFiles.Length + datFiles.Length];
|
||||||
Array.Copy( cwFiles, 0, files, 0, cwFiles.Length );
|
Array.Copy( cwFiles, 0, files, 0, cwFiles.Length );
|
||||||
Array.Copy( datFiles, 0, files, cwFiles.Length, datFiles.Length );
|
Array.Copy( datFiles, 0, files, cwFiles.Length, datFiles.Length );
|
||||||
|
@ -118,6 +118,7 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
string textPath;
|
string textPath;
|
||||||
void SaveMap( string path ) {
|
void SaveMap( string path ) {
|
||||||
|
path = Path.Combine( "maps", path );
|
||||||
path = Path.Combine( Program.AppDirectory, path );
|
path = Path.Combine( Program.AppDirectory, path );
|
||||||
try {
|
try {
|
||||||
if( File.Exists( path ) )
|
if( File.Exists( path ) )
|
||||||
|
@ -9,8 +9,8 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
public TexturePackScreen( Game game ) : base( game ) {
|
public TexturePackScreen( Game game ) : base( game ) {
|
||||||
titleText = "Select a texture pack zip";
|
titleText = "Select a texture pack zip";
|
||||||
string dir = Program.AppDirectory;
|
string dir = Path.Combine( Program.AppDirectory, TexturePackExtractor.Dir );
|
||||||
files = Directory.GetFiles( dir, "*.zip", SearchOption.AllDirectories );
|
files = Directory.GetFiles( dir, "*.zip" );
|
||||||
|
|
||||||
for( int i = 0; i < files.Length; i++ ) {
|
for( int i = 0; i < files.Length; i++ ) {
|
||||||
string absolutePath = files[i];
|
string absolutePath = files[i];
|
||||||
|
@ -19,7 +19,7 @@ using OpenTK.Input;
|
|||||||
namespace ClassicalSharp {
|
namespace ClassicalSharp {
|
||||||
|
|
||||||
public partial class Game : GameWindow {
|
public partial class Game : GameWindow {
|
||||||
|
|
||||||
void LoadAtlas( Bitmap bmp ) {
|
void LoadAtlas( Bitmap bmp ) {
|
||||||
TerrainAtlas1D.Dispose();
|
TerrainAtlas1D.Dispose();
|
||||||
TerrainAtlas.Dispose();
|
TerrainAtlas.Dispose();
|
||||||
@ -70,7 +70,7 @@ namespace ClassicalSharp {
|
|||||||
Animations = new Animations( this );
|
Animations = new Animations( this );
|
||||||
defTexturePack = Options.Get( OptionsKey.DefaultTexturePack ) ?? "default.zip";
|
defTexturePack = Options.Get( OptionsKey.DefaultTexturePack ) ?? "default.zip";
|
||||||
TexturePackExtractor extractor = new TexturePackExtractor();
|
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
|
// in case the user's default texture pack doesn't have all required textures
|
||||||
if( defTexturePack != "default.zip" )
|
if( defTexturePack != "default.zip" )
|
||||||
extractor.Extract( DefaultTexturePack, this );
|
extractor.Extract( DefaultTexturePack, this );
|
||||||
@ -137,7 +137,7 @@ namespace ClassicalSharp {
|
|||||||
if( File.Exists( launcherPath ) ) {
|
if( File.Exists( launcherPath ) ) {
|
||||||
Icon = Icon.ExtractAssociatedIcon( launcherPath );
|
Icon = Icon.ExtractAssociatedIcon( launcherPath );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
launcherPath = Path.Combine( Program.AppDirectory, "Launcher.exe" );
|
launcherPath = Path.Combine( Program.AppDirectory, "Launcher.exe" );
|
||||||
if( File.Exists( launcherPath ) ) {
|
if( File.Exists( launcherPath ) ) {
|
||||||
Icon = Icon.ExtractAssociatedIcon( launcherPath );
|
Icon = Icon.ExtractAssociatedIcon( launcherPath );
|
||||||
@ -225,7 +225,7 @@ namespace ClassicalSharp {
|
|||||||
const double ticksPeriod = 1.0 / ticksFrequency;
|
const double ticksPeriod = 1.0 / ticksFrequency;
|
||||||
const double imageCheckPeriod = 30.0;
|
const double imageCheckPeriod = 30.0;
|
||||||
const double cameraPeriod = 1.0 / 120;
|
const double cameraPeriod = 1.0 / 120;
|
||||||
double ticksAccumulator, imageCheckAccumulator,
|
double ticksAccumulator, imageCheckAccumulator,
|
||||||
cameraAccumulator;
|
cameraAccumulator;
|
||||||
|
|
||||||
void CheckScheduledTasks( double time ) {
|
void CheckScheduledTasks( double time ) {
|
||||||
@ -384,7 +384,7 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PerformFpsElapsed( double elapsedMs ) {
|
void PerformFpsElapsed( double elapsedMs ) {
|
||||||
limitAcc += elapsedMs;
|
limitAcc += elapsedMs;
|
||||||
if( limitAcc >= limitMilliseconds ) { // going slower than limit?
|
if( limitAcc >= limitMilliseconds ) { // going slower than limit?
|
||||||
limitAcc -= limitMilliseconds;
|
limitAcc -= limitMilliseconds;
|
||||||
} else { // going faster than limit
|
} else { // going faster than limit
|
||||||
@ -441,7 +441,7 @@ namespace ClassicalSharp {
|
|||||||
if( block == 0 ) return false;
|
if( block == 0 ) return false;
|
||||||
if( !BlockInfo.IsLiquid[block] ) return true;
|
if( !BlockInfo.IsLiquid[block] ) return true;
|
||||||
|
|
||||||
return !LiquidsBreakable ? false :
|
return !LiquidsBreakable ? false :
|
||||||
Inventory.CanPlace[block] && Inventory.CanDelete[block];
|
Inventory.CanPlace[block] && Inventory.CanDelete[block];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using ClassicalSharp.TexturePack;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
|
|
||||||
namespace ClassicalSharp {
|
namespace ClassicalSharp {
|
||||||
@ -16,9 +17,11 @@ namespace ClassicalSharp {
|
|||||||
AppDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
AppDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
||||||
string logPath = Path.Combine( AppDirectory, "client.log" );
|
string logPath = Path.Combine( AppDirectory, "client.log" );
|
||||||
ErrorHandler.InstallHandler( logPath );
|
ErrorHandler.InstallHandler( logPath );
|
||||||
|
CleanupMainDirectory();
|
||||||
|
|
||||||
Utils.LogDebug( "Starting " + AppName + ".." );
|
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." );
|
Utils.LogDebug( "default.zip not found. Cannot start." );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -76,5 +79,33 @@ namespace ClassicalSharp {
|
|||||||
game.Run();
|
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 ) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,8 +9,10 @@ namespace ClassicalSharp.TexturePack {
|
|||||||
/// <summary> Extracts resources from a .zip texture pack. </summary>
|
/// <summary> Extracts resources from a .zip texture pack. </summary>
|
||||||
public sealed class TexturePackExtractor {
|
public sealed class TexturePackExtractor {
|
||||||
|
|
||||||
|
public const string Dir = "texpacks";
|
||||||
Game game;
|
Game game;
|
||||||
public void Extract( string path, Game game ) {
|
public void Extract( string path, Game game ) {
|
||||||
|
path = Path.Combine( Dir, path );
|
||||||
path = Path.Combine( Program.AppDirectory, path );
|
path = Path.Combine( Program.AppDirectory, path );
|
||||||
using( Stream fs = new FileStream( path, FileMode.Open, FileAccess.Read, FileShare.Read ) )
|
using( Stream fs = new FileStream( path, FileMode.Open, FileAccess.Read, FileShare.Read ) )
|
||||||
Extract( fs, game );
|
Extract( fs, game );
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using ClassicalSharp.TexturePack;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Input;
|
using OpenTK.Input;
|
||||||
|
|
||||||
@ -118,9 +119,13 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static bool Load() {
|
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 )
|
if( Program.AppDirectory == null )
|
||||||
Program.AppDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
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 {
|
try {
|
||||||
string path = Path.Combine( Program.AppDirectory, OptionsFile );
|
string path = Path.Combine( Program.AppDirectory, OptionsFile );
|
||||||
|
@ -11,11 +11,12 @@ namespace Launcher2 {
|
|||||||
internal void TryLoadTexturePack() {
|
internal void TryLoadTexturePack() {
|
||||||
Options.Load();
|
Options.Load();
|
||||||
LauncherSkin.LoadFromOptions();
|
LauncherSkin.LoadFromOptions();
|
||||||
|
string texDir = Path.Combine( Program.AppDirectory, "texpacks" );
|
||||||
string texPack = Options.Get( OptionsKey.DefaultTexturePack ) ?? "default.zip";
|
string texPack = Options.Get( OptionsKey.DefaultTexturePack ) ?? "default.zip";
|
||||||
texPack = Path.Combine( Program.AppDirectory, texPack );
|
texPack = Path.Combine( texDir, texPack );
|
||||||
|
|
||||||
if( !File.Exists( texPack ) )
|
if( !File.Exists( texPack ) )
|
||||||
texPack = Path.Combine( Program.AppDirectory, "default.zip" );
|
texPack = Path.Combine( texDir, "default.zip" );
|
||||||
if( !File.Exists( texPack ) )
|
if( !File.Exists( texPack ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -112,7 +112,8 @@ namespace Launcher2 {
|
|||||||
AllResourcesExist = File.Exists( digPath + ".bin" )
|
AllResourcesExist = File.Exists( digPath + ".bin" )
|
||||||
&& File.Exists( stepPath + ".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 );
|
defaultZipExists = File.Exists( zipPath );
|
||||||
if( !defaultZipExists ) {
|
if( !defaultZipExists ) {
|
||||||
// classic.jar + 1.6.2.jar + terrain-patch.png + gui.png
|
// classic.jar + 1.6.2.jar + terrain-patch.png + gui.png
|
||||||
|
@ -21,7 +21,8 @@ namespace Launcher2 {
|
|||||||
reader = new ZipReader();
|
reader = new ZipReader();
|
||||||
reader.ShouldProcessZipEntry = ShouldProcessZipEntry_Classic;
|
reader.ShouldProcessZipEntry = ShouldProcessZipEntry_Classic;
|
||||||
reader.ProcessZipEntry = ProcessZipEntry_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 ),
|
using( Stream srcClassic = new MemoryStream( jarClassic ),
|
||||||
srcModern = new MemoryStream( jar162 ),
|
srcModern = new MemoryStream( jar162 ),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user