/// <summary> /// Load FileDescriptors that are stored in the given File /// </summary> /// <param name="flname"></param> /// <param name="list">null or the list that should be used to add the Items</param> /// <returns></returns> public static void LoadDescriptorsFromDisk(string flname, PackedFileDescriptors list) { if (list == null) { return; } bool run = WaitingScreen.Running; if (!run) { WaitingScreen.Wait(); } WaitingScreen.UpdateMessage("Load Descriptors From Disk"); //list = new PackedFileDescriptors(); try { if (flname.ToLower().EndsWith("package.xml")) { SimPe.Packages.File pkg = Packages.GeneratableFile.LoadFromStream(XmlPackageReader.OpenExtractedPackage(null, flname)); foreach (Interfaces.Files.IPackedFileDescriptor pfd in pkg.Index) { Interfaces.Files.IPackedFile file = pkg.Read(pfd); pfd.UserData = file.UncompressedData; if (!list.Contains(pfd)) { list.Add(pfd); } } } else if (flname.ToLower().EndsWith(".xml")) { Interfaces.Files.IPackedFileDescriptor pfd = XmlPackageReader.OpenExtractedPackedFile(flname); if (!list.Contains(pfd)) { list.Add(pfd); } } else if (flname.ToLower().EndsWith(".package") || flname.ToLower().EndsWith(".simpedis")) { SimPe.Packages.File pkg = SimPe.Packages.File.LoadFromFile(flname); foreach (Interfaces.Files.IPackedFileDescriptor pfd in pkg.Index) { Interfaces.Files.IPackedFile file = pkg.Read(pfd); pfd.UserData = file.UncompressedData; if (!list.Contains(pfd)) { list.Add(pfd); } } } else { Packages.PackedFileDescriptor pfd = new SimPe.Packages.PackedFileDescriptor(); pfd.Type = 0xffffffff; ToolLoaderItemExt.OpenPackedFile(flname, ref pfd); list.Add(pfd); } } finally { if (!run) { WaitingScreen.Stop(); } } }
/// <summary> /// Open a Packed File and add it to the package /// </summary> /// <param name="filename">Name of the File</param> /// <param name="pfd">Descriptor of the Target File</param> /// <param name="package">The package the Fille sould be added to</param> /// <returns>true if succesfull</returns> public static bool OpenPackedFile(string filename, ref Packages.PackedFileDescriptor pfd) { try { try { if (filename.ToLower().EndsWith(".xml")) { pfd = XmlPackageReader.OpenExtractedPackedFile(filename); filename = System.IO.Path.Combine(pfd.Path, pfd.Filename); } else { string[] part = System.IO.Path.GetFileNameWithoutExtension(filename).Split("-".ToCharArray(), 4); try { pfd.Type = Convert.ToUInt32(part[0].Trim(), 16); pfd.SubType = Convert.ToUInt32(part[1].Trim(), 16); pfd.Group = Convert.ToUInt32(part[2].Trim(), 16); pfd.Instance = Convert.ToUInt32(part[3].Trim(), 16); } catch (Exception) { part = System.IO.Path.GetFileNameWithoutExtension(filename).Split("-".ToCharArray(), 5); try { pfd.Type = Convert.ToUInt32(part[0].Trim(), 16); pfd.SubType = Convert.ToUInt32(part[2].Trim(), 16); pfd.Group = Convert.ToUInt32(part[3].Trim(), 16); pfd.Instance = Convert.ToUInt32(part[4].Trim(), 16); } catch (Exception) {} } try { part = System.IO.Path.GetDirectoryName(filename).Split("\\".ToCharArray()); if (part.Length > 0) { string last = part[part.Length - 1]; part = last.Split("-".ToCharArray(), 2); pfd.Type = Convert.ToUInt32(part[0].Trim(), 16); } } catch (Exception) {} } } catch (Exception) { } System.IO.FileStream fs = System.IO.File.OpenRead(filename); try { System.IO.BinaryReader mbr = new System.IO.BinaryReader(fs); byte[] data = new byte[mbr.BaseStream.Length]; for (int i = 0; i < data.Length; i++) { data[i] = mbr.ReadByte(); } pfd.UserData = data; } catch (Exception ex) { Helper.ExceptionMessage(Localization.Manager.GetString("err003").Replace("{0}", filename), ex); return(false); } finally { fs.Close(); fs.Dispose(); fs = null; } } catch (Exception ex) { Helper.ExceptionMessage(Localization.Manager.GetString("erropenfile") + " " + filename, ex); return(false); } return(true); }