//Thread responsável pela compilação de sprites para as versões entre 7.0 e 9.54 private void compileTo70() { //Declarando variaveis bool wrongVersion = false, cantReadSignature = false; UInt16 quantidade_de_sprites = 0; Image spr; //lendo assinatura try { setLog("Reading signature..."); assinatura.fromFile(compilar_onde); readSignature = assinatura.get(); } catch { cantReadSignature = true; } try { setLog("Reading sprite number..."); quantidade_de_sprites = Conversor.UInt32_to_UInt16(compilar_onde.getSprites()); } catch { wrongVersion = true; } if (wrongVersion == true) { setLog("Unable to read all the sprites"); setLog("The maximum supported sprites for a compilation between versions 7.0 and 9.54 is 65535 images."); setLog("Operation aborted..."); } else if (cantReadSignature == true) { setLog("Error while trying to read signature."); setLog("Operation aborted..."); } else { //organizando as variaveis para começar a leitura setLog("[0%] 0 sprites from " + quantidade_de_sprites.ToString()); compiling = new BinaryWriter(new FileStream(compilar_para_onde.getPath() + "\\virtual_memory.bin", FileMode.Create)); offset = new UInt32[quantidade_de_sprites]; offset[0] = Conversor.Int32_to_UInt32((quantidade_de_sprites * 4) + 6); compiledSprite = new byte[quantidade_de_sprites + 1]; //lendo as sprites aqui e criando as offsets for (int i = 1; i <= quantidade_de_sprites; i++) { lastLog("[" + percent(i, quantidade_de_sprites).ToString() + "%] " + i.ToString() + " sprites from " + quantidade_de_sprites.ToString()); spr = Image.FromFile(compilar_onde.getPath() + "\\s" + i.ToString() + ".bmp"); compiledSprite = sc70.CompileImg(spr); if (i != quantidade_de_sprites) { offset[i] = Conversor.UInt32_add(offset[i - 1], compiledSprite.Length); } compiling.Write(compiledSprite); } compiling.Flush(); compiling.Close(); compiling = null; //criando o arquivo .spr setLog("Concluding compilation..."); string file_name = compilar_para_onde.generateFileName(); compiled = new BinaryWriter(new FileStream(file_name, FileMode.Create)); compiled.Write(readSignature); compiled.Write(Conversor.UInt16_to_Byte(quantidade_de_sprites)); for (int i = 0; i < quantidade_de_sprites; i++) { compiled.Write(Conversor.UInt32_to_Byte(offset[i])); } get_bin_file_from_virtual_memory = new BinaryReader(File.OpenRead(compilar_para_onde.getPath() + "\\virtual_memory.bin")); get_bin_file_from_virtual_memory.BaseStream.Position = 0; compiled.Write(get_bin_file_from_virtual_memory.ReadBytes(Conversor.Int64_to_Int32(get_bin_file_from_virtual_memory.BaseStream.Length))); //Encerrando get_bin_file_from_virtual_memory.Close(); get_bin_file_from_virtual_memory = null; compiled.Flush(); compiled.Close(); compiled = null; File.Delete(compilar_para_onde.getPath() + "\\virtual_memory.bin"); setLog("File compiled to: " + file_name); setLog("Compilation complete!"); } }
public UInt32 getSprites() { FileInfo[] di = new DirectoryInfo(this.getPath()).GetFiles("*.bmp"); return(Conversor.Int32_to_UInt32(di.Length)); }