Quellcode durchsuchen

fixed seek for pak build extract

Nicolas Cannasse vor 5 Jahren
Ursprung
Commit
37414f0189
2 geänderte Dateien mit 18 neuen und 16 gelöschten Zeilen
  1. 1 2
      hxd/fmt/pak/Build.hx
  2. 17 14
      hxd/fmt/pak/FileSystem.hx

+ 1 - 2
hxd/fmt/pak/Build.hx

@@ -190,8 +190,7 @@ class Build {
 						for( c in f.content )
 						for( c in f.content )
 							extractRec(c,dir);
 							extractRec(c,dir);
 					} else {
 					} else {
-						// todo : seek large
-						fs.seek(Std.int(f.dataPosition+pak.headerSize), SeekBegin);
+						hxd.fmt.pak.FileSystem.FileSeek.seek(fs,f.dataPosition+pak.headerSize,SeekBegin);
 						sys.io.File.saveBytes(dir+"/"+f.name,fs.read(f.dataSize));
 						sys.io.File.saveBytes(dir+"/"+f.name,fs.read(f.dataSize));
 					}
 					}
 				}
 				}

+ 17 - 14
hxd/fmt/pak/FileSystem.hx

@@ -25,6 +25,22 @@ class FileInput extends haxe.io.BytesInput {
 }
 }
 #end
 #end
 
 
+class FileSeek {
+	#if (hl && hl_ver >= version("1.12.0"))
+	@:hlNative("std","file_seek2") static function seek2( f : sys.io.File.FileHandle, pos : Float, cur : Int ) : Bool { return false; }
+	#end
+	
+	public static function seek( f : sys.io.FileInput, pos : Float, mode : sys.io.FileSeek ) {
+		#if (hl && hl_ver >= version("1.12.0"))
+		if( !seek2(@:privateAccess f.__f,pos,mode.getIndex()) )
+			throw haxe.io.Error.Custom("seek2 failure()");
+		#else
+		if( pos > 0x7FFFFFFF ) throw haxe.io.Error.Custom("seek out of bounds");
+		f.seek(Std.int(pos),mode);
+		#end
+	}
+}
+
 @:allow(hxd.fmt.pak.FileSystem)
 @:allow(hxd.fmt.pak.FileSystem)
 @:access(hxd.fmt.pak.FileSystem)
 @:access(hxd.fmt.pak.FileSystem)
 private class PakEntry extends FileEntry {
 private class PakEntry extends FileEntry {
@@ -60,21 +76,8 @@ private class PakEntry extends FileEntry {
 		return file.isDirectory;
 		return file.isDirectory;
 	}
 	}
 
 
-	#if (hl && hl_ver >= version("1.12.0"))
-	@:hlNative("std","file_seek2") static function seek2( f : sys.io.File.FileHandle, pos : Float, cur : Int ) : Bool { return false; }
-	#end
-
 	function setPos() {
 	function setPos() {
-		if( file.dataPosition > 0x7FFFFFFF ) {
-			#if (hl && hl_ver >= version("1.12.0"))
-			if( !seek2(@:privateAccess pak.__f,file.dataPosition,0) )
-				throw haxe.io.Error.Custom("seek() failure");
-			#else
-			throw "PAK file is too large: max 2GB or compile with -D hl_ver=1.12.0";
-			#end
-			return;
-		}
-		pak.seek(Std.int(file.dataPosition), SeekBegin);
+		FileSeek.seek(pak,file.dataPosition, SeekBegin);
 	}
 	}
 
 
 	override function getSign() {
 	override function getSign() {