| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313 |
- using System;
- using System.Drawing;
- using System.Text;
- using System.IO;
- using System.Fire.FilePack.Exception;
- using System.IO.Compression;
- namespace System.Fire.FilePack {
- public class FilePack : IDisposable {
- private UInt16 keyCount;
- private string _filePath;
- private FilePackElements.FPKeyWords[] KeyWords;
- private bool bOpened;
- private BinaryReader _stream;
- private FileStream _streamBase;
- private bool disposed = false;
- private string _Password = "";
- private FilePackElements.eSet _settings;
- private FilePackElements.FileExtension[] Extensions;
- private DateTime _date;
- private FilePackElements.FPComment[] _comments;
- private byte _commentCount = 0;
- /// <summary>
- /// Signatur Ascii Array
- /// </summary>
- public static byte[] Signature = new byte[] { 70, 105, 108, 101, 80, 97, 99, 107, 66, 80 };
- /// <summary>
- /// Signature Version
- /// </summary>
- public FilePackElements.eVersion SignatureVersion = FilePackElements.eVersion.Version_1_0;
- private bool bConsole = false;
- /// <summary>Limit if File Items</summary>
- public const UInt16 FileLimit = 32767;
- /// <summary>Limit for the maximum comment count</summary>
- public const byte MaxCommentCount = 100;
- // Header Structur
- // Bytes Typ Name
- // 10 Byte() Signature (Fix)
- // 1 Byte Version
- // 1 eSet Einstellungen 1
- // 1 Byte Anzahl "Comment" Felder
- // 5 Byte() Datum
- // [1] Byte Prüfsumme - Wenn Passwort gesetzt
- // [1] Byte Prüfsumme + (Länge MOD 5) + ASC(PW{1}) - Wenn Passwort gesetzt
- // [1] Byte CheckSumme - Wenn Passwort gesetzt
- // 2 Int16 Anzahl Einträge
- // n FPKeyWords(n) Einträge
- // 1 Byte Anzahl Dateiendungen
- // n FileExtantion Dateiendungen
- #region "Class Functions"
- /// <summary>Erstellt ein neues FilePack Objekt</summary>
- /// <param name="FilePath">Pfad und Name der FilePack-Datei</param>
- public FilePack(string FilePath) {
- System.Diagnostics.Debug.WriteLine("Create Filepack(\"" + FilePath + "\")");
- this.Create(FilePath, "");
- }
- /// <summary>Erstellt ein neues FilePack Objekt</summary>
- /// <param name="FilePath">Pfad und Name der FilePack-Datei</param>
- /// <param name="Password">Setzt ein Passwort zum entschlüsseln geschützter Archive</param>
- public FilePack(string FilePath, string Password) {
- System.Diagnostics.Debug.WriteLine("Create Filepack(\"" + FilePath + "\", \"" + Password + "\")");
- this.Create(FilePath, Password);
- }
- /// <summary>Erstellt ein neues FilePack Objekt</summary>
- /// <param name="FilePath">Pfad und Name der FilePack-Datei</param>
- /// <param name="UseConsole">Consoleneinträge werden erstellt</param>
- public FilePack(string FilePath, bool UseConsole) {
- System.Diagnostics.Debug.WriteLine("Create Filepack(\"" + FilePath + "\", " + (UseConsole ? "True" : "False") + ")");
- this.Create(FilePath, "");
- this.bConsole = UseConsole;
- }
- /// <summary>Erstellt ein neues FilePack Objekt</summary>
- /// <param name="FilePath">Pfad und Name der FilePack-Datei</param>
- /// <param name="Password">Setzt ein Passwort zum entschlüsseln geschützter Archive</param>
- /// <param name="UseConsole">Consoleneinträge werden erstellt</param>
- public FilePack(string FilePath, string Password, bool UseConsole) {
- System.Diagnostics.Debug.WriteLine("Create Filepack(\"" + FilePath + "\", \"" + Password + "\", " + (UseConsole ? "True" : "False") + ")");
- this.Create(FilePath, Password);
- this.bConsole = UseConsole;
- }
- /// <summary>Erstellt ein neues FilePack Objekt</summary>
- /// <param name="FS">Dateistream</param>
- public FilePack(FileStream FS) {
- this.Create(FS, "");
- }
- /// <summary>Erstellt ein neues FilePack Objekt</summary>
- /// <param name="FS">Dateistream</param>
- /// <param name="Password">Setzt ein Passwort zum entschlüsseln geschützter Archive</param>
- public FilePack(FileStream FS, string Password) {
- this.Create(FS, Password);
- }
- /// <summary>Erstellt ein neues FilePack Objekt</summary>
- /// <param name="FS">Dateistream</param>
- /// <param name="UseConsole">Consoleneinträge werden erstellt</param>
- public FilePack(FileStream FS, bool UseConsole) {
- this.Create(FS, "");
- this.bConsole = UseConsole;
- }
- /// <summary>Erstellt ein neues FilePack Objekt</summary>
- /// <param name="FS">Dateistream</param>
- /// <param name="Password">Setzt ein Passwort zum entschlüsseln geschützter Archive</param>
- /// <param name="UseConsole">Consoleneinträge werden erstellt</param>
- public FilePack(FileStream FS, string Password, bool UseConsole) {
- this.Create(FS, Password);
- this.bConsole = UseConsole;
- }
- ~FilePack() {
- this.Dispose(false);
- }
- /// <summary>
- /// Gibt sämmtliche von FilePack verwendete Ressourcen frei
- /// </summary>
- public virtual void Dispose() {
- Dispose(true);
- GC.SuppressFinalize(this);
- bOpened = false;
- }
- /// <summary>
- /// Gibt die von FilePack und den untergeordneten Klassen verwednete Ressourcen, nicht verwalteten Ressourcen und optional auch die verwalteten Ressourcen frei.
- /// </summary>
- /// <param name="disposing">true, um sowohl die verwalteten als auch die nicht verwalteten Ressourcen freizugeben. false um ausschließlich die verwalteten Ressourcen freizugeben.</param>
- public virtual void Dispose(bool disposing) {
- if (disposed == false) {
- if (disposing) {
- if (this._stream != null)
- this._stream.Close();
- if (this._streamBase != null)
- this._streamBase.Close();
- if (this._streamBase != null)
- this._streamBase.Dispose();
- this._stream = null;
- this._streamBase = null;
- disposed = true;
- }
- this.Close();
- this._filePath = "";
- }
- }
- public void Cons(string str) {
- if (this.bConsole)
- Console.WriteLine(str);
- }
- public static void Cons(string str, bool bConsole) {
- if (bConsole)
- Console.WriteLine(str);
- }
- #endregion
- #region "This Property"
- public string this[string Name] {
- get { return this.getText(Name); }
- }
- public string this[FilePackElements.FPKeyWords Keyword] {
- get { return this.getText(Keyword); }
- }
- #endregion
- #region "Propertys"
- /// <summary>Gibt eine Auflistung der Keywords zurück</summary>
- /// <returns>Gibt eine Auflistung der Keywords im FPKeywords Object zurück</returns>
- public FilePackElements.FPKeyWords[] Keyword() {
- return this.KeyWords;
- }
- /// <summary>Gibt das dem Index entsprechende Keywords zurück</summary>
- /// <param name="Index">Index des Keywords</param>
- /// <returns>Gibt das dem Index entsprechende Keyword im FPKeywords Object zurück</returns>
- public FilePackElements.FPKeyWords Keyword(short Index) {
- return this.KeyWords[Index];
- }
- /// <summary>Gibt das dem Index entsprechende Keywords zurück</summary>
- /// <param name="Index">Index des Keywords</param>
- /// <returns>Gibt das dem Index entsprechende Keyword im FPKeywords Object zurück</returns>
- public FilePackElements.FPKeyWords Keyword(int Index) {
- return this.KeyWords[Index];
- }
- /// <summary>Gibt das dem Namen entsprechende Keywords zurück</summary>
- /// <param name="Name">Name des Keywords</param>
- /// <returns>Gibt das dem Namen entsprechende Keyword im FPKeywords Object zurück</returns>
- public FilePackElements.FPKeyWords Keyword(string Name) {
- return this.getKeywordByName(Name);
- }
- /// <summary>Gibt die Anzahl der geladenen Keywords zurück</summary>
- /// <returns>Gibt die Anzahl der geladenen Keywords zurück</returns>
- public ushort Length {
- get { return this.keyCount; }
- }
- /// <summary>Gibt das Erstellungsdatum des Archives zurück</summary>
- /// <returns>Gibt das Erstellungsdatum des Archives als Date-Object zurück</returns>
- public DateTime CreateDate {
- get { return this._date; }
- }
- /// <summary>Gibt die Einstellungen des geladenen Archivs zurück</summary>
- /// <returns>Gibt die Einstellungen des geladenen Archivs als eSet Objekt zurück</returns>
- public FilePackElements.eSet Settings {
- get { return this._settings; }
- }
- public FilePackElements.FileExtension Extension(byte ID) {
- byte uext = (byte)(this._settings | FilePackElements.eSet.Extantions);
- if (uext == (byte)this._settings)
- return this.Extensions[ID];
- else
- return new FilePackElements.FileExtension("");
- }
- #endregion
- #region "Load"
- /// <summary>Öffnet ein FilePack Archiv</summary>
- /// <param name="FilePath">Pfad zu dem FilePack Archiv</param>
- public void Load(string FilePath) {
- this.Create(FilePath, "");
- }
- /// <summary>Öffnet ein FilePack Archiv</summary>
- /// <param name="FilePath">Pfad zu dem FilePack Archiv</param>
- /// <param name="Password">Setzt ein Passwort zum entschlüsseln geschützter Archive</param>
- public void Load(string FilePath, string Password) {
- this.Create(FilePath, Password);
- }
- /// <summary>Öffnet ein FilePack Archiv</summary>
- /// <param name="Stream">Datei-Stream des FilePack Archives</param>
- public void Load(FileStream Stream) {
- this.Create(Stream, "");
- }
- /// <summary>Öffnet ein FilePack Archiv</summary>
- /// <param name="Stream">Datei-Stream des FilePack Archives</param>
- /// <param name="Password">Setzt ein Passwort zum entschlüsseln geschützter Archive</param>
- public void Load(FileStream Stream, string Password) {
- this.Create(Stream, Password);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="FilePath"></param>
- /// <param name="Password"></param>
- /// <exception cref="System.IO.FileNotFoundException">File not found</exception>
- private void Create(string FilePath, string Password) {
- System.Diagnostics.Debug.WriteLine("Create called: " + FilePath + (Password != "" ? ":" + Password : ""));
- if (this.bOpened == true) this.Close();
- if (File.Exists(FilePath)) {
- this.Cons("Open archive. Using password: " + (Password == "" ? "No" : "Yes"));
- this._streamBase = new FileStream(FilePath, FileMode.Open, FileAccess.Read);
- this._stream = new BinaryReader(this._streamBase, System.Text.Encoding.ASCII);
- this._filePath = FilePath;
- this._Password = Password;
- if (_streamBase.Length < 17) {
- this._filePath = "";
- this._Password = "";
- this._stream.Close();
- this._streamBase.Close();
- this._streamBase.Dispose();
- throw new Exception_Filesize(this._filePath, this._streamBase.Length);
- } else {
- byte[] s = this._stream.ReadBytes(10);
- if (checkSignature(s)) {
- SignatureVersion = (FilePackElements.eVersion)this._stream.ReadByte();
- this.bOpened = true;
- System.Diagnostics.Debug.WriteLine("File Signature: " + SignatureVersion.ToString());
- switch (SignatureVersion) {
- case FilePackElements.eVersion.Version_1_0:
- createVersion1();
- break;
- default:
- this._filePath = "";
- this._Password = "";
- this._stream.Close();
- this._streamBase.Close();
- this._streamBase.Dispose();
- throw new Exception_UnsportVersion(this._filePath, this._streamBase.Length, (byte)SignatureVersion);
- }
- } else
- throw new Exception_Signature(this._filePath, this._streamBase.Length);
- }
- } else
- throw new IO.FileNotFoundException("Datei konnte nicht gefunden werden\r\n" + FilePath, FilePath);
- }
- private void Create(FileStream Stream, string Password) {
- if (this.bOpened == true) this.Close();
- this.Cons("Open archive. Using password: " + (Password == "" ? "No" : "Yes"));
- this._streamBase = Stream;
- this._stream = new BinaryReader(this._streamBase, Text.Encoding.ASCII);
- this._filePath = Stream.Name;
- this._Password = Password;
- if (_streamBase.Length < 17) {
- this._filePath = "";
- this._Password = "";
- this._stream.Close();
- this._streamBase.Close();
- this._streamBase.Dispose();
- throw new Exception_Filesize(this._filePath, this._streamBase.Length);
- } else {
- byte[] s = this._stream.ReadBytes(10);
- if (checkSignature(s)) {
- SignatureVersion = (FilePackElements.eVersion)this._stream.ReadByte();
- this.bOpened = true;
- switch (SignatureVersion) {
- case FilePackElements.eVersion.Version_1_0:
- createVersion1();
- break;
- default:
- this._filePath = "";
- this._Password = "";
- this._stream.Close();
- this._streamBase.Close();
- this._streamBase.Dispose();
- throw new Exception_UnsportVersion(this._filePath, this._streamBase.Length, (byte)SignatureVersion);
- }
- } else
- throw new Exception_Signature(this._filePath, this._streamBase.Length);
- }
- }
- private void createVersion1() {
- this._settings = (FilePackElements.eSet)this._stream.ReadByte();
- this._commentCount = this._stream.ReadByte();
- this._date = FilePack.bitsToDate(this._stream.ReadBytes(5));
- System.Diagnostics.Debug.WriteLine("Header Info 1 - Settings: " + this._settings.ToString() + "; commentCount: " + this._commentCount + "; date: " + this._date.ToLongDateString());
- if (checkPW1()) {
- this.keyCount = this._stream.ReadUInt16();
- this.KeyWords = new FilePackElements.FPKeyWords[this.keyCount];
- System.Diagnostics.Debug.WriteLine("Header Info 2 - keyCount: " + this.keyCount);
- for (int i = 0; i < this.keyCount; i++)
- this.KeyWords[i] = new FilePackElements.FPKeyWords(this._stream);
-
- FilePackElements.eSet useExt = (this._settings | FilePackElements.eSet.Extantions);
- byte extCount = 0;
- if (useExt == this._settings) {
- extCount = this._stream.ReadByte();
- this.Extensions = new FilePackElements.FileExtension[extCount];
- for (int j = 0; j < extCount; j++)
- this.Extensions[j] = new FilePackElements.FileExtension(this._stream);
- }
- System.Diagnostics.Debug.WriteLine("Header Info 3 - useExt: " + (useExt == this._settings ? "True" : "False") + "; extCount: " + extCount);
- long off = this._streamBase.Position;
- for (int i = 0; i < this.keyCount; i++) {
- this.KeyWords[i].Offset = off;
- off += this.KeyWords[i].Length;
- }
- this.Cons("Data Count: " + this.keyCount);
- if (this._commentCount > 0) {
- this._comments = new FilePackElements.FPComment[this._commentCount - 1];
- for (int i = 0; i < this._commentCount; i++)
- this._comments[i] = new FilePackElements.FPComment(this._stream);
- }
- }
- }
- /// <summary>
- /// Schließt das Archiv und gibt den Stream frei
- /// </summary>
- /// <remarks></remarks>
- public void Close() {
- if (this._stream != null)
- this._stream.Close();
- if (this._streamBase != null)
- this._streamBase.Close();
- if (this._streamBase != null)
- this._streamBase.Dispose();
- this._stream = null;
- this._streamBase = null;
- this.keyCount = 0;
- this._filePath = "";
- this.bOpened = false;
- this._Password = "";
- if(this.KeyWords!=null)
- for (int i = 0; i < this.KeyWords.Length; i++)
- this.KeyWords[i] = null;
- this.KeyWords = null;
- if (this.Extensions != null) {
- if (this.Extensions.Length > 0)
- for (int i = 0; i < this.Extensions.Length; i++)
- this.Extensions[i] = null;
- this.Extensions = null;
- }
- this.Cons("Archive closed");
- }
- #endregion
- #region "Get Data"
- #region "getImage"
- /// <summary>Gibt die Daten anhand der ID als <see cref="System.Drawing.Image">Image</see>-Object zurück</summary>
- /// <param name="ID">Die ID des Eintrags in der Datei</param>
- /// <returns>Gibt die Daten anhand der ID als <see cref="System.Drawing.Image">Image</see>-Object zurück</returns>
- /// <remarks>System.Drawing.Image</remarks>
- public Image getImage(int ID) {
- FilePackElements.FPKeyWords fpk = this.KeyWords[ID];
- if(fpk!=null) {
- byte[] Data = fpk.getBytes();
- FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
- if(DataGZip == this._settings) {
- IO.MemoryStream mem = new IO.MemoryStream(Data);
- System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
- StreamReader sr = new IO.StreamReader(gz);
- sr.Close();
- gz.Close();
- mem.Close();
- sr.Dispose();
- gz.Dispose();
- mem.Dispose();
- }
- FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
- if(crypt == this._settings)
- Data = this.Decode(Data, this._Password);
- return (Image)new ImageConverter().ConvertFrom(Data);
- }
- return null;
- }
- /// <summary>Gibt die Daten anhand des Keyword-Objektes als <see cref="System.Drawing.Image">Image</see>-Object zurück</summary>
- /// <param name="FPK">Das Keyword-Objektes für die Identifizierung</param>
- /// <returns>Gibt die Daten anhand des Keyword-Objektes als <see cref="System.Drawing.Image">Image</see>-Object zurück</returns>
- /// <remarks>System.Drawing.Image</remarks>
- public Image getImage(FilePackElements.FPKeyWords fpk) {
- if (fpk != null) {
- byte[] Data = fpk.getBytes();
- FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
- if (DataGZip == this._settings) {
- IO.MemoryStream mem = new IO.MemoryStream(Data);
- System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
- StreamReader sr = new IO.StreamReader(gz);
- sr.Close();
- gz.Close();
- mem.Close();
- sr.Dispose();
- gz.Dispose();
- mem.Dispose();
- }
- FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
- if (crypt == this._settings)
- Data = this.Decode(Data, this._Password);
- return (Image)new ImageConverter().ConvertFrom(Data);
- }
- return null;
- }
- /// <summary>Gibt die Daten anhand des Namen als <see cref="System.Drawing.Image">Image</see>-Object zurück</summary>
- /// <param name="Name">Der Keyword-Name</param>
- /// <returns>Gibt die Daten anhand des Namen als <see cref="System.Drawing.Image">Image</see>-Object zurück</returns>
- /// <remarks>System.Drawing.Image</remarks>
- public Image getImage(string Name) {
- FilePackElements.FPKeyWords fpk = this.getKeywordByName(Name, FilePackElements.DataType.dtImage);
- if (fpk != null) {
- byte[] Data = fpk.getBytes();
- FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
- if (DataGZip == this._settings) {
- IO.MemoryStream mem = new IO.MemoryStream(Data);
- System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
- StreamReader sr = new IO.StreamReader(gz);
- sr.Close();
- gz.Close();
- mem.Close();
- sr.Dispose();
- gz.Dispose();
- mem.Dispose();
- }
- FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
- if (crypt == this._settings)
- Data = this.Decode(Data, this._Password);
- return (Image)new ImageConverter().ConvertFrom(Data);
- }
- return null;
- }
- #endregion
- #region "getText"
- public string getText(int ID) {
- FilePackElements.FPKeyWords fpk = this.KeyWords[ID];
- if (fpk != null) {
- byte[] Data = fpk.getBytes();
- Encoding enc = System.Text.Encoding.UTF8;
- FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
- if (DataGZip == this._settings) {
- IO.MemoryStream mem = new IO.MemoryStream(Data);
- System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
- gz.Write(Data, 0, Data.Length);
- StreamReader sr = new IO.StreamReader(gz);
- Data = mem.ToArray();
- gz.Flush();
- sr.Close();
- gz.Close();
- mem.Close();
- sr.Dispose();
- gz.Dispose();
- mem.Dispose();
- }
- FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
- if (crypt == this._settings)
- Data = this.Decode(Data, this._Password);
- return enc.GetString(Data);
- }
- return null;
- }
- public string getText(FilePackElements.FPKeyWords fpk) {
- if (fpk != null) {
- byte[] Data = fpk.getBytes();
- Encoding enc = System.Text.Encoding.UTF8;
- FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
- if (DataGZip == this._settings) {
- IO.MemoryStream mem = new IO.MemoryStream(Data);
- System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
- gz.Write(Data, 0, Data.Length);
- StreamReader sr = new IO.StreamReader(gz);
- Data = mem.ToArray();
- gz.Flush();
- sr.Close();
- gz.Close();
- mem.Close();
- sr.Dispose();
- gz.Dispose();
- mem.Dispose();
- }
- FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
- if (crypt == this._settings)
- Data = this.Decode(Data, this._Password);
- return enc.GetString(Data);
- }
- return null;
- }
- public string getText(string Name) {
- FilePackElements.FPKeyWords fpk = this.getKeywordByName(Name, FilePackElements.DataType.dtImage);
- if (fpk != null) {
- byte[] Data = fpk.getBytes();
- Encoding enc = System.Text.Encoding.UTF8;
- FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
- if (DataGZip == this._settings) {
- IO.MemoryStream mem = new IO.MemoryStream(Data);
- System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
- gz.Write(Data, 0, Data.Length);
- StreamReader sr = new IO.StreamReader(gz);
- Data = mem.ToArray();
- gz.Flush();
- sr.Close();
- gz.Close();
- mem.Close();
- sr.Dispose();
- gz.Dispose();
- mem.Dispose();
- }
- FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
- if (crypt == this._settings)
- Data = this.Decode(Data, this._Password);
- return enc.GetString(Data);
- }
- return null;
- }
- public string getText(int ID, Encoding enc) {
- FilePackElements.FPKeyWords fpk = this.KeyWords[ID];
- if (fpk != null) {
- byte[] Data = fpk.getBytes();
- FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
- if (DataGZip == this._settings) {
- IO.MemoryStream mem = new IO.MemoryStream(Data);
- System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
- gz.Write(Data, 0, Data.Length);
- StreamReader sr = new IO.StreamReader(gz);
- Data = mem.ToArray();
- gz.Flush();
- sr.Close();
- gz.Close();
- mem.Close();
- sr.Dispose();
- gz.Dispose();
- mem.Dispose();
- }
- FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
- if (crypt == this._settings)
- Data = this.Decode(Data, this._Password);
- return enc.GetString(Data);
- }
- return null;
- }
- public string getText(FilePackElements.FPKeyWords fpk, Encoding enc) {
- if (fpk != null) {
- byte[] Data = fpk.getBytes();
- FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
- if (DataGZip == this._settings) {
- IO.MemoryStream mem = new IO.MemoryStream(Data);
- System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
- gz.Write(Data, 0, Data.Length);
- StreamReader sr = new IO.StreamReader(gz);
- Data = mem.ToArray();
- gz.Flush();
- sr.Close();
- gz.Close();
- mem.Close();
- sr.Dispose();
- gz.Dispose();
- mem.Dispose();
- }
- FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
- if (crypt == this._settings)
- Data = this.Decode(Data, this._Password);
- return enc.GetString(Data);
- }
- return null;
- }
- public string getText(string Name, Encoding enc) {
- FilePackElements.FPKeyWords fpk = this.getKeywordByName(Name, FilePackElements.DataType.dtImage);
- if (fpk != null) {
- byte[] Data = fpk.getBytes();
- FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
- if (DataGZip == this._settings) {
- IO.MemoryStream mem = new IO.MemoryStream(Data);
- System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
- gz.Write(Data, 0, Data.Length);
- StreamReader sr = new IO.StreamReader(gz);
- Data = mem.ToArray();
- gz.Flush();
- sr.Close();
- gz.Close();
- mem.Close();
- sr.Dispose();
- gz.Dispose();
- mem.Dispose();
- }
- FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
- if (crypt == this._settings)
- Data = this.Decode(Data, this._Password);
- return enc.GetString(Data);
- }
- return null;
- }
- #endregion
- #region "getData"
- /// <summary>Gibt die Daten anhand der ID als <see cref="System.String">String</see> zurück</summary>
- /// <param name="ID">Die ID des Eintrags in der Datei</param>
- /// <returns>Gibt die Daten anhand der ID als <see cref="System.String">String</see> zurück</returns>
- /// <remarks>System.String</remarks>
- public string getData(int ID) {
- FilePackElements.FPKeyWords fpk = this.KeyWords[ID];
- if (fpk != null) {
- byte[] Data = fpk.getBytes();
- Encoding enc = System.Text.Encoding.ASCII;
- FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
- if (DataGZip == this._settings) {
- IO.MemoryStream mem = new IO.MemoryStream(Data);
- System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
- gz.Write(Data, 0, Data.Length);
- StreamReader sr = new IO.StreamReader(gz);
- Data = mem.ToArray();
- gz.Flush();
- sr.Close();
- gz.Close();
- mem.Close();
- sr.Dispose();
- gz.Dispose();
- mem.Dispose();
- }
- FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
- if (crypt == this._settings)
- Data = this.Decode(Data, this._Password);
- return enc.GetString(Data);
- }
- return null;
- }
- /// <summary>Gibt die Daten anhand des Keyword-Objektes als <see cref="System.String">String</see> zurück</summary>
- /// <param name="FPK">Das Keyword-Objektes für die Identifizierung</param>
- /// <returns>Gibt die Daten anhand des Keyword-Objektes als <see cref="System.String">String</see> zurück</returns>
- /// <remarks>System.String</remarks>
- public string getData(FilePackElements.FPKeyWords fpk) {
- if (fpk != null) {
- byte[] Data = fpk.getBytes();
- Encoding enc = System.Text.Encoding.ASCII;
- FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
- if (DataGZip == this._settings) {
- IO.MemoryStream mem = new IO.MemoryStream(Data);
- System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
- gz.Write(Data, 0, Data.Length);
- StreamReader sr = new IO.StreamReader(gz);
- Data = mem.ToArray();
- gz.Flush();
- sr.Close();
- gz.Close();
- mem.Close();
- sr.Dispose();
- gz.Dispose();
- mem.Dispose();
- }
- FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
- if (crypt == this._settings)
- Data = this.Decode(Data, this._Password);
- return enc.GetString(Data);
- }
- return null;
- }
- /// <summary>Gibt die Daten anhand des Namen als <see cref="System.String">String</see> zurück</summary>
- /// <param name="Name">Der Keyword-Name</param>
- /// <returns>Gibt die Daten anhand des Namen als <see cref="System.String">String</see> zurück</returns>
- /// <remarks>System.String</remarks>
- public string getData(string Name) {
- FilePackElements.FPKeyWords fpk = this.getKeywordByName(Name, FilePackElements.DataType.dtImage);
- if (fpk != null) {
- byte[] Data = fpk.getBytes();
- Encoding enc = System.Text.Encoding.ASCII;
- FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
- if (DataGZip == this._settings) {
- IO.MemoryStream mem = new IO.MemoryStream(Data);
- System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
- gz.Write(Data, 0, Data.Length);
- StreamReader sr = new IO.StreamReader(gz);
- Data = mem.ToArray();
- gz.Flush();
- sr.Close();
- gz.Close();
- mem.Close();
- sr.Dispose();
- gz.Dispose();
- mem.Dispose();
- }
- FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
- if (crypt == this._settings)
- Data = this.Decode(Data, this._Password);
- return enc.GetString(Data);
- }
- return null;
- }
- #endregion
- #region "getByteArray"
- /// <summary>Gibt die Daten anhand der ID als <see cref="System.String">Byte-Array</see> zurück</summary>
- /// <param name="ID">Die ID des Eintrags in der Datei</param>
- /// <returns>Gibt die Daten anhand der ID als <see cref="System.String">Byte-Array</see> zurück</returns>
- /// <remarks>System.Byte</remarks>
- public byte[] getByteArray(int ID) {
- FilePackElements.FPKeyWords fpk = this.KeyWords[ID];
- if (fpk != null) {
- byte[] Data = fpk.getBytes();
- FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
- if (DataGZip == this._settings) {
- IO.MemoryStream mem = new IO.MemoryStream(Data);
- System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
- gz.Write(Data, 0, Data.Length);
- StreamReader sr = new IO.StreamReader(gz);
- Data = mem.ToArray();
- gz.Flush();
- sr.Close();
- gz.Close();
- mem.Close();
- sr.Dispose();
- gz.Dispose();
- mem.Dispose();
- }
- FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
- if (crypt == this._settings)
- Data = this.Decode(Data, this._Password);
- return Data;
- }
- return null;
- }
- /// <summary>Gibt die Daten anhand des Keyword-Objektes als <see cref="System.String">Byte-Array</see> zurück</summary>
- /// <param name="FPK">Das Keyword-Objektes für die Identifizierung</param>
- /// <returns>Gibt die Daten anhand des Keyword-Objektes als <see cref="System.String">Byte-Array</see> zurück</returns>
- /// <remarks>System.Byte</remarks>
- public byte[] getByteArray(FilePackElements.FPKeyWords fpk) {
- if (fpk != null) {
- byte[] Data = fpk.getBytes();
- FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
- if (DataGZip == this._settings) {
- IO.MemoryStream mem = new IO.MemoryStream(Data);
- System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
- gz.Write(Data, 0, Data.Length);
- StreamReader sr = new IO.StreamReader(gz);
- Data = mem.ToArray();
- gz.Flush();
- sr.Close();
- gz.Close();
- mem.Close();
- sr.Dispose();
- gz.Dispose();
- mem.Dispose();
- }
- FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
- if (crypt == this._settings)
- Data = this.Decode(Data, this._Password);
- return Data;
- }
- return null;
- }
- /// <summary>Gibt die Daten anhand des Namen als <see cref="System.String">Byte-Array</see> zurück</summary>
- /// <param name="Name">Der Keyword-Name</param>
- /// <returns>Gibt die Daten anhand des Namen als <see cref="System.String">Byte-Array</see> zurück</returns>
- /// <remarks>System.Byte</remarks>
- public byte[] getByteArray(string Name) {
- FilePackElements.FPKeyWords fpk = this.getKeywordByName(Name, FilePackElements.DataType.dtImage);
- if (fpk != null) {
- byte[] Data = fpk.getBytes();
- FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
- if (DataGZip == this._settings) {
- IO.MemoryStream mem = new IO.MemoryStream(Data);
- System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
- gz.Write(Data, 0, Data.Length);
- StreamReader sr = new IO.StreamReader(gz);
- Data = mem.ToArray();
- gz.Flush();
- sr.Close();
- gz.Close();
- mem.Close();
- sr.Dispose();
- gz.Dispose();
- mem.Dispose();
- }
- FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
- if (crypt == this._settings)
- Data = this.Decode(Data, this._Password);
- return Data;
- }
- return null;
- }
- #endregion
- #region "getStream"
- /// <summary>Gibt die Daten anhand der ID als <see cref="System.String">Stream</see> zurück</summary>
- /// <param name="ID">Die ID des Eintrags in der Datei</param>
- /// <returns>Gibt die Daten anhand der ID als <see cref="System.String">Stream</see> zurück</returns>
- /// <remarks>System.IO.Stream</remarks>
- public Stream getStream(int ID) {
- FilePackElements.FPKeyWords fpk = this.KeyWords[ID];
- if (fpk != null) {
- byte[] Data = fpk.getBytes();
- FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
- if (DataGZip == this._settings) {
- IO.MemoryStream mem = new IO.MemoryStream(Data);
- System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
- gz.Write(Data, 0, Data.Length);
- StreamReader sr = new IO.StreamReader(gz);
- Data = mem.ToArray();
- gz.Flush();
- sr.Close();
- gz.Close();
- mem.Close();
- sr.Dispose();
- gz.Dispose();
- mem.Dispose();
- }
- FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
- if (crypt == this._settings)
- Data = this.Decode(Data, this._Password);
- return new IO.MemoryStream(Data);
- }
- return null;
- }
- /// <summary>Gibt die Daten anhand des Keyword-Objektes als <see cref="System.String">Stream</see> zurück</summary>
- /// <param name="FPK">Das Keyword-Objektes für die Identifizierung</param>
- /// <returns>Gibt die Daten anhand des Keyword-Objektes als <see cref="System.String">Stream</see> zurück</returns>
- /// <remarks>System.IO.Stream</remarks>
- public Stream getStream(FilePackElements.FPKeyWords fpk) {
- if (fpk != null) {
- byte[] Data = fpk.getBytes();
- FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
- if (DataGZip == this._settings) {
- IO.MemoryStream mem = new IO.MemoryStream(Data);
- System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
- gz.Write(Data, 0, Data.Length);
- StreamReader sr = new IO.StreamReader(gz);
- Data = mem.ToArray();
- gz.Flush();
- sr.Close();
- gz.Close();
- mem.Close();
- sr.Dispose();
- gz.Dispose();
- mem.Dispose();
- }
- FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
- if (crypt == this._settings)
- Data = this.Decode(Data, this._Password);
- return new IO.MemoryStream(Data);
- }
- return null;
- }
- /// <summary>Gibt die Daten anhand des Namen als <see cref="System.String">Stream</see> zurück</summary>
- /// <param name="Name">Der Keyword-Name</param>
- /// <returns>Gibt die Daten anhand des Namen als <see cref="System.String">Stream</see> zurück</returns>
- /// <remarks>System.IO.Stream</remarks>
- public Stream getStream(string Name) {
- FilePackElements.FPKeyWords fpk = this.getKeywordByName(Name, FilePackElements.DataType.dtImage);
- if (fpk != null) {
- byte[] Data = fpk.getBytes();
- FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
- if (DataGZip == this._settings) {
- IO.MemoryStream mem = new IO.MemoryStream(Data);
- System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
- gz.Write(Data, 0, Data.Length);
- StreamReader sr = new IO.StreamReader(gz);
- Data = mem.ToArray();
- gz.Flush();
- sr.Close();
- gz.Close();
- mem.Close();
- sr.Dispose();
- gz.Dispose();
- mem.Dispose();
- }
- FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
- if (crypt == this._settings)
- Data = this.Decode(Data, this._Password);
- return new IO.MemoryStream(Data);
- }
- return null;
- }
- #endregion
- #region "getAssembly"
- /// <summary>Gibt die Daten anhand der ID als <see cref="System.String">Stream</see> zurück</summary>
- /// <param name="ID">Die ID des Eintrags in der Datei</param>
- /// <returns>Gibt die Daten anhand der ID als <see cref="System.String">Stream</see> zurück</returns>
- /// <remarks>System.IO.Stream</remarks>
- public System.Reflection.Assembly getAssembly(int ID) {
- FilePackElements.FPKeyWords fpk = this.KeyWords[ID];
- if (fpk != null) {
- byte[] Data = fpk.getBytes();
- FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
- if (DataGZip == this._settings) {
- IO.MemoryStream mem = new IO.MemoryStream(Data);
- System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
- gz.Write(Data, 0, Data.Length);
- StreamReader sr = new IO.StreamReader(gz);
- Data = mem.ToArray();
- gz.Flush();
- sr.Close();
- gz.Close();
- mem.Close();
- sr.Dispose();
- gz.Dispose();
- mem.Dispose();
- }
- FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
- if (crypt == this._settings)
- Data = this.Decode(Data, this._Password);
- return System.Reflection.Assembly.Load(Data);
- }
- return null;
- }
- /// <summary>Gibt die Daten anhand des Keyword-Objektes als <see cref="System.String">Stream</see> zurück</summary>
- /// <param name="FPK">Das Keyword-Objektes für die Identifizierung</param>
- /// <returns>Gibt die Daten anhand des Keyword-Objektes als <see cref="System.String">Stream</see> zurück</returns>
- /// <remarks>System.IO.Stream</remarks>
- public System.Reflection.Assembly getAssembly(FilePackElements.FPKeyWords fpk) {
- if (fpk != null) {
- byte[] Data = fpk.getBytes();
- FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
- if (DataGZip == this._settings) {
- IO.MemoryStream mem = new IO.MemoryStream(Data);
- System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
- gz.Write(Data, 0, Data.Length);
- StreamReader sr = new IO.StreamReader(gz);
- Data = mem.ToArray();
- gz.Flush();
- sr.Close();
- gz.Close();
- mem.Close();
- sr.Dispose();
- gz.Dispose();
- mem.Dispose();
- }
- FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
- if (crypt == this._settings)
- Data = this.Decode(Data, this._Password);
- return System.Reflection.Assembly.Load(Data);
- }
- return null;
- }
- /// <summary>Gibt die Daten anhand des Namen als <see cref="System.String">Stream</see> zurück</summary>
- /// <param name="Name">Der Keyword-Name</param>
- /// <returns>Gibt die Daten anhand des Namen als <see cref="System.String">Stream</see> zurück</returns>
- /// <remarks>System.IO.Stream</remarks>
- public System.Reflection.Assembly getAssembly(string Name) {
- FilePackElements.FPKeyWords fpk = this.getKeywordByName(Name, FilePackElements.DataType.dtImage);
- if (fpk != null) {
- byte[] Data = fpk.getBytes();
- FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
- if (DataGZip == this._settings) {
- IO.MemoryStream mem = new IO.MemoryStream(Data);
- System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
- gz.Write(Data, 0, Data.Length);
- StreamReader sr = new IO.StreamReader(gz);
- Data = mem.ToArray();
- gz.Flush();
- sr.Close();
- gz.Close();
- mem.Close();
- sr.Dispose();
- gz.Dispose();
- mem.Dispose();
- }
- FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
- if (crypt == this._settings)
- Data = this.Decode(Data, this._Password);
- return System.Reflection.Assembly.Load(Data);
- }
- return null;
- }
- #endregion
- #endregion
- #region "Comments"
- public enum TextCommentType : byte {
- TextComment = 1,
- ShortTextComment = 7,
- Homepage = 2,
- Email = 4,
- Company = 5,
- Address = 8
- }
- public FilePackElements.FPComment addComment(string Text, TextCommentType Type) {
- Array.Resize(ref this._comments, this._commentCount + 1);
- this._comments[this._commentCount] = new FilePackElements.FPComment();
- this._comments[this._commentCount].Type = (FilePackElements.FPCommentType)((byte)Type);
- this._comments[this._commentCount].Caption = Text;
- this._commentCount += 1;
- return this._comments[this._commentCount - 1];
- }
- public FilePackElements.FPComment addComment(UInt16 FileID, string Text) {
- Array.Resize(ref this._comments, this._commentCount + 1);
- this._comments[this._commentCount] = new FilePackElements.FPComment();
- this._comments[this._commentCount].Type = FilePackElements.FPCommentType.FileComment;
- this._comments[this._commentCount].Caption = Text;
- this._comments[this._commentCount].FileID = FileID;
- this._commentCount += 1;
- return this._comments[this._commentCount - 1];
- }
- public FilePackElements.FPComment addComment(Bitmap Img) {
- Array.Resize(ref this._comments, this._commentCount + 1);
- this._comments[this._commentCount] = new FilePackElements.FPComment();
- this._comments[this._commentCount].Type = FilePackElements.FPCommentType.Image;
- this._comments[this._commentCount].Picture = Img;
- this._commentCount += 1;
- return this._comments[this._commentCount - 1];
- }
- public FilePackElements.FPComment addComment(UInt16 FileID, Bitmap Img) {
- Array.Resize(ref this._comments, this._commentCount + 1);
- this._comments[this._commentCount] = new FilePackElements.FPComment();
- this._comments[this._commentCount].Type = FilePackElements.FPCommentType.FileImage;
- this._comments[this._commentCount].Picture = Img;
- this._comments[this._commentCount].FileID = FileID;
- this._commentCount += 1;
- return this._comments[this._commentCount - 1];
- }
- public FilePackElements.FPComment addComment(Icon Ico) {
- Array.Resize(ref this._comments, this._commentCount + 1);
- this._comments[this._commentCount] = new FilePackElements.FPComment();
- this._comments[this._commentCount].Type = FilePackElements.FPCommentType.Icon;
- this._comments[this._commentCount].Icon = Ico;
- this._commentCount += 1;
- return this._comments[this._commentCount - 1];
- }
- public FilePackElements.FPComment addComment(UInt16 FileID, Icon Ico) {
- Array.Resize(ref this._comments, this._commentCount + 1);
- this._comments[this._commentCount] = new FilePackElements.FPComment();
- this._comments[this._commentCount].Type = FilePackElements.FPCommentType.FileIcon;
- this._comments[this._commentCount].Icon = Ico;
- this._comments[this._commentCount].FileID = FileID;
- this._commentCount += 1;
- return this._comments[this._commentCount - 1];
- }
- #endregion
- #region "Exists"
- /// <summary>Überprüft ob ein Keyword existiert</summary>
- /// <param name="Keyword">Name des Keywords</param>
- /// <returns>Gibt bei erfolg true zurück, false falls das Keyword nicht existiert.</returns>
- public bool Exsists(string Keyword) {
- for (int i = 0; i < this.keyCount; i++) {
- if (this.KeyWords[i].Keyword == Keyword)
- return true;
- }
- return false;
- }
- /// <summary>Überprüft ob ein Array mit Keywords existiert</summary>
- /// <param name="Keywords">Array mit Namen der Keywords</param>
- /// <returns>Gibt bei erfolg true zurück, false falls ein oder mehrere Keywords nicht existieren.</returns>
- public bool Exsists(string[] Keywords) {
- for (int i = 0; i < this.keyCount; i++) {
- bool bFound = false;
- for (int j = 0; j < Keywords.Length; j++) {
- if (this.KeyWords[i].Keyword == Keywords[j]) {
- bFound = true;
- break; // TODO: might not be correct. Was : Exit For
- }
- }
- if (bFound == false)
- return false;
- }
- return false;
- }
- #endregion
- #region "Crypt"
- private bool checkPW1() {
- byte s = (byte)(this._settings | FilePackElements.eSet.UsePassword);
- if (s == (byte)this._settings) {
- long sumx = 0;
- int sumy = 0;
- System.Text.Encoding enc = System.Text.Encoding.UTF8;
- byte[] xpw = enc.GetBytes(this._Password);
- for (int i = 0; i <= xpw.Length - 1; i++) {
- sumx = (sumx + xpw[i]) % 200;
- sumy = xpw[i] % 11;
- }
- byte sum = this._stream.ReadByte();
- byte sum2 = this._stream.ReadByte();
- byte sum3 = this._stream.ReadByte();
- sumx = (sumx % 200) + 25;
- if (sumx != sum) {
- throw new Exception_PassCheckSum(this._filePath, this._streamBase.Length, (byte)SignatureVersion, sum, sumx, 1);
- //return false;
- }
- sumx += (xpw.Length % 5) + xpw[0] % 200;
- if (sumx != sum2) {
- throw new Exception_PassCheckSum(this._filePath, this._streamBase.Length, (byte)SignatureVersion, sum2, sumx, 2);
- //return false;
- }
- sumy = (((sumy + xpw[xpw.Length - 1]) % 50) + ((sumy + xpw[xpw.Length - 1]) % 47) + ((sumy + xpw[xpw.Length - 1]) % 127) + 30);
- if (sumy != sum3) {
- throw new Exception_PassCheckSum(this._filePath, this._streamBase.Length, (byte)SignatureVersion, sum3, sumy, 3);
- //return false;
- }
- }
- return true;
- }
- private static void writePW1(ref IO.BinaryWriter S, string PW) {
- long sumx = 0;
- int sumy = 0;
- System.Text.Encoding enc = System.Text.Encoding.UTF8;
- byte[] xpw = enc.GetBytes(PW);
- for (int i = 0; i <= xpw.Length - 1; i++) {
- sumx = (sumx + xpw[i]) % 200;
- sumy = xpw[i] % 11;
- }
- sumx = (sumx % 200) + 25;
- S.Write(Convert.ToByte(sumx));
- sumx += (xpw.Length % 5) + xpw[0] % 200;
- S.Write(Convert.ToByte(sumx));
- sumy = (((sumy + xpw[xpw.Length - 1]) % 50) + ((sumy + xpw[xpw.Length - 1]) % 47) + ((sumy + xpw[xpw.Length - 1]) % 127) + 30);
- S.Write(Convert.ToByte(sumy));
- }
- private static byte[] Encode(byte[] b, string Password = "") {
- if (Password == "") {
- for (int i = 0; i < b.Length; i++) {
- byte j = (byte)((b[i] + i + b.Length) % 256);
- b[i] = j;
- }
- return b;
- } else {
- byte[] pw = Convert.FromBase64String(Password);
- int pwLen = pw.Length;
- for (int i = 0; i < b.Length; i++) {
- int j = ((b[i] + i + b.Length + pw[i % pwLen]) + pwLen) % 256;
- b[i] = (byte)j;
- }
- return b;
- }
- }
- private byte[] Decode(byte[] b, string Password = "") {
- if (Password=="") {
- for (int i = 0; i < b.Length; i++) {
- byte j = (byte)(((b[i] - (i % 256) - (b.Length % 256)) + 512) % 256);
- b[i] = j;
- }
- } else {
- byte[] pw = Convert.FromBase64String(Password);
- int pwLen = pw.Length;
- for (int i = 0; i < b.Length; i++) {
- int j = (((b[i] - (i % 256) - (b.Length % 256) - pw[i % pwLen]) - pwLen) + 2048) % 256;
- b[i] = (byte)j;
- }
- }
- return b;
- }
- #endregion
- #region "Count Property"
- /// <summary>Gibt die Anzahl Einträge zurück</summary>
- /// <returns>Gibt die Anzahl Einträge zurück</returns>
- /// <remarks></remarks>
- public int Count() {
- return this.KeyWords.Length;
- }
- /// <summary>Gibt die Anzahl Einträge des angegebenen Typen zurück</summary>
- /// <param name="Type">Gibt den Typen der Daten an, nach denen gezählt werden soll</param>
- /// <returns>Gibt die Anzahl Einträge des angegebenen Typen zurück</returns>
- /// <remarks></remarks>
- public int Count(FilePackElements.DataType Type) {
- int nr = 0;
- foreach (FilePackElements.FPKeyWords kw in this.KeyWords)
- if (kw.Type == Type) nr += 1;
- return nr;
- }
- /// <summary>Gibt die Anzahl Einträge mit der angegebenen Dateiendung zurück</summary>
- /// <param name="Extensions">Gibt die Dateiendung an, nach der gezählt werden soll</param>
- /// <returns>Gibt die Anzahl Einträge mit der angegebenen Dateiendung zurück</returns>
- /// <remarks></remarks>
- public int Count(string Extensions) {
- int nr = 0;
- foreach (FilePackElements.FPKeyWords kw in this.KeyWords)
- if (this.Extensions[kw.FileExtension].Extensions == Extensions) nr += 1;
- return nr;
- }
- #endregion
- #region "Other Functions"
- /// <summary>
- /// Gibt das entsprechende Keyword-Objekt als System.BlackPro.FilePackBP.FilePackElements.FPKeyWords zurück
- /// </summary>
- /// <param name="Name">Name des Keywords als String</param>
- /// <returns>Gibt das entsprechende Keyword-Objekt als System.BlackPro.FilePackBP.FilePackElements.FPKeyWords zurück</returns>
- public FilePackElements.FPKeyWords getKeywordByName(string Name) {
- for (int i = 0; i < this.keyCount; i++) {
- if (this.KeyWords[i].Keyword == Name)
- return this.KeyWords[i];
- }
- return null;
- }
- /// <summary>
- /// Gibt das entsprechende Keyword-Objekt als System.BlackPro.FilePackBP.FilePackElements.FPKeyWords zurück
- /// </summary>
- /// <param name="Name">Name des Keywords als String</param>
- /// <param name="Type">Datentyp des Keywords als System.BlackPro.FilePackBP.FilePack.DataType</param>
- /// <returns>Gibt das entsprechende Keyword-Objekt als System.BlackPro.FilePackBP.FilePackElements.FPKeyWords zurück</returns>
- public FilePackElements.FPKeyWords getKeywordByName(string Name, FilePackElements.DataType Type) {
- for (int i = 0; i < this.keyCount; i++) {
- if (this.KeyWords[i].Keyword == Name & this.KeyWords[i].Type == Type)
- return this.KeyWords[i];
- }
- return null;
- }
- /// <summary>
- /// Prüft die Signatur des Archivs
- /// </summary>
- /// <param name="b">Die Signatur als Byte-Array</param>
- /// <returns>Gibt bei erfolgreicher Signaturprüfung True zurück</returns>
- public static bool checkSignature(byte[] b) {
- if (b == null)
- return false;
- if (b.Length == 0)
- return false;
- if (b.Length == Signature.Length) {
- for (int i = 0; i < b.Length; i++) {
- if (b[i] != Signature[i])
- return false;
- }
- return true;
- } else {
- return false;
- }
- }
- private static char Chr(int b) {
- return Convert.ToChar(b);
- }
- private static char Chr(byte b) {
- return Convert.ToChar(b);
- }
- private static byte Asc(char c) {
- return Convert.ToByte(c);
- }
- private static string IIF(bool b, string t, string f) {
- if (b) {
- return t;
- } else {
- return f;
- }
- }
- private static byte IIF(bool b, byte t, byte f) {
- if (b) {
- return t;
- } else {
- return f;
- }
- }
- private static int IIF(bool b, int t, int f) {
- if (b) {
- return t;
- } else {
- return f;
- }
- }
- #endregion
- #region "Export"
- /// <summary>
- /// Exportiert die Einträge des Archives in das glaiche Verzeichnis
- /// </summary>
- public void exportToDirectory() {
- if (!string.IsNullOrEmpty(this._filePath)) {
- FileInfo fi = new FileInfo(this._filePath);
- this.exportToDirectory(fi.FullName.Substring(0, fi.FullName.Length - fi.Extension.Length) + "\\");
- }
- }
- /// <summary>
- /// Exportiert die Einträge des Archives in das glaiche Verzeichnis
- /// </summary>
- /// <param name="Overwrite">Gibt an, ob existierende Dateien überschrieben werden sollen</param>
- public void exportToDirectory(bool Overwrite) {
- if (!string.IsNullOrEmpty(this._filePath)) {
- FileInfo fi = new FileInfo(this._filePath);
- this.exportToDirectory(fi.FullName.Substring(0, fi.FullName.Length - fi.Extension.Length) + "\\", Overwrite);
- }
- }
- /// <summary>
- /// Exportiert die Einträge des Archives in das angegebene Verzeichnis
- /// </summary>
- /// <param name="Dir">Das Verzeichnis in das die Daten exportiert werden sollen</param>
- public void exportToDirectory(string Dir) {
- byte canExport = (byte)(this._settings | FilePackElements.eSet.ExportLocked);
- if (canExport != (byte)this._settings) {
- if (Directory.Exists(Dir) == false)
- Directory.CreateDirectory(Dir);
- foreach (FilePackElements.FPKeyWords kw in this.KeyWords) {
- string ext = this.Extensions[kw.FileExtension].Extensions;
- string FPath = Dir + (Dir.EndsWith(IO.Path.DirectorySeparatorChar.ToString()) ? "" : IO.Path.DirectorySeparatorChar.ToString()) + kw.Keyword + (!string.IsNullOrEmpty(ext) ? "." + ext : "");
- if (FPath.Contains(IO.Path.DirectorySeparatorChar.ToString())) {
- FileInfo fi = new FileInfo(FPath);
- if (fi.Directory.Exists == false)
- fi.Directory.Create();
- //Directory.CreateDirectory(fi.Directory)
- }
- if (IO.File.Exists(FPath) == false) {
- this.Cons("Export Data '" + kw.Keyword + (!string.IsNullOrEmpty(ext) ? "." + ext : "") + "' (" + kw.Length.ToString("#,##0") + " Bytes)");
- File.WriteAllBytes(FPath, this.getByteArray(kw));
- } else {
- this.Cons("File already exists '" + kw.Keyword + (!string.IsNullOrEmpty(ext) ? "." + ext : "") + "' (" + kw.Length.ToString("#,##0") + " Bytes)");
- }
- }
- } else {
- throw new System.Fire.FilePack.Exception.Exception_ExportLocked(this._filePath, this._streamBase.Length, (byte)SignatureVersion);
- }
- }
- /// <summary>
- /// Exportiert die Einträge des Archives in das angegebene Verzeichnis
- /// </summary>
- /// <param name="Dir">Das Verzeichnis in das die Daten exportiert werden sollen</param>
- /// <param name="Overwrite">Gibt an, ob existierende Dateien überschrieben werden sollen</param>
- public void exportToDirectory(string Dir, bool Overwrite) {
- byte canExport = (byte)(this._settings | FilePackElements.eSet.ExportLocked);
- if (canExport != (byte)this._settings) {
- if (Directory.Exists(Dir) == false)
- Directory.CreateDirectory(Dir);
- foreach (FilePackElements.FPKeyWords kw in this.KeyWords) {
- string ext = this.Extensions[kw.FileExtension].Extensions;
- this.Cons("Export Data '" + kw.Keyword + (!string.IsNullOrEmpty(ext) ? "." + ext : "") + "' (" + kw.Length.ToString("#,##0") + " Bytes)");
- if (IO.File.Exists(Dir + (Dir.EndsWith(IO.Path.DirectorySeparatorChar.ToString()) ? "" : IO.Path.DirectorySeparatorChar.ToString()) + kw.Keyword + (!string.IsNullOrEmpty(ext) ? "." + ext : "")) & Overwrite == true) {
- IO.File.Delete(Dir + (Dir.EndsWith(IO.Path.DirectorySeparatorChar.ToString()) ? "" : IO.Path.DirectorySeparatorChar.ToString()) + kw.Keyword + (!string.IsNullOrEmpty(ext) ? "." + ext : ""));
- } else if (IO.File.Exists(Dir + (Dir.EndsWith(IO.Path.DirectorySeparatorChar.ToString()) ? "" : IO.Path.DirectorySeparatorChar.ToString()) + kw.Keyword + (!string.IsNullOrEmpty(ext) ? "." + ext : "")) == false) {
- File.WriteAllBytes(Dir + (Dir.EndsWith(IO.Path.DirectorySeparatorChar.ToString()) ? "" : IO.Path.DirectorySeparatorChar.ToString()) + kw.Keyword + (!string.IsNullOrEmpty(ext) ? "." + ext : ""), this.getByteArray(kw));
- }
- }
- } else {
- throw new System.Fire.FilePack.Exception.Exception_ExportLocked(this._filePath, this._streamBase.Length, (byte)SignatureVersion);
- }
- }
- #endregion
- #region "Create"
- /// <summary>
- /// Erstellt ein Archiv im Parent-Directory anhand des Verzeichnises <para>DirPath</para>
- /// </summary>
- /// <param name="DirPath">Gibt das Verzeichnis an, das archiviert werden soll.</param>
- /// <param name="Version">Gibt die Version des Archives an.</param>
- public static void createFromDirectory(string DirPath, ref FilePackElements.eVersion Version) {
- string Destination = createFilepathFromDir(DirPath);
- createFromDirectory1(DirPath, Destination, Version, new FilePackElements.CreateSetting(true), false);
- }
- /// <summary>
- /// Erstellt ein Archiv im Parent-Directory mit Einstellungen anhand des Verzeichnises <para>DirPath</para>
- /// </summary>
- /// <param name="DirPath">Gibt das Verzeichnis an, das archiviert werden soll.</param>
- /// <param name="Version">Gibt die Version des Archives an.</param>
- /// <param name="Settings">Die Einstellungen unter denen das Archiv erstellt werden soll</param>
- public static void createFromDirectory(string DirPath, FilePackElements.eVersion Version, FilePackElements.CreateSetting Settings) {
- string Destination = createFilepathFromDir(DirPath);
- createFromDirectory1(DirPath, Destination, Version, Settings, false);
- }
- /// <summary>
- /// Erstellt ein Archiv im <para>DestinationFile</para> anhand des Verzeichnises <para>DirPath</para>
- /// </summary>
- /// <param name="DirPath">Gibt das Verzeichnis an, das archiviert werden soll.</param>
- /// <param name="DestinationFile">Gibt den Pfad des Zielarchives an.</param>
- /// <param name="Version">Gibt die Version des Archives an.</param>
- public static void createFromDirectory(string DirPath, string DestinationFile, FilePackElements.eVersion Version) {
- createFromDirectory1(DirPath, DestinationFile, Version, new FilePackElements.CreateSetting(true), false);
- }
- /// <summary>
- /// Erstellt ein Archiv im <para>DestinationFile</para> anhand des Verzeichnises <para>DirPath</para>
- /// </summary>
- /// <param name="DirPath">Gibt das Verzeichnis an, das archiviert werden soll.</param>
- /// <param name="DestinationFile">Gibt den Pfad des Zielarchives an.</param>
- /// <param name="Version">Gibt die Version des Archives an.</param>
- /// <param name="Settings">Die Einstellungen unter denen das Archiv erstellt werden soll</param>
- public static void createFromDirectory(string DirPath, string DestinationFile, FilePackElements.eVersion Version, FilePackElements.CreateSetting Settings) {
- createFromDirectory1(DirPath, DestinationFile, Version, Settings, false);
- }
- /// <summary>
- /// Erstellt ein Archiv im Parent-Directory anhand des Verzeichnises <para>DirPath</para>
- /// </summary>
- /// <param name="DirPath">Gibt das Verzeichnis an, das archiviert werden soll.</param>
- /// <param name="Version">Gibt die Version des Archives an.</param>
- /// <param name="Console">true, gibt die Ausgabe in der Console wieder</param>
- public static void createFromDirectory(string DirPath, FilePackElements.eVersion Version, bool Console) {
- string Destination = createFilepathFromDir(DirPath);
- createFromDirectory1(DirPath, Destination, Version, new FilePackElements.CreateSetting(true), Console);
- }
- /// <summary>
- /// Erstellt ein Archiv im Parent-Directory mit Einstellungen anhand des Verzeichnises <para>DirPath</para>
- /// </summary>
- /// <param name="DirPath">Gibt das Verzeichnis an, das archiviert werden soll.</param>
- /// <param name="Version">Gibt die Version des Archives an.</param>
- /// <param name="Settings">Die Einstellungen unter denen das Archiv erstellt werden soll</param>
- /// <param name="Console">true, gibt die Ausgabe in der Console wieder</param>
- public static void createFromDirectory(string DirPath, FilePackElements.eVersion Version, FilePackElements.CreateSetting Settings, bool Console) {
- string Destination = createFilepathFromDir(DirPath);
- createFromDirectory1(DirPath, Destination, Version, Settings, Console);
- }
- /// <summary>
- /// Erstellt ein Archiv im <para>DestinationFile</para> anhand des Verzeichnises <para>DirPath</para>
- /// </summary>
- /// <param name="DirPath">Gibt das Verzeichnis an, das archiviert werden soll.</param>
- /// <param name="DestinationFile">Gibt den Pfad des Zielarchives an.</param>
- /// <param name="Version">Gibt die Version des Archives an.</param>
- /// <param name="Console">true, gibt die Ausgabe in der Console wieder</param>
- public static void createFromDirectory(string DirPath, string DestinationFile, FilePackElements.eVersion Version, bool Console) {
- createFromDirectory1(DirPath, DestinationFile, Version, new FilePackElements.CreateSetting(true), Console);
- }
- /// <summary>
- /// Erstellt ein Archiv im <para>DestinationFile</para> anhand des Verzeichnises <para>DirPath</para>
- /// </summary>
- /// <param name="DirPath">Gibt das Verzeichnis an, das archiviert werden soll.</param>
- /// <param name="DestinationFile">Gibt den Pfad des Zielarchives an.</param>
- /// <param name="Version">Gibt die Version des Archives an.</param>
- /// <param name="Settings">Die Einstellungen unter denen das Archiv erstellt werden soll</param>
- /// <param name="Console">true, gibt die Ausgabe in der Console wieder</param>
- public static void createFromDirectory(string DirPath, string DestinationFile, FilePackElements.eVersion Version, FilePackElements.CreateSetting Settings, bool Console) {
- createFromDirectory1(DirPath, DestinationFile, Version, Settings, Console);
- }
- private static string createFilepathFromDir(string DirPath) {
- if (DirPath.EndsWith(IO.Path.DirectorySeparatorChar.ToString()))
- DirPath = DirPath.Substring(0, DirPath.Length - (IO.Path.DirectorySeparatorChar.ToString().Length));
- return DirPath + ".bfp";
- }
- private struct sFileInfo {
- private string _Extension;
- private byte _ExtensionIndex;
- private string _FileName;
- private string _AbsolutePath;
- private string _Name;
- private long _FileSize;
- private FilePackElements.DataType _Type;
- private string _Temp;
- public string Extension {
- get { return this._Extension; }
- set { this._Extension = value; }
- }
- public string Temp {
- get { return this._Temp; }
- set { this._Temp = value; }
- }
- public byte ExtensionIndex {
- get { return this._ExtensionIndex; }
- set { this._ExtensionIndex = value; }
- }
- public string FileName {
- get { return this._FileName; }
- set { this._FileName = value; }
- }
- public string AbsolutePath {
- get { return this._AbsolutePath; }
- set { this._AbsolutePath = value; }
- }
- public string Name {
- get { return this._Name; }
- set { this._Name = value; }
- }
- public long FileSize {
- get { return this._FileSize; }
- set { this._FileSize = value; }
- }
- public FilePackElements.DataType Type {
- get { return this._Type; }
- set { this._Type = value; }
- }
- }
- private static void createFromDirectory1(string DirPath, string Destination, FilePackElements.eVersion Version, FilePackElements.CreateSetting Settings, bool bCons) {
- if (File.Exists(Destination)) {
- throw new System.Fire.FilePack.Exception.Exception_ArchiveExists(Destination);
- //return;
- }
- IO.DirectoryInfo di = new IO.DirectoryInfo(DirPath);
- IO.FileStream fs = new IO.FileStream(Destination, FileMode.CreateNew);
- IO.BinaryWriter bw = new IO.BinaryWriter(fs);
- FilePackElements.eSet xsettings = 0;
- System.Text.Encoding enc = System.Text.Encoding.UTF8;
- if (Settings.DataGZip)
- xsettings = xsettings | FilePackElements.eSet.Data_GZip;
- if (Settings.Crypt)
- xsettings = xsettings | FilePackElements.eSet.Crypt;
- if (Settings.LockExport)
- xsettings = xsettings | FilePackElements.eSet.ExportLocked;
- if (Settings.TextGZip)
- xsettings = xsettings | FilePackElements.eSet.Text_GZip;
- if (Settings.UsePassword)
- xsettings = xsettings | FilePackElements.eSet.UsePassword;
- if (Settings.Extantions)
- xsettings = xsettings | FilePackElements.eSet.Extantions;
- FilePack.Cons("Create archive '" + di.Name + "' using password: " + (!string.IsNullOrEmpty(Settings.Password) & Settings.UsePassword ? "Yes" : "No"), bCons);
- bw.Write(System.Fire.FilePack.FilePack.Signature);
- bw.Write(Convert.ToByte(FilePackElements.eVersion.Version_1_0));
- bw.Write(Convert.ToByte(xsettings));
- bw.Write(Convert.ToByte(0));
- // 0 Kommentar-Felder
- bw.Write(FilePack.dateToBytes());
- if (Settings.UsePassword & !string.IsNullOrEmpty(Settings.Password))
- FilePack.writePW1(ref bw, Settings.Password);
- string[] f = { };
- if (DirPath.EndsWith(IO.Path.DirectorySeparatorChar.ToString()) == false)
- DirPath += IO.Path.DirectorySeparatorChar;
- getFileList(DirPath, ref f);
- string[] ext = { };
- sFileInfo[] FileInfos = { };
- int FileInfoCount = 0;
- // File Count
- ushort fc = 0;
- foreach (string s in f)
- if (s != DirPath) {
- FileInfo fi = new FileInfo(s);
- string itemName = fi.FullName.Substring(DirPath.Length, fi.FullName.Length - DirPath.Length - fi.Extension.Length);
- if (itemName.Length < 240)
- fc += 1;
- }
- bw.Write(fc);
- foreach (string s in f) {
- if (s != DirPath) {
- FileInfo fi = new FileInfo(s);
- byte extIndex = 0;
- if (Array.IndexOf(ext, fi.Extension.ToLower().Substring(1)) > -1) {
- for (byte i = 0; i < ext.Length; i++) {
- if (ext[i] == fi.Extension.ToLower().Substring(1)) {
- extIndex = i;
- break; // TODO: might not be correct. Was : Exit For
- }
- }
- } else {
- extIndex = (byte)ext.Length;
- Array.Resize(ref ext, extIndex + 1);
- ext[extIndex] = fi.Extension.ToLower().Substring(1);
- }
- string itemName = fi.FullName.Substring(DirPath.Length, fi.FullName.Length - DirPath.Length - ext[extIndex].Length - 1);
- // Pfad der geschrieben wird
- FilePackElements.DataType type = FilePack.getDataType(ext[extIndex]);
- // Maximal 240 Dateiendungen
- if (itemName.Length < 240) {
- Array.Resize(ref FileInfos, FileInfoCount + 1);
- FileInfos[FileInfoCount] = new sFileInfo();
- FileInfos[FileInfoCount].AbsolutePath = fi.FullName;
- FileInfos[FileInfoCount].Extension = ext[extIndex];
- FileInfos[FileInfoCount].ExtensionIndex = extIndex;
- FileInfos[FileInfoCount].FileName = fi.Name;
- FileInfos[FileInfoCount].FileSize = fi.Length;
- FileInfos[FileInfoCount].Name = itemName;
- FileInfos[FileInfoCount].Temp = System.IO.Path.GetTempFileName();
- FileInfos[FileInfoCount].Type = type;
- FilePack.Cons("Packe '" + fi.Name + "'", bCons);
- // Erstelle eine Temporäre Datei mit den Inhalten
- byte[] data = File.ReadAllBytes(fi.FullName);
- if ((Settings.DataGZip & (type == FilePackElements.DataType.dtBinaryData | type == FilePackElements.DataType.dtByteArray | type == FilePackElements.DataType.dtVideo | type == FilePackElements.DataType.dtUnsuportImage | type == FilePackElements.DataType.dtImage)) | (Settings.TextGZip & type == FilePackElements.DataType.dtString)) {
- IO.MemoryStream mem = new IO.MemoryStream();
- System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Compress);
- gz.Write(data, 0, data.Length);
- data = mem.ToArray();
- gz.Close();
- mem.Close();
- gz.Dispose();
- mem.Dispose();
- }
- if (Settings.Crypt) {
- if (Settings.UsePassword) {
- data = FilePack.Encode(data, Settings.Password);
- } else {
- data = FilePack.Encode(data, "");
- }
- FileInfos[FileInfoCount].FileSize = data.Length;
- }
- File.WriteAllBytes(FileInfos[FileInfoCount].Temp, data);
- // Trage die Daten in die ArchivDatei ein
- // Keyword Daten schreiben
- //Dim NameLen() As Byte = BitConverter.GetBytes(CByte(enc.GetBytes(FileInfos(FileInfoCount).Name).Length))
- byte[] FileSize = BitConverter.GetBytes(Convert.ToInt64(FileInfos[FileInfoCount].FileSize));
- //Dim FileType() As Byte = BitConverter.GetBytes(CByte(FileInfos(FileInfoCount).Type))
- byte[] FileNameBytes = enc.GetBytes(FileInfos[FileInfoCount].Name);
- fs.WriteByte((byte)enc.GetBytes(FileInfos[FileInfoCount].Name).Length);
- // NameLen
- //bw.Write(NameLen)
- bw.Write(FileSize);
- // Länge
- fs.WriteByte(Convert.ToByte(FileInfos[FileInfoCount].Type));
- // Type
- //bw.Write(FileType) ' Typ
- if (Settings.Extantions) {
- fs.WriteByte(Convert.ToByte(FileInfos[FileInfoCount].ExtensionIndex));
- } else {
- fs.WriteByte(Convert.ToByte(0));
- }
- bw.Write(FileNameBytes);
- FileInfoCount += 1;
- }
- }
- }
- if (Settings.Extantions) {
- bw.Write(Convert.ToByte(ext.Length));
- // Dateiendung (Anzahl)
- foreach (string e in ext) {
- bw.Write(Convert.ToByte(e.Length + 70));
- bw.Write(enc.GetBytes(e));
- }
- }
- FilePack.Cons("Schreibe Daten", bCons);
- if (FileInfos.Length > 0) {
- foreach (sFileInfo s in FileInfos) {
- bw.Write(File.ReadAllBytes(s.Temp));
- File.Delete(s.Temp);
- }
- }
- bw.Close();
- fs.Close();
- fs.Dispose();
- }
- /// <summary>
- /// Erstellt ein FilePack auf Basis eines Verzeichnisses.
- /// </summary>
- /// <param name="DirPath">Das Verzeichnis, dass Archiviert werden soll</param>
- /// <param name="Destination">Die Zieldatei</param>
- /// <remarks></remarks>
- public void Save(string DirPath, string Destination) {
- this.Save(DirPath, Destination, false);
- }
- /// <summary>
- /// Erstellt ein FilePack auf Basis eines Verzeichnisses.
- /// </summary>
- /// <param name="DirPath">Das Verzeichnis, dass Archiviert werden soll</param>
- /// <param name="Destination">Die Zieldatei</param>
- /// <param name="bCons">Soll die Statusmeldungen in der Output Console angezeigt werden</param>
- /// <remarks></remarks>
- public void Save(string DirPath, string Destination, bool bCons) {
- if (File.Exists(Destination)) {
- throw new System.Fire.FilePack.Exception.Exception_ArchiveExists(Destination);
- //return;
- }
- IO.DirectoryInfo di = new IO.DirectoryInfo(DirPath);
- IO.FileStream fs = new IO.FileStream(Destination, FileMode.CreateNew);
- IO.BinaryWriter bw = new IO.BinaryWriter(fs);
- System.Text.Encoding enc = System.Text.Encoding.UTF8;
- byte bpw = (byte)(this._settings | FilePackElements.eSet.UsePassword);
- bool bUsePW = (bpw == (byte)this._settings) && this._Password != "";
- bool bCrypt = (this._settings | FilePackElements.eSet.Crypt) == this._settings;
- bool bDataGZip = (this._settings | FilePackElements.eSet.Data_GZip) == this._settings;
- bool bTextGZip = (this._settings | FilePackElements.eSet.Text_GZip) == this._settings;
- bool bExtantions = (this._settings | FilePackElements.eSet.Extantions) == this._settings;
- FilePack.Cons("Create archive '" + di.Name + "' using password: " + (bUsePW ? "Yes" : "No"), bCons);
- FilePack.Cons("Using Filepack Version: " + this.SignatureVersion.ToString(), bCons);
- bw.Write(Signature);
- bw.Write(Convert.ToByte(this.SignatureVersion));
- bw.Write(Convert.ToByte(this._settings));
- bw.Write(Convert.ToByte(this._commentCount));
- // n Kommentar-Felder
- bw.Write(FilePack.dateToBytes());
- // Datum eintragen
- if (bUsePW)
- writePW1(ref bw, this._Password);
- string[] f = { };
- if (DirPath.EndsWith(IO.Path.DirectorySeparatorChar.ToString()) == false)
- DirPath += IO.Path.DirectorySeparatorChar;
- getFileList(DirPath, ref f);
- string[] ext = { };
- sFileInfo[] FileInfos = { };
- int FileInfoCount = 0;
- bw.Write(Convert.ToByte(this.keyCount));
- // Keyword Count
- foreach (string s in f) {
- if (s != DirPath) {
- FileInfo fi = new FileInfo(s);
- byte extIndex = 0;
- if (Array.IndexOf(ext, fi.Extension.ToLower().Substring(1)) > -1) {
- for (byte i = 0; i < ext.Length; i++) {
- if (ext[i] == fi.Extension.ToLower().Substring(1)) {
- extIndex = i;
- break; // TODO: might not be correct. Was : Exit For
- }
- }
- } else {
- extIndex = (byte)ext.Length;
- Array.Resize(ref ext, extIndex + 1);
- ext[extIndex] = fi.Extension.ToLower().Substring(1);
- }
- string itemName = fi.FullName.Substring(DirPath.Length, fi.FullName.Length - DirPath.Length - ext[extIndex].Length - 1);
- // Pfad der geschrieben wird
- FilePackElements.DataType type = getDataType(ext[extIndex]);
- // Maximal 240 Dateiendungen
- if (itemName.Length < 240) {
- Array.Resize(ref FileInfos, FileInfoCount + 1);
- FileInfos[FileInfoCount] = new sFileInfo();
- FileInfos[FileInfoCount].AbsolutePath = fi.FullName;
- FileInfos[FileInfoCount].Extension = ext[extIndex];
- FileInfos[FileInfoCount].ExtensionIndex = extIndex;
- FileInfos[FileInfoCount].FileName = fi.Name;
- FileInfos[FileInfoCount].FileSize = fi.Length;
- FileInfos[FileInfoCount].Name = itemName;
- FileInfos[FileInfoCount].Temp = System.IO.Path.GetTempFileName();
- FileInfos[FileInfoCount].Type = type;
- FilePack.Cons("Packe '" + fi.Name + "'", bCons);
- // Erstelle eine Temporäre Datei mit den Inhalten
- byte[] data = File.ReadAllBytes(fi.FullName);
- if ((bDataGZip & (type == FilePackElements.DataType.dtBinaryData | type == FilePackElements.DataType.dtByteArray | type == FilePackElements.DataType.dtVideo | type == FilePackElements.DataType.dtUnsuportImage | type == FilePackElements.DataType.dtImage)) | (bTextGZip & type == FilePackElements.DataType.dtString)) {
- IO.MemoryStream mem = new IO.MemoryStream();
- System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Compress);
- gz.Write(data, 0, data.Length);
- data = mem.ToArray();
- gz.Close();
- mem.Close();
- gz.Dispose();
- mem.Dispose();
- }
- if (bCrypt) {
- if (bUsePW) {
- data = FilePack.Encode(data, this._Password);
- } else {
- data = FilePack.Encode(data, "");
- }
- FileInfos[FileInfoCount].FileSize = data.Length;
- }
- File.WriteAllBytes(FileInfos[FileInfoCount].Temp, data);
- // Trage die Daten in die ArchivDatei ein
- // Keyword Daten schreiben
- //Dim NameLen() As Byte = BitConverter.GetBytes(CByte(enc.GetBytes(FileInfos(FileInfoCount).Name).Length))
- byte[] FileSize = BitConverter.GetBytes(Convert.ToInt64(FileInfos[FileInfoCount].FileSize));
- //Dim FileType() As Byte = BitConverter.GetBytes(CByte(FileInfos(FileInfoCount).Type))
- byte[] FileNameBytes = enc.GetBytes(FileInfos[FileInfoCount].Name);
- fs.WriteByte((byte)enc.GetBytes(FileInfos[FileInfoCount].Name).Length);
- // NameLen
- //bw.Write(NameLen)
- bw.Write(FileSize);
- // Länge
- fs.WriteByte(Convert.ToByte(FileInfos[FileInfoCount].Type));
- // Type
- //bw.Write(FileType) ' Typ
- if (bExtantions) {
- fs.WriteByte(Convert.ToByte(FileInfos[FileInfoCount].ExtensionIndex));
- } else {
- fs.WriteByte(Convert.ToByte(0));
- }
- bw.Write(FileNameBytes);
- FileInfoCount += 1;
- }
- }
- }
- if (bExtantions) {
- bw.Write(Convert.ToByte(ext.Length));
- // Dateiendung (Anzahl)
- foreach (string e in ext) {
- bw.Write(Convert.ToByte(e.Length + 70));
- bw.Write(enc.GetBytes(e));
- }
- }
- FilePack.Cons("Schreibe Daten", bCons);
- if (FileInfos.Length > 0) {
- foreach (sFileInfo s in FileInfos) {
- bw.Write(File.ReadAllBytes(s.Temp));
- File.Delete(s.Temp);
- }
- }
- bw.Close();
- fs.Close();
- fs.Dispose();
- }
- private static FilePackElements.DataType getDataType(string FileExt) {
- switch (FileExt) {
- // Typ
- case "jpg":
- return FilePackElements.DataType.dtImage;
- case "jpeg":
- return FilePackElements.DataType.dtImage;
- case "gif":
- return FilePackElements.DataType.dtImage;
- case "png":
- return FilePackElements.DataType.dtImage;
- case "bmp":
- return FilePackElements.DataType.dtImage;
- case "dds":
- return FilePackElements.DataType.dtUnsuportImage;
- case "tif":
- return FilePackElements.DataType.dtUnsuportImage;
- case "cr2":
- return FilePackElements.DataType.dtUnsuportImage;
- case "tiff":
- return FilePackElements.DataType.dtUnsuportImage;
- case "dwf":
- return FilePackElements.DataType.dtUnsuportImage;
- case "dwg":
- return FilePackElements.DataType.dtUnsuportImage;
- case "dxf":
- return FilePackElements.DataType.dtUnsuportImage;
- case "3ds":
- return FilePackElements.DataType.dtUnsuportImage;
- case "mov":
- return FilePackElements.DataType.dtVideo;
- case "mpg":
- return FilePackElements.DataType.dtVideo;
- case "mp4":
- return FilePackElements.DataType.dtVideo;
- case "wmv":
- return FilePackElements.DataType.dtVideo;
- case "avi":
- return FilePackElements.DataType.dtVideo;
- case "mpeg":
- return FilePackElements.DataType.dtVideo;
- case "txt":
- return FilePackElements.DataType.dtString;
- case "log":
- return FilePackElements.DataType.dtString;
- case "wav":
- return FilePackElements.DataType.dtAudio;
- case "mp3":
- return FilePackElements.DataType.dtAudio;
- case "ogg":
- return FilePackElements.DataType.dtAudio;
- case "wma":
- return FilePackElements.DataType.dtAudio;
- case "js":
- return FilePackElements.DataType.dtSourceCode;
- case "vbs":
- return FilePackElements.DataType.dtSourceCode;
- case "html":
- return FilePackElements.DataType.dtSourceCode;
- case "css":
- return FilePackElements.DataType.dtSourceCode;
- case "c":
- return FilePackElements.DataType.dtSourceCode;
- case "cpp":
- return FilePackElements.DataType.dtSourceCode;
- case "h":
- return FilePackElements.DataType.dtSourceCode;
- case "vb":
- return FilePackElements.DataType.dtSourceCode;
- case "cs":
- return FilePackElements.DataType.dtSourceCode;
- case "vbproj":
- return FilePackElements.DataType.dtSourceCode;
- case "csproj":
- return FilePackElements.DataType.dtSourceCode;
- case "settings":
- return FilePackElements.DataType.dtSourceCode;
- case "xml":
- return FilePackElements.DataType.dtSourceCode;
- case "xls":
- return FilePackElements.DataType.dtSourceCode;
- case "resx":
- return FilePackElements.DataType.dtSourceCode;
- case "vcxproj":
- return FilePackElements.DataType.dtSourceCode;
- case "php":
- return FilePackElements.DataType.dtSourceCode;
- case "php3":
- return FilePackElements.DataType.dtSourceCode;
- case "php4":
- return FilePackElements.DataType.dtSourceCode;
- case "php5":
- return FilePackElements.DataType.dtSourceCode;
- case "php6":
- return FilePackElements.DataType.dtSourceCode;
- case "sln":
- return FilePackElements.DataType.dtSourceCode;
- case "ini":
- return FilePackElements.DataType.dtConfiguration;
- case "inf":
- return FilePackElements.DataType.dtConfiguration;
- case "dll":
- return FilePackElements.DataType.dtExecuteable;
- case "exe":
- return FilePackElements.DataType.dtExecuteable;
- case "com":
- return FilePackElements.DataType.dtExecuteable;
- case "bas":
- return FilePackElements.DataType.dtExecuteable;
- case "lib":
- return FilePackElements.DataType.dtExecuteable;
- default:
- return FilePackElements.DataType.dtBinaryData;
- }
- }
- private static void getFileList(string sPath, ref string[] sFiles) {
- FileSystemInfo[] FSIs = new DirectoryInfo(sPath).GetFileSystemInfos();
- foreach (FileSystemInfo FSI in FSIs) {
- if (sFiles.Length < FileLimit) {
- if (FSI is DirectoryInfo) {
- getFileList(FSI.FullName + IO.Path.DirectorySeparatorChar.ToString(), ref sFiles);
- } else {
- int x = sFiles.Length;
- Array.Resize(ref sFiles, x + 1);
- sFiles[x] = FSI.FullName;
- }
- }
- }
- }
- #endregion
- #region "Date Functions"
- private const int BaseYear = 1950;
- private static byte[] dateToBytes() {
- return FilePack.bitsToBytes(FilePack.dateToBits());
- }
- private static byte[] dateToBytes(ref System.DateTime xDate) {
- return FilePack.bitsToBytes(FilePack.dateToBits(xDate));
- }
- private static bool[] dateToBits() {
- return FilePack.dateToBits(System.DateTime.UtcNow);
- }
- private static bool[] dateToBits(System.DateTime xDate) {
- int xyear = xDate.Year - FilePack.BaseYear;
- bool[] bits = new bool[40];
- if (xDate.Kind != DateTimeKind.Utc)
- xDate = xDate.ToUniversalTime();
- // Year
- for (int i = 0; i <= 8; i++) {
- int x = (xyear | ((int)Math.Pow(2, i)));
- bits[8 - i] = x == xyear;
- }
- // Month
- for (int i = 0; i <= 4; i++) {
- int x = (xDate.Month | (int)(Math.Pow(2, i)));
- bits[13 - i] = x == xDate.Month;
- }
- // Day
- for (int i = 0; i <= 5; i++) {
- int x = (xDate.Day | (int)(Math.Pow(2, i)));
- bits[19 - i] = x == xDate.Day;
- }
- // Hour
- for (int i = 0; i <= 5; i++) {
- int x = (xDate.Hour | (int)(Math.Pow(2, i)));
- bits[25 - i] = x == xDate.Hour;
- }
- // Minute
- for (int i = 0; i <= 6; i++) {
- int x = (xDate.Minute | (int)(Math.Pow(2, i)));
- bits[32 - i] = x == xDate.Minute;
- }
- // Seconds
- for (int i = 0; i <= 6; i++) {
- int x = (xDate.Second | (int)(Math.Pow(2, i)));
- bits[39 - i] = x == xDate.Second;
- }
- return bits;
- }
- private static byte[] bitsToBytes(bool[] b) {
- byte[] tmp = new byte[((int)Math.Ceiling((decimal)(b.Length / 8)))];
- for (int i = 0; i < Math.Ceiling((decimal)(b.Length / 8)); i++) {
- for (int j = 0; j <= 7; j++) {
- if (b.Length > (i * 8) + j)
- if (b[(i * 8) + j])
- tmp[i] = (byte)(tmp[i] | (byte)(Math.Pow(2, j)));
- }
- }
- return tmp;
- }
- private static bool[] bytesToBits(byte[] b) {
- bool[] tmp = new bool[(b.Length * 8)];
- for (int i = 0; i < b.Length; i++) {
- for (int j = 0; j <= 7; j++) {
- byte bIs = (byte)(b[i] | (byte)(Math.Pow(2, j)));
- tmp[(i * 8) + j] = bIs == b[i];
- }
- }
- return tmp;
- }
- private static System.DateTime bitsToDate(byte[] b) {
- return FilePack.bitsToDate(FilePack.bytesToBits(b));
- }
- private static System.DateTime bitsToDate(bool[] b) {
- int iDay = 0;
- int iMonth = 0;
- int iYear = 0;
- int iHours = 0;
- int iMinutes = 0;
- int iSeconds = 0;
- // Year
- for (int i = 0; i <= 8; i++) {
- if (b[8 - i] == true)
- iYear = iYear | (int)(Math.Pow(2, i));
- }
- // Month
- for (int i = 0; i <= 4; i++) {
- if (b[13 - i] == true)
- iMonth = iMonth | (int)(Math.Pow(2, i));
- }
- // Day
- for (int i = 0; i <= 5; i++) {
- if (b[19 - i] == true)
- iDay = iDay | (int)(Math.Pow(2, i));
- }
- // Hour
- for (int i = 0; i <= 5; i++) {
- if (b[25 - i] == true)
- iHours = iHours | (int)(Math.Pow(2, i));
- }
- // Minutes
- for (int i = 0; i <= 6; i++) {
- if (b[32 - i] == true)
- iMinutes = iMinutes | (int)(Math.Pow(2, i));
- }
- // Seconds
- for (int i = 0; i <= 6; i++) {
- if (b[39 - i] == true)
- iSeconds = iSeconds | (int)(Math.Pow(2, i));
- }
- return new System.DateTime(iYear + FilePack.BaseYear, iMonth, iDay, iHours, iMinutes, iSeconds, System.DateTimeKind.Utc);
- }
- #endregion
- #region "Shared Functions"
- /// <summary>
- /// Überprüft ob das Archiv <para>Filepath</para> gültig ist
- /// </summary>
- /// <param name="Filepath">Gibt den Pfad des Archives an.</param>
- /// <returns>Gibt bei erfolgreicher Prüfung true zurück. false falls das Archiv nicht gültig ist.</returns>
- public static bool IsValide(string Filepath) {
- if (File.Exists(Filepath)) {
- FileStream tstream = new FileStream(Filepath, FileMode.Open);
- if (tstream.Length < 17) {
- tstream.Close();
- tstream.Dispose();
- return false;
- } else {
- BinaryReader tb = new BinaryReader(tstream);
- byte[] s = tb.ReadBytes(10);
- if (FilePack.checkSignature(s)) {
- FilePackElements.eVersion SignatureVersion = (FilePackElements.eVersion)tb.ReadByte();
- tb.Close();
- tstream.Close();
- tstream.Dispose();
- switch (SignatureVersion) {
- case FilePackElements.eVersion.Version_1_0:
- return true;
- default:
- return false;
- }
- } else {
- tb.Close();
- tstream.Close();
- tstream.Dispose();
- return false;
- }
- }
- } else {
- return false;
- }
- }
- /// <summary>
- /// Gibt die Archiv-Version der angegebenen Datei zurück.
- /// </summary>
- /// <param name="Filepath">Gibt den Pfad des Archives an.</param>
- /// <returns>Gibt die Archiv-Version der angegebenen Datei zurück.</returns>
- public static FilePackElements.eVersion GetFileVersion(string Filepath) {
- if (File.Exists(Filepath)) {
- FileStream tstream = new FileStream(Filepath, FileMode.Open);
- if (tstream.Length < 17) {
- tstream.Close();
- tstream.Dispose();
- return FilePackElements.eVersion.Unsuported;
- } else {
- BinaryReader tb = new BinaryReader(tstream);
- byte[] s = tb.ReadBytes(10);
- if (FilePack.checkSignature(s)) {
- FilePackElements.eVersion sv = (FilePackElements.eVersion)tb.ReadByte();
- tb.Close();
- tstream.Close();
- tstream.Dispose();
- return sv;
- } else {
- tb.Close();
- tstream.Close();
- tstream.Dispose();
- return FilePackElements.eVersion.Unsuported;
- }
- }
- } else {
- return FilePackElements.eVersion.Unsuported;
- }
- }
- /// <summary>
- /// Überprüft das angegebene Archiv <para>Filepath</para> ob dieses mit einem Passwort geschützt ist.
- /// </summary>
- /// <param name="Filepath">Gibt den Pfad des Archives an.</param>
- /// <returns>true, wenn das angegebene Archiv mit einem Passwort geschützt ist. false wenn das Archiv nicht mit einem Passwort geschützt ist.</returns>
- public static bool IsPasswordProtectedFile(string Filepath) {
- if (File.Exists(Filepath)) {
- FileStream tstream = new FileStream(Filepath, FileMode.Open);
- if (tstream.Length < 17) {
- tstream.Close();
- tstream.Dispose();
- return false;
- } else {
- BinaryReader tb = new BinaryReader(tstream);
- byte[] s = tb.ReadBytes(10);
- if (FilePack.checkSignature(s)) {
- tb.ReadByte();
- FilePackElements.eSet xset = (FilePackElements.eSet)tb.ReadByte();
- byte upw = (byte)(xset | FilePackElements.eSet.UsePassword);
- tb.Close();
- tstream.Close();
- tstream.Dispose();
- return (upw == (byte)xset);
- } else {
- tb.Close();
- tstream.Close();
- tstream.Dispose();
- return false;
- }
- }
- } else {
- return false;
- }
- }
- #endregion
- }
- }
|