FilePack.cs 106 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313
  1. using System;
  2. using System.Drawing;
  3. using System.Text;
  4. using System.IO;
  5. using System.Fire.FilePack.Exception;
  6. using System.IO.Compression;
  7. namespace System.Fire.FilePack {
  8. public class FilePack : IDisposable {
  9. private UInt16 keyCount;
  10. private string _filePath;
  11. private FilePackElements.FPKeyWords[] KeyWords;
  12. private bool bOpened;
  13. private BinaryReader _stream;
  14. private FileStream _streamBase;
  15. private bool disposed = false;
  16. private string _Password = "";
  17. private FilePackElements.eSet _settings;
  18. private FilePackElements.FileExtension[] Extensions;
  19. private DateTime _date;
  20. private FilePackElements.FPComment[] _comments;
  21. private byte _commentCount = 0;
  22. /// <summary>
  23. /// Signatur Ascii Array
  24. /// </summary>
  25. public static byte[] Signature = new byte[] { 70, 105, 108, 101, 80, 97, 99, 107, 66, 80 };
  26. /// <summary>
  27. /// Signature Version
  28. /// </summary>
  29. public FilePackElements.eVersion SignatureVersion = FilePackElements.eVersion.Version_1_0;
  30. private bool bConsole = false;
  31. /// <summary>Limit if File Items</summary>
  32. public const UInt16 FileLimit = 32767;
  33. /// <summary>Limit for the maximum comment count</summary>
  34. public const byte MaxCommentCount = 100;
  35. // Header Structur
  36. // Bytes Typ Name
  37. // 10 Byte() Signature (Fix)
  38. // 1 Byte Version
  39. // 1 eSet Einstellungen 1
  40. // 1 Byte Anzahl "Comment" Felder
  41. // 5 Byte() Datum
  42. // [1] Byte Prüfsumme - Wenn Passwort gesetzt
  43. // [1] Byte Prüfsumme + (Länge MOD 5) + ASC(PW{1}) - Wenn Passwort gesetzt
  44. // [1] Byte CheckSumme - Wenn Passwort gesetzt
  45. // 2 Int16 Anzahl Einträge
  46. // n FPKeyWords(n) Einträge
  47. // 1 Byte Anzahl Dateiendungen
  48. // n FileExtantion Dateiendungen
  49. #region "Class Functions"
  50. /// <summary>Erstellt ein neues FilePack Objekt</summary>
  51. /// <param name="FilePath">Pfad und Name der FilePack-Datei</param>
  52. public FilePack(string FilePath) {
  53. System.Diagnostics.Debug.WriteLine("Create Filepack(\"" + FilePath + "\")");
  54. this.Create(FilePath, "");
  55. }
  56. /// <summary>Erstellt ein neues FilePack Objekt</summary>
  57. /// <param name="FilePath">Pfad und Name der FilePack-Datei</param>
  58. /// <param name="Password">Setzt ein Passwort zum entschlüsseln geschützter Archive</param>
  59. public FilePack(string FilePath, string Password) {
  60. System.Diagnostics.Debug.WriteLine("Create Filepack(\"" + FilePath + "\", \"" + Password + "\")");
  61. this.Create(FilePath, Password);
  62. }
  63. /// <summary>Erstellt ein neues FilePack Objekt</summary>
  64. /// <param name="FilePath">Pfad und Name der FilePack-Datei</param>
  65. /// <param name="UseConsole">Consoleneinträge werden erstellt</param>
  66. public FilePack(string FilePath, bool UseConsole) {
  67. System.Diagnostics.Debug.WriteLine("Create Filepack(\"" + FilePath + "\", " + (UseConsole ? "True" : "False") + ")");
  68. this.Create(FilePath, "");
  69. this.bConsole = UseConsole;
  70. }
  71. /// <summary>Erstellt ein neues FilePack Objekt</summary>
  72. /// <param name="FilePath">Pfad und Name der FilePack-Datei</param>
  73. /// <param name="Password">Setzt ein Passwort zum entschlüsseln geschützter Archive</param>
  74. /// <param name="UseConsole">Consoleneinträge werden erstellt</param>
  75. public FilePack(string FilePath, string Password, bool UseConsole) {
  76. System.Diagnostics.Debug.WriteLine("Create Filepack(\"" + FilePath + "\", \"" + Password + "\", " + (UseConsole ? "True" : "False") + ")");
  77. this.Create(FilePath, Password);
  78. this.bConsole = UseConsole;
  79. }
  80. /// <summary>Erstellt ein neues FilePack Objekt</summary>
  81. /// <param name="FS">Dateistream</param>
  82. public FilePack(FileStream FS) {
  83. this.Create(FS, "");
  84. }
  85. /// <summary>Erstellt ein neues FilePack Objekt</summary>
  86. /// <param name="FS">Dateistream</param>
  87. /// <param name="Password">Setzt ein Passwort zum entschlüsseln geschützter Archive</param>
  88. public FilePack(FileStream FS, string Password) {
  89. this.Create(FS, Password);
  90. }
  91. /// <summary>Erstellt ein neues FilePack Objekt</summary>
  92. /// <param name="FS">Dateistream</param>
  93. /// <param name="UseConsole">Consoleneinträge werden erstellt</param>
  94. public FilePack(FileStream FS, bool UseConsole) {
  95. this.Create(FS, "");
  96. this.bConsole = UseConsole;
  97. }
  98. /// <summary>Erstellt ein neues FilePack Objekt</summary>
  99. /// <param name="FS">Dateistream</param>
  100. /// <param name="Password">Setzt ein Passwort zum entschlüsseln geschützter Archive</param>
  101. /// <param name="UseConsole">Consoleneinträge werden erstellt</param>
  102. public FilePack(FileStream FS, string Password, bool UseConsole) {
  103. this.Create(FS, Password);
  104. this.bConsole = UseConsole;
  105. }
  106. ~FilePack() {
  107. this.Dispose(false);
  108. }
  109. /// <summary>
  110. /// Gibt sämmtliche von FilePack verwendete Ressourcen frei
  111. /// </summary>
  112. public virtual void Dispose() {
  113. Dispose(true);
  114. GC.SuppressFinalize(this);
  115. bOpened = false;
  116. }
  117. /// <summary>
  118. /// Gibt die von FilePack und den untergeordneten Klassen verwednete Ressourcen, nicht verwalteten Ressourcen und optional auch die verwalteten Ressourcen frei.
  119. /// </summary>
  120. /// <param name="disposing">true, um sowohl die verwalteten als auch die nicht verwalteten Ressourcen freizugeben. false um ausschließlich die verwalteten Ressourcen freizugeben.</param>
  121. public virtual void Dispose(bool disposing) {
  122. if (disposed == false) {
  123. if (disposing) {
  124. if (this._stream != null)
  125. this._stream.Close();
  126. if (this._streamBase != null)
  127. this._streamBase.Close();
  128. if (this._streamBase != null)
  129. this._streamBase.Dispose();
  130. this._stream = null;
  131. this._streamBase = null;
  132. disposed = true;
  133. }
  134. this.Close();
  135. this._filePath = "";
  136. }
  137. }
  138. public void Cons(string str) {
  139. if (this.bConsole)
  140. Console.WriteLine(str);
  141. }
  142. public static void Cons(string str, bool bConsole) {
  143. if (bConsole)
  144. Console.WriteLine(str);
  145. }
  146. #endregion
  147. #region "This Property"
  148. public string this[string Name] {
  149. get { return this.getText(Name); }
  150. }
  151. public string this[FilePackElements.FPKeyWords Keyword] {
  152. get { return this.getText(Keyword); }
  153. }
  154. #endregion
  155. #region "Propertys"
  156. /// <summary>Gibt eine Auflistung der Keywords zurück</summary>
  157. /// <returns>Gibt eine Auflistung der Keywords im FPKeywords Object zurück</returns>
  158. public FilePackElements.FPKeyWords[] Keyword() {
  159. return this.KeyWords;
  160. }
  161. /// <summary>Gibt das dem Index entsprechende Keywords zurück</summary>
  162. /// <param name="Index">Index des Keywords</param>
  163. /// <returns>Gibt das dem Index entsprechende Keyword im FPKeywords Object zurück</returns>
  164. public FilePackElements.FPKeyWords Keyword(short Index) {
  165. return this.KeyWords[Index];
  166. }
  167. /// <summary>Gibt das dem Index entsprechende Keywords zurück</summary>
  168. /// <param name="Index">Index des Keywords</param>
  169. /// <returns>Gibt das dem Index entsprechende Keyword im FPKeywords Object zurück</returns>
  170. public FilePackElements.FPKeyWords Keyword(int Index) {
  171. return this.KeyWords[Index];
  172. }
  173. /// <summary>Gibt das dem Namen entsprechende Keywords zurück</summary>
  174. /// <param name="Name">Name des Keywords</param>
  175. /// <returns>Gibt das dem Namen entsprechende Keyword im FPKeywords Object zurück</returns>
  176. public FilePackElements.FPKeyWords Keyword(string Name) {
  177. return this.getKeywordByName(Name);
  178. }
  179. /// <summary>Gibt die Anzahl der geladenen Keywords zurück</summary>
  180. /// <returns>Gibt die Anzahl der geladenen Keywords zurück</returns>
  181. public ushort Length {
  182. get { return this.keyCount; }
  183. }
  184. /// <summary>Gibt das Erstellungsdatum des Archives zurück</summary>
  185. /// <returns>Gibt das Erstellungsdatum des Archives als Date-Object zurück</returns>
  186. public DateTime CreateDate {
  187. get { return this._date; }
  188. }
  189. /// <summary>Gibt die Einstellungen des geladenen Archivs zurück</summary>
  190. /// <returns>Gibt die Einstellungen des geladenen Archivs als eSet Objekt zurück</returns>
  191. public FilePackElements.eSet Settings {
  192. get { return this._settings; }
  193. }
  194. public FilePackElements.FileExtension Extension(byte ID) {
  195. byte uext = (byte)(this._settings | FilePackElements.eSet.Extantions);
  196. if (uext == (byte)this._settings)
  197. return this.Extensions[ID];
  198. else
  199. return new FilePackElements.FileExtension("");
  200. }
  201. #endregion
  202. #region "Load"
  203. /// <summary>Öffnet ein FilePack Archiv</summary>
  204. /// <param name="FilePath">Pfad zu dem FilePack Archiv</param>
  205. public void Load(string FilePath) {
  206. this.Create(FilePath, "");
  207. }
  208. /// <summary>Öffnet ein FilePack Archiv</summary>
  209. /// <param name="FilePath">Pfad zu dem FilePack Archiv</param>
  210. /// <param name="Password">Setzt ein Passwort zum entschlüsseln geschützter Archive</param>
  211. public void Load(string FilePath, string Password) {
  212. this.Create(FilePath, Password);
  213. }
  214. /// <summary>Öffnet ein FilePack Archiv</summary>
  215. /// <param name="Stream">Datei-Stream des FilePack Archives</param>
  216. public void Load(FileStream Stream) {
  217. this.Create(Stream, "");
  218. }
  219. /// <summary>Öffnet ein FilePack Archiv</summary>
  220. /// <param name="Stream">Datei-Stream des FilePack Archives</param>
  221. /// <param name="Password">Setzt ein Passwort zum entschlüsseln geschützter Archive</param>
  222. public void Load(FileStream Stream, string Password) {
  223. this.Create(Stream, Password);
  224. }
  225. /// <summary>
  226. ///
  227. /// </summary>
  228. /// <param name="FilePath"></param>
  229. /// <param name="Password"></param>
  230. /// <exception cref="System.IO.FileNotFoundException">File not found</exception>
  231. private void Create(string FilePath, string Password) {
  232. System.Diagnostics.Debug.WriteLine("Create called: " + FilePath + (Password != "" ? ":" + Password : ""));
  233. if (this.bOpened == true) this.Close();
  234. if (File.Exists(FilePath)) {
  235. this.Cons("Open archive. Using password: " + (Password == "" ? "No" : "Yes"));
  236. this._streamBase = new FileStream(FilePath, FileMode.Open, FileAccess.Read);
  237. this._stream = new BinaryReader(this._streamBase, System.Text.Encoding.ASCII);
  238. this._filePath = FilePath;
  239. this._Password = Password;
  240. if (_streamBase.Length < 17) {
  241. this._filePath = "";
  242. this._Password = "";
  243. this._stream.Close();
  244. this._streamBase.Close();
  245. this._streamBase.Dispose();
  246. throw new Exception_Filesize(this._filePath, this._streamBase.Length);
  247. } else {
  248. byte[] s = this._stream.ReadBytes(10);
  249. if (checkSignature(s)) {
  250. SignatureVersion = (FilePackElements.eVersion)this._stream.ReadByte();
  251. this.bOpened = true;
  252. System.Diagnostics.Debug.WriteLine("File Signature: " + SignatureVersion.ToString());
  253. switch (SignatureVersion) {
  254. case FilePackElements.eVersion.Version_1_0:
  255. createVersion1();
  256. break;
  257. default:
  258. this._filePath = "";
  259. this._Password = "";
  260. this._stream.Close();
  261. this._streamBase.Close();
  262. this._streamBase.Dispose();
  263. throw new Exception_UnsportVersion(this._filePath, this._streamBase.Length, (byte)SignatureVersion);
  264. }
  265. } else
  266. throw new Exception_Signature(this._filePath, this._streamBase.Length);
  267. }
  268. } else
  269. throw new IO.FileNotFoundException("Datei konnte nicht gefunden werden\r\n" + FilePath, FilePath);
  270. }
  271. private void Create(FileStream Stream, string Password) {
  272. if (this.bOpened == true) this.Close();
  273. this.Cons("Open archive. Using password: " + (Password == "" ? "No" : "Yes"));
  274. this._streamBase = Stream;
  275. this._stream = new BinaryReader(this._streamBase, Text.Encoding.ASCII);
  276. this._filePath = Stream.Name;
  277. this._Password = Password;
  278. if (_streamBase.Length < 17) {
  279. this._filePath = "";
  280. this._Password = "";
  281. this._stream.Close();
  282. this._streamBase.Close();
  283. this._streamBase.Dispose();
  284. throw new Exception_Filesize(this._filePath, this._streamBase.Length);
  285. } else {
  286. byte[] s = this._stream.ReadBytes(10);
  287. if (checkSignature(s)) {
  288. SignatureVersion = (FilePackElements.eVersion)this._stream.ReadByte();
  289. this.bOpened = true;
  290. switch (SignatureVersion) {
  291. case FilePackElements.eVersion.Version_1_0:
  292. createVersion1();
  293. break;
  294. default:
  295. this._filePath = "";
  296. this._Password = "";
  297. this._stream.Close();
  298. this._streamBase.Close();
  299. this._streamBase.Dispose();
  300. throw new Exception_UnsportVersion(this._filePath, this._streamBase.Length, (byte)SignatureVersion);
  301. }
  302. } else
  303. throw new Exception_Signature(this._filePath, this._streamBase.Length);
  304. }
  305. }
  306. private void createVersion1() {
  307. this._settings = (FilePackElements.eSet)this._stream.ReadByte();
  308. this._commentCount = this._stream.ReadByte();
  309. this._date = FilePack.bitsToDate(this._stream.ReadBytes(5));
  310. System.Diagnostics.Debug.WriteLine("Header Info 1 - Settings: " + this._settings.ToString() + "; commentCount: " + this._commentCount + "; date: " + this._date.ToLongDateString());
  311. if (checkPW1()) {
  312. this.keyCount = this._stream.ReadUInt16();
  313. this.KeyWords = new FilePackElements.FPKeyWords[this.keyCount];
  314. System.Diagnostics.Debug.WriteLine("Header Info 2 - keyCount: " + this.keyCount);
  315. for (int i = 0; i < this.keyCount; i++)
  316. this.KeyWords[i] = new FilePackElements.FPKeyWords(this._stream);
  317. FilePackElements.eSet useExt = (this._settings | FilePackElements.eSet.Extantions);
  318. byte extCount = 0;
  319. if (useExt == this._settings) {
  320. extCount = this._stream.ReadByte();
  321. this.Extensions = new FilePackElements.FileExtension[extCount];
  322. for (int j = 0; j < extCount; j++)
  323. this.Extensions[j] = new FilePackElements.FileExtension(this._stream);
  324. }
  325. System.Diagnostics.Debug.WriteLine("Header Info 3 - useExt: " + (useExt == this._settings ? "True" : "False") + "; extCount: " + extCount);
  326. long off = this._streamBase.Position;
  327. for (int i = 0; i < this.keyCount; i++) {
  328. this.KeyWords[i].Offset = off;
  329. off += this.KeyWords[i].Length;
  330. }
  331. this.Cons("Data Count: " + this.keyCount);
  332. if (this._commentCount > 0) {
  333. this._comments = new FilePackElements.FPComment[this._commentCount - 1];
  334. for (int i = 0; i < this._commentCount; i++)
  335. this._comments[i] = new FilePackElements.FPComment(this._stream);
  336. }
  337. }
  338. }
  339. /// <summary>
  340. /// Schließt das Archiv und gibt den Stream frei
  341. /// </summary>
  342. /// <remarks></remarks>
  343. public void Close() {
  344. if (this._stream != null)
  345. this._stream.Close();
  346. if (this._streamBase != null)
  347. this._streamBase.Close();
  348. if (this._streamBase != null)
  349. this._streamBase.Dispose();
  350. this._stream = null;
  351. this._streamBase = null;
  352. this.keyCount = 0;
  353. this._filePath = "";
  354. this.bOpened = false;
  355. this._Password = "";
  356. if(this.KeyWords!=null)
  357. for (int i = 0; i < this.KeyWords.Length; i++)
  358. this.KeyWords[i] = null;
  359. this.KeyWords = null;
  360. if (this.Extensions != null) {
  361. if (this.Extensions.Length > 0)
  362. for (int i = 0; i < this.Extensions.Length; i++)
  363. this.Extensions[i] = null;
  364. this.Extensions = null;
  365. }
  366. this.Cons("Archive closed");
  367. }
  368. #endregion
  369. #region "Get Data"
  370. #region "getImage"
  371. /// <summary>Gibt die Daten anhand der ID als <see cref="System.Drawing.Image">Image</see>-Object zurück</summary>
  372. /// <param name="ID">Die ID des Eintrags in der Datei</param>
  373. /// <returns>Gibt die Daten anhand der ID als <see cref="System.Drawing.Image">Image</see>-Object zurück</returns>
  374. /// <remarks>System.Drawing.Image</remarks>
  375. public Image getImage(int ID) {
  376. FilePackElements.FPKeyWords fpk = this.KeyWords[ID];
  377. if(fpk!=null) {
  378. byte[] Data = fpk.getBytes();
  379. FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
  380. if(DataGZip == this._settings) {
  381. IO.MemoryStream mem = new IO.MemoryStream(Data);
  382. System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
  383. StreamReader sr = new IO.StreamReader(gz);
  384. sr.Close();
  385. gz.Close();
  386. mem.Close();
  387. sr.Dispose();
  388. gz.Dispose();
  389. mem.Dispose();
  390. }
  391. FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
  392. if(crypt == this._settings)
  393. Data = this.Decode(Data, this._Password);
  394. return (Image)new ImageConverter().ConvertFrom(Data);
  395. }
  396. return null;
  397. }
  398. /// <summary>Gibt die Daten anhand des Keyword-Objektes als <see cref="System.Drawing.Image">Image</see>-Object zurück</summary>
  399. /// <param name="FPK">Das Keyword-Objektes für die Identifizierung</param>
  400. /// <returns>Gibt die Daten anhand des Keyword-Objektes als <see cref="System.Drawing.Image">Image</see>-Object zurück</returns>
  401. /// <remarks>System.Drawing.Image</remarks>
  402. public Image getImage(FilePackElements.FPKeyWords fpk) {
  403. if (fpk != null) {
  404. byte[] Data = fpk.getBytes();
  405. FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
  406. if (DataGZip == this._settings) {
  407. IO.MemoryStream mem = new IO.MemoryStream(Data);
  408. System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
  409. StreamReader sr = new IO.StreamReader(gz);
  410. sr.Close();
  411. gz.Close();
  412. mem.Close();
  413. sr.Dispose();
  414. gz.Dispose();
  415. mem.Dispose();
  416. }
  417. FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
  418. if (crypt == this._settings)
  419. Data = this.Decode(Data, this._Password);
  420. return (Image)new ImageConverter().ConvertFrom(Data);
  421. }
  422. return null;
  423. }
  424. /// <summary>Gibt die Daten anhand des Namen als <see cref="System.Drawing.Image">Image</see>-Object zurück</summary>
  425. /// <param name="Name">Der Keyword-Name</param>
  426. /// <returns>Gibt die Daten anhand des Namen als <see cref="System.Drawing.Image">Image</see>-Object zurück</returns>
  427. /// <remarks>System.Drawing.Image</remarks>
  428. public Image getImage(string Name) {
  429. FilePackElements.FPKeyWords fpk = this.getKeywordByName(Name, FilePackElements.DataType.dtImage);
  430. if (fpk != null) {
  431. byte[] Data = fpk.getBytes();
  432. FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
  433. if (DataGZip == this._settings) {
  434. IO.MemoryStream mem = new IO.MemoryStream(Data);
  435. System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
  436. StreamReader sr = new IO.StreamReader(gz);
  437. sr.Close();
  438. gz.Close();
  439. mem.Close();
  440. sr.Dispose();
  441. gz.Dispose();
  442. mem.Dispose();
  443. }
  444. FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
  445. if (crypt == this._settings)
  446. Data = this.Decode(Data, this._Password);
  447. return (Image)new ImageConverter().ConvertFrom(Data);
  448. }
  449. return null;
  450. }
  451. #endregion
  452. #region "getText"
  453. public string getText(int ID) {
  454. FilePackElements.FPKeyWords fpk = this.KeyWords[ID];
  455. if (fpk != null) {
  456. byte[] Data = fpk.getBytes();
  457. Encoding enc = System.Text.Encoding.UTF8;
  458. FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
  459. if (DataGZip == this._settings) {
  460. IO.MemoryStream mem = new IO.MemoryStream(Data);
  461. System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
  462. gz.Write(Data, 0, Data.Length);
  463. StreamReader sr = new IO.StreamReader(gz);
  464. Data = mem.ToArray();
  465. gz.Flush();
  466. sr.Close();
  467. gz.Close();
  468. mem.Close();
  469. sr.Dispose();
  470. gz.Dispose();
  471. mem.Dispose();
  472. }
  473. FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
  474. if (crypt == this._settings)
  475. Data = this.Decode(Data, this._Password);
  476. return enc.GetString(Data);
  477. }
  478. return null;
  479. }
  480. public string getText(FilePackElements.FPKeyWords fpk) {
  481. if (fpk != null) {
  482. byte[] Data = fpk.getBytes();
  483. Encoding enc = System.Text.Encoding.UTF8;
  484. FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
  485. if (DataGZip == this._settings) {
  486. IO.MemoryStream mem = new IO.MemoryStream(Data);
  487. System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
  488. gz.Write(Data, 0, Data.Length);
  489. StreamReader sr = new IO.StreamReader(gz);
  490. Data = mem.ToArray();
  491. gz.Flush();
  492. sr.Close();
  493. gz.Close();
  494. mem.Close();
  495. sr.Dispose();
  496. gz.Dispose();
  497. mem.Dispose();
  498. }
  499. FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
  500. if (crypt == this._settings)
  501. Data = this.Decode(Data, this._Password);
  502. return enc.GetString(Data);
  503. }
  504. return null;
  505. }
  506. public string getText(string Name) {
  507. FilePackElements.FPKeyWords fpk = this.getKeywordByName(Name, FilePackElements.DataType.dtImage);
  508. if (fpk != null) {
  509. byte[] Data = fpk.getBytes();
  510. Encoding enc = System.Text.Encoding.UTF8;
  511. FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
  512. if (DataGZip == this._settings) {
  513. IO.MemoryStream mem = new IO.MemoryStream(Data);
  514. System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
  515. gz.Write(Data, 0, Data.Length);
  516. StreamReader sr = new IO.StreamReader(gz);
  517. Data = mem.ToArray();
  518. gz.Flush();
  519. sr.Close();
  520. gz.Close();
  521. mem.Close();
  522. sr.Dispose();
  523. gz.Dispose();
  524. mem.Dispose();
  525. }
  526. FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
  527. if (crypt == this._settings)
  528. Data = this.Decode(Data, this._Password);
  529. return enc.GetString(Data);
  530. }
  531. return null;
  532. }
  533. public string getText(int ID, Encoding enc) {
  534. FilePackElements.FPKeyWords fpk = this.KeyWords[ID];
  535. if (fpk != null) {
  536. byte[] Data = fpk.getBytes();
  537. FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
  538. if (DataGZip == this._settings) {
  539. IO.MemoryStream mem = new IO.MemoryStream(Data);
  540. System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
  541. gz.Write(Data, 0, Data.Length);
  542. StreamReader sr = new IO.StreamReader(gz);
  543. Data = mem.ToArray();
  544. gz.Flush();
  545. sr.Close();
  546. gz.Close();
  547. mem.Close();
  548. sr.Dispose();
  549. gz.Dispose();
  550. mem.Dispose();
  551. }
  552. FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
  553. if (crypt == this._settings)
  554. Data = this.Decode(Data, this._Password);
  555. return enc.GetString(Data);
  556. }
  557. return null;
  558. }
  559. public string getText(FilePackElements.FPKeyWords fpk, Encoding enc) {
  560. if (fpk != null) {
  561. byte[] Data = fpk.getBytes();
  562. FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
  563. if (DataGZip == this._settings) {
  564. IO.MemoryStream mem = new IO.MemoryStream(Data);
  565. System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
  566. gz.Write(Data, 0, Data.Length);
  567. StreamReader sr = new IO.StreamReader(gz);
  568. Data = mem.ToArray();
  569. gz.Flush();
  570. sr.Close();
  571. gz.Close();
  572. mem.Close();
  573. sr.Dispose();
  574. gz.Dispose();
  575. mem.Dispose();
  576. }
  577. FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
  578. if (crypt == this._settings)
  579. Data = this.Decode(Data, this._Password);
  580. return enc.GetString(Data);
  581. }
  582. return null;
  583. }
  584. public string getText(string Name, Encoding enc) {
  585. FilePackElements.FPKeyWords fpk = this.getKeywordByName(Name, FilePackElements.DataType.dtImage);
  586. if (fpk != null) {
  587. byte[] Data = fpk.getBytes();
  588. FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
  589. if (DataGZip == this._settings) {
  590. IO.MemoryStream mem = new IO.MemoryStream(Data);
  591. System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
  592. gz.Write(Data, 0, Data.Length);
  593. StreamReader sr = new IO.StreamReader(gz);
  594. Data = mem.ToArray();
  595. gz.Flush();
  596. sr.Close();
  597. gz.Close();
  598. mem.Close();
  599. sr.Dispose();
  600. gz.Dispose();
  601. mem.Dispose();
  602. }
  603. FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
  604. if (crypt == this._settings)
  605. Data = this.Decode(Data, this._Password);
  606. return enc.GetString(Data);
  607. }
  608. return null;
  609. }
  610. #endregion
  611. #region "getData"
  612. /// <summary>Gibt die Daten anhand der ID als <see cref="System.String">String</see> zurück</summary>
  613. /// <param name="ID">Die ID des Eintrags in der Datei</param>
  614. /// <returns>Gibt die Daten anhand der ID als <see cref="System.String">String</see> zurück</returns>
  615. /// <remarks>System.String</remarks>
  616. public string getData(int ID) {
  617. FilePackElements.FPKeyWords fpk = this.KeyWords[ID];
  618. if (fpk != null) {
  619. byte[] Data = fpk.getBytes();
  620. Encoding enc = System.Text.Encoding.ASCII;
  621. FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
  622. if (DataGZip == this._settings) {
  623. IO.MemoryStream mem = new IO.MemoryStream(Data);
  624. System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
  625. gz.Write(Data, 0, Data.Length);
  626. StreamReader sr = new IO.StreamReader(gz);
  627. Data = mem.ToArray();
  628. gz.Flush();
  629. sr.Close();
  630. gz.Close();
  631. mem.Close();
  632. sr.Dispose();
  633. gz.Dispose();
  634. mem.Dispose();
  635. }
  636. FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
  637. if (crypt == this._settings)
  638. Data = this.Decode(Data, this._Password);
  639. return enc.GetString(Data);
  640. }
  641. return null;
  642. }
  643. /// <summary>Gibt die Daten anhand des Keyword-Objektes als <see cref="System.String">String</see> zurück</summary>
  644. /// <param name="FPK">Das Keyword-Objektes für die Identifizierung</param>
  645. /// <returns>Gibt die Daten anhand des Keyword-Objektes als <see cref="System.String">String</see> zurück</returns>
  646. /// <remarks>System.String</remarks>
  647. public string getData(FilePackElements.FPKeyWords fpk) {
  648. if (fpk != null) {
  649. byte[] Data = fpk.getBytes();
  650. Encoding enc = System.Text.Encoding.ASCII;
  651. FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
  652. if (DataGZip == this._settings) {
  653. IO.MemoryStream mem = new IO.MemoryStream(Data);
  654. System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
  655. gz.Write(Data, 0, Data.Length);
  656. StreamReader sr = new IO.StreamReader(gz);
  657. Data = mem.ToArray();
  658. gz.Flush();
  659. sr.Close();
  660. gz.Close();
  661. mem.Close();
  662. sr.Dispose();
  663. gz.Dispose();
  664. mem.Dispose();
  665. }
  666. FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
  667. if (crypt == this._settings)
  668. Data = this.Decode(Data, this._Password);
  669. return enc.GetString(Data);
  670. }
  671. return null;
  672. }
  673. /// <summary>Gibt die Daten anhand des Namen als <see cref="System.String">String</see> zurück</summary>
  674. /// <param name="Name">Der Keyword-Name</param>
  675. /// <returns>Gibt die Daten anhand des Namen als <see cref="System.String">String</see> zurück</returns>
  676. /// <remarks>System.String</remarks>
  677. public string getData(string Name) {
  678. FilePackElements.FPKeyWords fpk = this.getKeywordByName(Name, FilePackElements.DataType.dtImage);
  679. if (fpk != null) {
  680. byte[] Data = fpk.getBytes();
  681. Encoding enc = System.Text.Encoding.ASCII;
  682. FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
  683. if (DataGZip == this._settings) {
  684. IO.MemoryStream mem = new IO.MemoryStream(Data);
  685. System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
  686. gz.Write(Data, 0, Data.Length);
  687. StreamReader sr = new IO.StreamReader(gz);
  688. Data = mem.ToArray();
  689. gz.Flush();
  690. sr.Close();
  691. gz.Close();
  692. mem.Close();
  693. sr.Dispose();
  694. gz.Dispose();
  695. mem.Dispose();
  696. }
  697. FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
  698. if (crypt == this._settings)
  699. Data = this.Decode(Data, this._Password);
  700. return enc.GetString(Data);
  701. }
  702. return null;
  703. }
  704. #endregion
  705. #region "getByteArray"
  706. /// <summary>Gibt die Daten anhand der ID als <see cref="System.String">Byte-Array</see> zurück</summary>
  707. /// <param name="ID">Die ID des Eintrags in der Datei</param>
  708. /// <returns>Gibt die Daten anhand der ID als <see cref="System.String">Byte-Array</see> zurück</returns>
  709. /// <remarks>System.Byte</remarks>
  710. public byte[] getByteArray(int ID) {
  711. FilePackElements.FPKeyWords fpk = this.KeyWords[ID];
  712. if (fpk != null) {
  713. byte[] Data = fpk.getBytes();
  714. FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
  715. if (DataGZip == this._settings) {
  716. IO.MemoryStream mem = new IO.MemoryStream(Data);
  717. System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
  718. gz.Write(Data, 0, Data.Length);
  719. StreamReader sr = new IO.StreamReader(gz);
  720. Data = mem.ToArray();
  721. gz.Flush();
  722. sr.Close();
  723. gz.Close();
  724. mem.Close();
  725. sr.Dispose();
  726. gz.Dispose();
  727. mem.Dispose();
  728. }
  729. FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
  730. if (crypt == this._settings)
  731. Data = this.Decode(Data, this._Password);
  732. return Data;
  733. }
  734. return null;
  735. }
  736. /// <summary>Gibt die Daten anhand des Keyword-Objektes als <see cref="System.String">Byte-Array</see> zurück</summary>
  737. /// <param name="FPK">Das Keyword-Objektes für die Identifizierung</param>
  738. /// <returns>Gibt die Daten anhand des Keyword-Objektes als <see cref="System.String">Byte-Array</see> zurück</returns>
  739. /// <remarks>System.Byte</remarks>
  740. public byte[] getByteArray(FilePackElements.FPKeyWords fpk) {
  741. if (fpk != null) {
  742. byte[] Data = fpk.getBytes();
  743. FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
  744. if (DataGZip == this._settings) {
  745. IO.MemoryStream mem = new IO.MemoryStream(Data);
  746. System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
  747. gz.Write(Data, 0, Data.Length);
  748. StreamReader sr = new IO.StreamReader(gz);
  749. Data = mem.ToArray();
  750. gz.Flush();
  751. sr.Close();
  752. gz.Close();
  753. mem.Close();
  754. sr.Dispose();
  755. gz.Dispose();
  756. mem.Dispose();
  757. }
  758. FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
  759. if (crypt == this._settings)
  760. Data = this.Decode(Data, this._Password);
  761. return Data;
  762. }
  763. return null;
  764. }
  765. /// <summary>Gibt die Daten anhand des Namen als <see cref="System.String">Byte-Array</see> zurück</summary>
  766. /// <param name="Name">Der Keyword-Name</param>
  767. /// <returns>Gibt die Daten anhand des Namen als <see cref="System.String">Byte-Array</see> zurück</returns>
  768. /// <remarks>System.Byte</remarks>
  769. public byte[] getByteArray(string Name) {
  770. FilePackElements.FPKeyWords fpk = this.getKeywordByName(Name, FilePackElements.DataType.dtImage);
  771. if (fpk != null) {
  772. byte[] Data = fpk.getBytes();
  773. FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
  774. if (DataGZip == this._settings) {
  775. IO.MemoryStream mem = new IO.MemoryStream(Data);
  776. System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
  777. gz.Write(Data, 0, Data.Length);
  778. StreamReader sr = new IO.StreamReader(gz);
  779. Data = mem.ToArray();
  780. gz.Flush();
  781. sr.Close();
  782. gz.Close();
  783. mem.Close();
  784. sr.Dispose();
  785. gz.Dispose();
  786. mem.Dispose();
  787. }
  788. FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
  789. if (crypt == this._settings)
  790. Data = this.Decode(Data, this._Password);
  791. return Data;
  792. }
  793. return null;
  794. }
  795. #endregion
  796. #region "getStream"
  797. /// <summary>Gibt die Daten anhand der ID als <see cref="System.String">Stream</see> zurück</summary>
  798. /// <param name="ID">Die ID des Eintrags in der Datei</param>
  799. /// <returns>Gibt die Daten anhand der ID als <see cref="System.String">Stream</see> zurück</returns>
  800. /// <remarks>System.IO.Stream</remarks>
  801. public Stream getStream(int ID) {
  802. FilePackElements.FPKeyWords fpk = this.KeyWords[ID];
  803. if (fpk != null) {
  804. byte[] Data = fpk.getBytes();
  805. FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
  806. if (DataGZip == this._settings) {
  807. IO.MemoryStream mem = new IO.MemoryStream(Data);
  808. System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
  809. gz.Write(Data, 0, Data.Length);
  810. StreamReader sr = new IO.StreamReader(gz);
  811. Data = mem.ToArray();
  812. gz.Flush();
  813. sr.Close();
  814. gz.Close();
  815. mem.Close();
  816. sr.Dispose();
  817. gz.Dispose();
  818. mem.Dispose();
  819. }
  820. FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
  821. if (crypt == this._settings)
  822. Data = this.Decode(Data, this._Password);
  823. return new IO.MemoryStream(Data);
  824. }
  825. return null;
  826. }
  827. /// <summary>Gibt die Daten anhand des Keyword-Objektes als <see cref="System.String">Stream</see> zurück</summary>
  828. /// <param name="FPK">Das Keyword-Objektes für die Identifizierung</param>
  829. /// <returns>Gibt die Daten anhand des Keyword-Objektes als <see cref="System.String">Stream</see> zurück</returns>
  830. /// <remarks>System.IO.Stream</remarks>
  831. public Stream getStream(FilePackElements.FPKeyWords fpk) {
  832. if (fpk != null) {
  833. byte[] Data = fpk.getBytes();
  834. FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
  835. if (DataGZip == this._settings) {
  836. IO.MemoryStream mem = new IO.MemoryStream(Data);
  837. System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
  838. gz.Write(Data, 0, Data.Length);
  839. StreamReader sr = new IO.StreamReader(gz);
  840. Data = mem.ToArray();
  841. gz.Flush();
  842. sr.Close();
  843. gz.Close();
  844. mem.Close();
  845. sr.Dispose();
  846. gz.Dispose();
  847. mem.Dispose();
  848. }
  849. FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
  850. if (crypt == this._settings)
  851. Data = this.Decode(Data, this._Password);
  852. return new IO.MemoryStream(Data);
  853. }
  854. return null;
  855. }
  856. /// <summary>Gibt die Daten anhand des Namen als <see cref="System.String">Stream</see> zurück</summary>
  857. /// <param name="Name">Der Keyword-Name</param>
  858. /// <returns>Gibt die Daten anhand des Namen als <see cref="System.String">Stream</see> zurück</returns>
  859. /// <remarks>System.IO.Stream</remarks>
  860. public Stream getStream(string Name) {
  861. FilePackElements.FPKeyWords fpk = this.getKeywordByName(Name, FilePackElements.DataType.dtImage);
  862. if (fpk != null) {
  863. byte[] Data = fpk.getBytes();
  864. FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
  865. if (DataGZip == this._settings) {
  866. IO.MemoryStream mem = new IO.MemoryStream(Data);
  867. System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
  868. gz.Write(Data, 0, Data.Length);
  869. StreamReader sr = new IO.StreamReader(gz);
  870. Data = mem.ToArray();
  871. gz.Flush();
  872. sr.Close();
  873. gz.Close();
  874. mem.Close();
  875. sr.Dispose();
  876. gz.Dispose();
  877. mem.Dispose();
  878. }
  879. FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
  880. if (crypt == this._settings)
  881. Data = this.Decode(Data, this._Password);
  882. return new IO.MemoryStream(Data);
  883. }
  884. return null;
  885. }
  886. #endregion
  887. #region "getAssembly"
  888. /// <summary>Gibt die Daten anhand der ID als <see cref="System.String">Stream</see> zurück</summary>
  889. /// <param name="ID">Die ID des Eintrags in der Datei</param>
  890. /// <returns>Gibt die Daten anhand der ID als <see cref="System.String">Stream</see> zurück</returns>
  891. /// <remarks>System.IO.Stream</remarks>
  892. public System.Reflection.Assembly getAssembly(int ID) {
  893. FilePackElements.FPKeyWords fpk = this.KeyWords[ID];
  894. if (fpk != null) {
  895. byte[] Data = fpk.getBytes();
  896. FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
  897. if (DataGZip == this._settings) {
  898. IO.MemoryStream mem = new IO.MemoryStream(Data);
  899. System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
  900. gz.Write(Data, 0, Data.Length);
  901. StreamReader sr = new IO.StreamReader(gz);
  902. Data = mem.ToArray();
  903. gz.Flush();
  904. sr.Close();
  905. gz.Close();
  906. mem.Close();
  907. sr.Dispose();
  908. gz.Dispose();
  909. mem.Dispose();
  910. }
  911. FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
  912. if (crypt == this._settings)
  913. Data = this.Decode(Data, this._Password);
  914. return System.Reflection.Assembly.Load(Data);
  915. }
  916. return null;
  917. }
  918. /// <summary>Gibt die Daten anhand des Keyword-Objektes als <see cref="System.String">Stream</see> zurück</summary>
  919. /// <param name="FPK">Das Keyword-Objektes für die Identifizierung</param>
  920. /// <returns>Gibt die Daten anhand des Keyword-Objektes als <see cref="System.String">Stream</see> zurück</returns>
  921. /// <remarks>System.IO.Stream</remarks>
  922. public System.Reflection.Assembly getAssembly(FilePackElements.FPKeyWords fpk) {
  923. if (fpk != null) {
  924. byte[] Data = fpk.getBytes();
  925. FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
  926. if (DataGZip == this._settings) {
  927. IO.MemoryStream mem = new IO.MemoryStream(Data);
  928. System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
  929. gz.Write(Data, 0, Data.Length);
  930. StreamReader sr = new IO.StreamReader(gz);
  931. Data = mem.ToArray();
  932. gz.Flush();
  933. sr.Close();
  934. gz.Close();
  935. mem.Close();
  936. sr.Dispose();
  937. gz.Dispose();
  938. mem.Dispose();
  939. }
  940. FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
  941. if (crypt == this._settings)
  942. Data = this.Decode(Data, this._Password);
  943. return System.Reflection.Assembly.Load(Data);
  944. }
  945. return null;
  946. }
  947. /// <summary>Gibt die Daten anhand des Namen als <see cref="System.String">Stream</see> zurück</summary>
  948. /// <param name="Name">Der Keyword-Name</param>
  949. /// <returns>Gibt die Daten anhand des Namen als <see cref="System.String">Stream</see> zurück</returns>
  950. /// <remarks>System.IO.Stream</remarks>
  951. public System.Reflection.Assembly getAssembly(string Name) {
  952. FilePackElements.FPKeyWords fpk = this.getKeywordByName(Name, FilePackElements.DataType.dtImage);
  953. if (fpk != null) {
  954. byte[] Data = fpk.getBytes();
  955. FilePackElements.eSet DataGZip = this._settings | FilePackElements.eSet.Data_GZip;
  956. if (DataGZip == this._settings) {
  957. IO.MemoryStream mem = new IO.MemoryStream(Data);
  958. System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Decompress);
  959. gz.Write(Data, 0, Data.Length);
  960. StreamReader sr = new IO.StreamReader(gz);
  961. Data = mem.ToArray();
  962. gz.Flush();
  963. sr.Close();
  964. gz.Close();
  965. mem.Close();
  966. sr.Dispose();
  967. gz.Dispose();
  968. mem.Dispose();
  969. }
  970. FilePackElements.eSet crypt = this._settings | FilePackElements.eSet.Crypt;
  971. if (crypt == this._settings)
  972. Data = this.Decode(Data, this._Password);
  973. return System.Reflection.Assembly.Load(Data);
  974. }
  975. return null;
  976. }
  977. #endregion
  978. #endregion
  979. #region "Comments"
  980. public enum TextCommentType : byte {
  981. TextComment = 1,
  982. ShortTextComment = 7,
  983. Homepage = 2,
  984. Email = 4,
  985. Company = 5,
  986. Address = 8
  987. }
  988. public FilePackElements.FPComment addComment(string Text, TextCommentType Type) {
  989. Array.Resize(ref this._comments, this._commentCount + 1);
  990. this._comments[this._commentCount] = new FilePackElements.FPComment();
  991. this._comments[this._commentCount].Type = (FilePackElements.FPCommentType)((byte)Type);
  992. this._comments[this._commentCount].Caption = Text;
  993. this._commentCount += 1;
  994. return this._comments[this._commentCount - 1];
  995. }
  996. public FilePackElements.FPComment addComment(UInt16 FileID, string Text) {
  997. Array.Resize(ref this._comments, this._commentCount + 1);
  998. this._comments[this._commentCount] = new FilePackElements.FPComment();
  999. this._comments[this._commentCount].Type = FilePackElements.FPCommentType.FileComment;
  1000. this._comments[this._commentCount].Caption = Text;
  1001. this._comments[this._commentCount].FileID = FileID;
  1002. this._commentCount += 1;
  1003. return this._comments[this._commentCount - 1];
  1004. }
  1005. public FilePackElements.FPComment addComment(Bitmap Img) {
  1006. Array.Resize(ref this._comments, this._commentCount + 1);
  1007. this._comments[this._commentCount] = new FilePackElements.FPComment();
  1008. this._comments[this._commentCount].Type = FilePackElements.FPCommentType.Image;
  1009. this._comments[this._commentCount].Picture = Img;
  1010. this._commentCount += 1;
  1011. return this._comments[this._commentCount - 1];
  1012. }
  1013. public FilePackElements.FPComment addComment(UInt16 FileID, Bitmap Img) {
  1014. Array.Resize(ref this._comments, this._commentCount + 1);
  1015. this._comments[this._commentCount] = new FilePackElements.FPComment();
  1016. this._comments[this._commentCount].Type = FilePackElements.FPCommentType.FileImage;
  1017. this._comments[this._commentCount].Picture = Img;
  1018. this._comments[this._commentCount].FileID = FileID;
  1019. this._commentCount += 1;
  1020. return this._comments[this._commentCount - 1];
  1021. }
  1022. public FilePackElements.FPComment addComment(Icon Ico) {
  1023. Array.Resize(ref this._comments, this._commentCount + 1);
  1024. this._comments[this._commentCount] = new FilePackElements.FPComment();
  1025. this._comments[this._commentCount].Type = FilePackElements.FPCommentType.Icon;
  1026. this._comments[this._commentCount].Icon = Ico;
  1027. this._commentCount += 1;
  1028. return this._comments[this._commentCount - 1];
  1029. }
  1030. public FilePackElements.FPComment addComment(UInt16 FileID, Icon Ico) {
  1031. Array.Resize(ref this._comments, this._commentCount + 1);
  1032. this._comments[this._commentCount] = new FilePackElements.FPComment();
  1033. this._comments[this._commentCount].Type = FilePackElements.FPCommentType.FileIcon;
  1034. this._comments[this._commentCount].Icon = Ico;
  1035. this._comments[this._commentCount].FileID = FileID;
  1036. this._commentCount += 1;
  1037. return this._comments[this._commentCount - 1];
  1038. }
  1039. #endregion
  1040. #region "Exists"
  1041. /// <summary>Überprüft ob ein Keyword existiert</summary>
  1042. /// <param name="Keyword">Name des Keywords</param>
  1043. /// <returns>Gibt bei erfolg true zurück, false falls das Keyword nicht existiert.</returns>
  1044. public bool Exsists(string Keyword) {
  1045. for (int i = 0; i < this.keyCount; i++) {
  1046. if (this.KeyWords[i].Keyword == Keyword)
  1047. return true;
  1048. }
  1049. return false;
  1050. }
  1051. /// <summary>Überprüft ob ein Array mit Keywords existiert</summary>
  1052. /// <param name="Keywords">Array mit Namen der Keywords</param>
  1053. /// <returns>Gibt bei erfolg true zurück, false falls ein oder mehrere Keywords nicht existieren.</returns>
  1054. public bool Exsists(string[] Keywords) {
  1055. for (int i = 0; i < this.keyCount; i++) {
  1056. bool bFound = false;
  1057. for (int j = 0; j < Keywords.Length; j++) {
  1058. if (this.KeyWords[i].Keyword == Keywords[j]) {
  1059. bFound = true;
  1060. break; // TODO: might not be correct. Was : Exit For
  1061. }
  1062. }
  1063. if (bFound == false)
  1064. return false;
  1065. }
  1066. return false;
  1067. }
  1068. #endregion
  1069. #region "Crypt"
  1070. private bool checkPW1() {
  1071. byte s = (byte)(this._settings | FilePackElements.eSet.UsePassword);
  1072. if (s == (byte)this._settings) {
  1073. long sumx = 0;
  1074. int sumy = 0;
  1075. System.Text.Encoding enc = System.Text.Encoding.UTF8;
  1076. byte[] xpw = enc.GetBytes(this._Password);
  1077. for (int i = 0; i <= xpw.Length - 1; i++) {
  1078. sumx = (sumx + xpw[i]) % 200;
  1079. sumy = xpw[i] % 11;
  1080. }
  1081. byte sum = this._stream.ReadByte();
  1082. byte sum2 = this._stream.ReadByte();
  1083. byte sum3 = this._stream.ReadByte();
  1084. sumx = (sumx % 200) + 25;
  1085. if (sumx != sum) {
  1086. throw new Exception_PassCheckSum(this._filePath, this._streamBase.Length, (byte)SignatureVersion, sum, sumx, 1);
  1087. //return false;
  1088. }
  1089. sumx += (xpw.Length % 5) + xpw[0] % 200;
  1090. if (sumx != sum2) {
  1091. throw new Exception_PassCheckSum(this._filePath, this._streamBase.Length, (byte)SignatureVersion, sum2, sumx, 2);
  1092. //return false;
  1093. }
  1094. sumy = (((sumy + xpw[xpw.Length - 1]) % 50) + ((sumy + xpw[xpw.Length - 1]) % 47) + ((sumy + xpw[xpw.Length - 1]) % 127) + 30);
  1095. if (sumy != sum3) {
  1096. throw new Exception_PassCheckSum(this._filePath, this._streamBase.Length, (byte)SignatureVersion, sum3, sumy, 3);
  1097. //return false;
  1098. }
  1099. }
  1100. return true;
  1101. }
  1102. private static void writePW1(ref IO.BinaryWriter S, string PW) {
  1103. long sumx = 0;
  1104. int sumy = 0;
  1105. System.Text.Encoding enc = System.Text.Encoding.UTF8;
  1106. byte[] xpw = enc.GetBytes(PW);
  1107. for (int i = 0; i <= xpw.Length - 1; i++) {
  1108. sumx = (sumx + xpw[i]) % 200;
  1109. sumy = xpw[i] % 11;
  1110. }
  1111. sumx = (sumx % 200) + 25;
  1112. S.Write(Convert.ToByte(sumx));
  1113. sumx += (xpw.Length % 5) + xpw[0] % 200;
  1114. S.Write(Convert.ToByte(sumx));
  1115. sumy = (((sumy + xpw[xpw.Length - 1]) % 50) + ((sumy + xpw[xpw.Length - 1]) % 47) + ((sumy + xpw[xpw.Length - 1]) % 127) + 30);
  1116. S.Write(Convert.ToByte(sumy));
  1117. }
  1118. private static byte[] Encode(byte[] b, string Password = "") {
  1119. if (Password == "") {
  1120. for (int i = 0; i < b.Length; i++) {
  1121. byte j = (byte)((b[i] + i + b.Length) % 256);
  1122. b[i] = j;
  1123. }
  1124. return b;
  1125. } else {
  1126. byte[] pw = Convert.FromBase64String(Password);
  1127. int pwLen = pw.Length;
  1128. for (int i = 0; i < b.Length; i++) {
  1129. int j = ((b[i] + i + b.Length + pw[i % pwLen]) + pwLen) % 256;
  1130. b[i] = (byte)j;
  1131. }
  1132. return b;
  1133. }
  1134. }
  1135. private byte[] Decode(byte[] b, string Password = "") {
  1136. if (Password=="") {
  1137. for (int i = 0; i < b.Length; i++) {
  1138. byte j = (byte)(((b[i] - (i % 256) - (b.Length % 256)) + 512) % 256);
  1139. b[i] = j;
  1140. }
  1141. } else {
  1142. byte[] pw = Convert.FromBase64String(Password);
  1143. int pwLen = pw.Length;
  1144. for (int i = 0; i < b.Length; i++) {
  1145. int j = (((b[i] - (i % 256) - (b.Length % 256) - pw[i % pwLen]) - pwLen) + 2048) % 256;
  1146. b[i] = (byte)j;
  1147. }
  1148. }
  1149. return b;
  1150. }
  1151. #endregion
  1152. #region "Count Property"
  1153. /// <summary>Gibt die Anzahl Einträge zurück</summary>
  1154. /// <returns>Gibt die Anzahl Einträge zurück</returns>
  1155. /// <remarks></remarks>
  1156. public int Count() {
  1157. return this.KeyWords.Length;
  1158. }
  1159. /// <summary>Gibt die Anzahl Einträge des angegebenen Typen zurück</summary>
  1160. /// <param name="Type">Gibt den Typen der Daten an, nach denen gezählt werden soll</param>
  1161. /// <returns>Gibt die Anzahl Einträge des angegebenen Typen zurück</returns>
  1162. /// <remarks></remarks>
  1163. public int Count(FilePackElements.DataType Type) {
  1164. int nr = 0;
  1165. foreach (FilePackElements.FPKeyWords kw in this.KeyWords)
  1166. if (kw.Type == Type) nr += 1;
  1167. return nr;
  1168. }
  1169. /// <summary>Gibt die Anzahl Einträge mit der angegebenen Dateiendung zurück</summary>
  1170. /// <param name="Extensions">Gibt die Dateiendung an, nach der gezählt werden soll</param>
  1171. /// <returns>Gibt die Anzahl Einträge mit der angegebenen Dateiendung zurück</returns>
  1172. /// <remarks></remarks>
  1173. public int Count(string Extensions) {
  1174. int nr = 0;
  1175. foreach (FilePackElements.FPKeyWords kw in this.KeyWords)
  1176. if (this.Extensions[kw.FileExtension].Extensions == Extensions) nr += 1;
  1177. return nr;
  1178. }
  1179. #endregion
  1180. #region "Other Functions"
  1181. /// <summary>
  1182. /// Gibt das entsprechende Keyword-Objekt als System.BlackPro.FilePackBP.FilePackElements.FPKeyWords zurück
  1183. /// </summary>
  1184. /// <param name="Name">Name des Keywords als String</param>
  1185. /// <returns>Gibt das entsprechende Keyword-Objekt als System.BlackPro.FilePackBP.FilePackElements.FPKeyWords zurück</returns>
  1186. public FilePackElements.FPKeyWords getKeywordByName(string Name) {
  1187. for (int i = 0; i < this.keyCount; i++) {
  1188. if (this.KeyWords[i].Keyword == Name)
  1189. return this.KeyWords[i];
  1190. }
  1191. return null;
  1192. }
  1193. /// <summary>
  1194. /// Gibt das entsprechende Keyword-Objekt als System.BlackPro.FilePackBP.FilePackElements.FPKeyWords zurück
  1195. /// </summary>
  1196. /// <param name="Name">Name des Keywords als String</param>
  1197. /// <param name="Type">Datentyp des Keywords als System.BlackPro.FilePackBP.FilePack.DataType</param>
  1198. /// <returns>Gibt das entsprechende Keyword-Objekt als System.BlackPro.FilePackBP.FilePackElements.FPKeyWords zurück</returns>
  1199. public FilePackElements.FPKeyWords getKeywordByName(string Name, FilePackElements.DataType Type) {
  1200. for (int i = 0; i < this.keyCount; i++) {
  1201. if (this.KeyWords[i].Keyword == Name & this.KeyWords[i].Type == Type)
  1202. return this.KeyWords[i];
  1203. }
  1204. return null;
  1205. }
  1206. /// <summary>
  1207. /// Prüft die Signatur des Archivs
  1208. /// </summary>
  1209. /// <param name="b">Die Signatur als Byte-Array</param>
  1210. /// <returns>Gibt bei erfolgreicher Signaturprüfung True zurück</returns>
  1211. public static bool checkSignature(byte[] b) {
  1212. if (b == null)
  1213. return false;
  1214. if (b.Length == 0)
  1215. return false;
  1216. if (b.Length == Signature.Length) {
  1217. for (int i = 0; i < b.Length; i++) {
  1218. if (b[i] != Signature[i])
  1219. return false;
  1220. }
  1221. return true;
  1222. } else {
  1223. return false;
  1224. }
  1225. }
  1226. private static char Chr(int b) {
  1227. return Convert.ToChar(b);
  1228. }
  1229. private static char Chr(byte b) {
  1230. return Convert.ToChar(b);
  1231. }
  1232. private static byte Asc(char c) {
  1233. return Convert.ToByte(c);
  1234. }
  1235. private static string IIF(bool b, string t, string f) {
  1236. if (b) {
  1237. return t;
  1238. } else {
  1239. return f;
  1240. }
  1241. }
  1242. private static byte IIF(bool b, byte t, byte f) {
  1243. if (b) {
  1244. return t;
  1245. } else {
  1246. return f;
  1247. }
  1248. }
  1249. private static int IIF(bool b, int t, int f) {
  1250. if (b) {
  1251. return t;
  1252. } else {
  1253. return f;
  1254. }
  1255. }
  1256. #endregion
  1257. #region "Export"
  1258. /// <summary>
  1259. /// Exportiert die Einträge des Archives in das glaiche Verzeichnis
  1260. /// </summary>
  1261. public void exportToDirectory() {
  1262. if (!string.IsNullOrEmpty(this._filePath)) {
  1263. FileInfo fi = new FileInfo(this._filePath);
  1264. this.exportToDirectory(fi.FullName.Substring(0, fi.FullName.Length - fi.Extension.Length) + "\\");
  1265. }
  1266. }
  1267. /// <summary>
  1268. /// Exportiert die Einträge des Archives in das glaiche Verzeichnis
  1269. /// </summary>
  1270. /// <param name="Overwrite">Gibt an, ob existierende Dateien überschrieben werden sollen</param>
  1271. public void exportToDirectory(bool Overwrite) {
  1272. if (!string.IsNullOrEmpty(this._filePath)) {
  1273. FileInfo fi = new FileInfo(this._filePath);
  1274. this.exportToDirectory(fi.FullName.Substring(0, fi.FullName.Length - fi.Extension.Length) + "\\", Overwrite);
  1275. }
  1276. }
  1277. /// <summary>
  1278. /// Exportiert die Einträge des Archives in das angegebene Verzeichnis
  1279. /// </summary>
  1280. /// <param name="Dir">Das Verzeichnis in das die Daten exportiert werden sollen</param>
  1281. public void exportToDirectory(string Dir) {
  1282. byte canExport = (byte)(this._settings | FilePackElements.eSet.ExportLocked);
  1283. if (canExport != (byte)this._settings) {
  1284. if (Directory.Exists(Dir) == false)
  1285. Directory.CreateDirectory(Dir);
  1286. foreach (FilePackElements.FPKeyWords kw in this.KeyWords) {
  1287. string ext = this.Extensions[kw.FileExtension].Extensions;
  1288. string FPath = Dir + (Dir.EndsWith(IO.Path.DirectorySeparatorChar.ToString()) ? "" : IO.Path.DirectorySeparatorChar.ToString()) + kw.Keyword + (!string.IsNullOrEmpty(ext) ? "." + ext : "");
  1289. if (FPath.Contains(IO.Path.DirectorySeparatorChar.ToString())) {
  1290. FileInfo fi = new FileInfo(FPath);
  1291. if (fi.Directory.Exists == false)
  1292. fi.Directory.Create();
  1293. //Directory.CreateDirectory(fi.Directory)
  1294. }
  1295. if (IO.File.Exists(FPath) == false) {
  1296. this.Cons("Export Data '" + kw.Keyword + (!string.IsNullOrEmpty(ext) ? "." + ext : "") + "' (" + kw.Length.ToString("#,##0") + " Bytes)");
  1297. File.WriteAllBytes(FPath, this.getByteArray(kw));
  1298. } else {
  1299. this.Cons("File already exists '" + kw.Keyword + (!string.IsNullOrEmpty(ext) ? "." + ext : "") + "' (" + kw.Length.ToString("#,##0") + " Bytes)");
  1300. }
  1301. }
  1302. } else {
  1303. throw new System.Fire.FilePack.Exception.Exception_ExportLocked(this._filePath, this._streamBase.Length, (byte)SignatureVersion);
  1304. }
  1305. }
  1306. /// <summary>
  1307. /// Exportiert die Einträge des Archives in das angegebene Verzeichnis
  1308. /// </summary>
  1309. /// <param name="Dir">Das Verzeichnis in das die Daten exportiert werden sollen</param>
  1310. /// <param name="Overwrite">Gibt an, ob existierende Dateien überschrieben werden sollen</param>
  1311. public void exportToDirectory(string Dir, bool Overwrite) {
  1312. byte canExport = (byte)(this._settings | FilePackElements.eSet.ExportLocked);
  1313. if (canExport != (byte)this._settings) {
  1314. if (Directory.Exists(Dir) == false)
  1315. Directory.CreateDirectory(Dir);
  1316. foreach (FilePackElements.FPKeyWords kw in this.KeyWords) {
  1317. string ext = this.Extensions[kw.FileExtension].Extensions;
  1318. this.Cons("Export Data '" + kw.Keyword + (!string.IsNullOrEmpty(ext) ? "." + ext : "") + "' (" + kw.Length.ToString("#,##0") + " Bytes)");
  1319. if (IO.File.Exists(Dir + (Dir.EndsWith(IO.Path.DirectorySeparatorChar.ToString()) ? "" : IO.Path.DirectorySeparatorChar.ToString()) + kw.Keyword + (!string.IsNullOrEmpty(ext) ? "." + ext : "")) & Overwrite == true) {
  1320. IO.File.Delete(Dir + (Dir.EndsWith(IO.Path.DirectorySeparatorChar.ToString()) ? "" : IO.Path.DirectorySeparatorChar.ToString()) + kw.Keyword + (!string.IsNullOrEmpty(ext) ? "." + ext : ""));
  1321. } else if (IO.File.Exists(Dir + (Dir.EndsWith(IO.Path.DirectorySeparatorChar.ToString()) ? "" : IO.Path.DirectorySeparatorChar.ToString()) + kw.Keyword + (!string.IsNullOrEmpty(ext) ? "." + ext : "")) == false) {
  1322. File.WriteAllBytes(Dir + (Dir.EndsWith(IO.Path.DirectorySeparatorChar.ToString()) ? "" : IO.Path.DirectorySeparatorChar.ToString()) + kw.Keyword + (!string.IsNullOrEmpty(ext) ? "." + ext : ""), this.getByteArray(kw));
  1323. }
  1324. }
  1325. } else {
  1326. throw new System.Fire.FilePack.Exception.Exception_ExportLocked(this._filePath, this._streamBase.Length, (byte)SignatureVersion);
  1327. }
  1328. }
  1329. #endregion
  1330. #region "Create"
  1331. /// <summary>
  1332. /// Erstellt ein Archiv im Parent-Directory anhand des Verzeichnises <para>DirPath</para>
  1333. /// </summary>
  1334. /// <param name="DirPath">Gibt das Verzeichnis an, das archiviert werden soll.</param>
  1335. /// <param name="Version">Gibt die Version des Archives an.</param>
  1336. public static void createFromDirectory(string DirPath, ref FilePackElements.eVersion Version) {
  1337. string Destination = createFilepathFromDir(DirPath);
  1338. createFromDirectory1(DirPath, Destination, Version, new FilePackElements.CreateSetting(true), false);
  1339. }
  1340. /// <summary>
  1341. /// Erstellt ein Archiv im Parent-Directory mit Einstellungen anhand des Verzeichnises <para>DirPath</para>
  1342. /// </summary>
  1343. /// <param name="DirPath">Gibt das Verzeichnis an, das archiviert werden soll.</param>
  1344. /// <param name="Version">Gibt die Version des Archives an.</param>
  1345. /// <param name="Settings">Die Einstellungen unter denen das Archiv erstellt werden soll</param>
  1346. public static void createFromDirectory(string DirPath, FilePackElements.eVersion Version, FilePackElements.CreateSetting Settings) {
  1347. string Destination = createFilepathFromDir(DirPath);
  1348. createFromDirectory1(DirPath, Destination, Version, Settings, false);
  1349. }
  1350. /// <summary>
  1351. /// Erstellt ein Archiv im <para>DestinationFile</para> anhand des Verzeichnises <para>DirPath</para>
  1352. /// </summary>
  1353. /// <param name="DirPath">Gibt das Verzeichnis an, das archiviert werden soll.</param>
  1354. /// <param name="DestinationFile">Gibt den Pfad des Zielarchives an.</param>
  1355. /// <param name="Version">Gibt die Version des Archives an.</param>
  1356. public static void createFromDirectory(string DirPath, string DestinationFile, FilePackElements.eVersion Version) {
  1357. createFromDirectory1(DirPath, DestinationFile, Version, new FilePackElements.CreateSetting(true), false);
  1358. }
  1359. /// <summary>
  1360. /// Erstellt ein Archiv im <para>DestinationFile</para> anhand des Verzeichnises <para>DirPath</para>
  1361. /// </summary>
  1362. /// <param name="DirPath">Gibt das Verzeichnis an, das archiviert werden soll.</param>
  1363. /// <param name="DestinationFile">Gibt den Pfad des Zielarchives an.</param>
  1364. /// <param name="Version">Gibt die Version des Archives an.</param>
  1365. /// <param name="Settings">Die Einstellungen unter denen das Archiv erstellt werden soll</param>
  1366. public static void createFromDirectory(string DirPath, string DestinationFile, FilePackElements.eVersion Version, FilePackElements.CreateSetting Settings) {
  1367. createFromDirectory1(DirPath, DestinationFile, Version, Settings, false);
  1368. }
  1369. /// <summary>
  1370. /// Erstellt ein Archiv im Parent-Directory anhand des Verzeichnises <para>DirPath</para>
  1371. /// </summary>
  1372. /// <param name="DirPath">Gibt das Verzeichnis an, das archiviert werden soll.</param>
  1373. /// <param name="Version">Gibt die Version des Archives an.</param>
  1374. /// <param name="Console">true, gibt die Ausgabe in der Console wieder</param>
  1375. public static void createFromDirectory(string DirPath, FilePackElements.eVersion Version, bool Console) {
  1376. string Destination = createFilepathFromDir(DirPath);
  1377. createFromDirectory1(DirPath, Destination, Version, new FilePackElements.CreateSetting(true), Console);
  1378. }
  1379. /// <summary>
  1380. /// Erstellt ein Archiv im Parent-Directory mit Einstellungen anhand des Verzeichnises <para>DirPath</para>
  1381. /// </summary>
  1382. /// <param name="DirPath">Gibt das Verzeichnis an, das archiviert werden soll.</param>
  1383. /// <param name="Version">Gibt die Version des Archives an.</param>
  1384. /// <param name="Settings">Die Einstellungen unter denen das Archiv erstellt werden soll</param>
  1385. /// <param name="Console">true, gibt die Ausgabe in der Console wieder</param>
  1386. public static void createFromDirectory(string DirPath, FilePackElements.eVersion Version, FilePackElements.CreateSetting Settings, bool Console) {
  1387. string Destination = createFilepathFromDir(DirPath);
  1388. createFromDirectory1(DirPath, Destination, Version, Settings, Console);
  1389. }
  1390. /// <summary>
  1391. /// Erstellt ein Archiv im <para>DestinationFile</para> anhand des Verzeichnises <para>DirPath</para>
  1392. /// </summary>
  1393. /// <param name="DirPath">Gibt das Verzeichnis an, das archiviert werden soll.</param>
  1394. /// <param name="DestinationFile">Gibt den Pfad des Zielarchives an.</param>
  1395. /// <param name="Version">Gibt die Version des Archives an.</param>
  1396. /// <param name="Console">true, gibt die Ausgabe in der Console wieder</param>
  1397. public static void createFromDirectory(string DirPath, string DestinationFile, FilePackElements.eVersion Version, bool Console) {
  1398. createFromDirectory1(DirPath, DestinationFile, Version, new FilePackElements.CreateSetting(true), Console);
  1399. }
  1400. /// <summary>
  1401. /// Erstellt ein Archiv im <para>DestinationFile</para> anhand des Verzeichnises <para>DirPath</para>
  1402. /// </summary>
  1403. /// <param name="DirPath">Gibt das Verzeichnis an, das archiviert werden soll.</param>
  1404. /// <param name="DestinationFile">Gibt den Pfad des Zielarchives an.</param>
  1405. /// <param name="Version">Gibt die Version des Archives an.</param>
  1406. /// <param name="Settings">Die Einstellungen unter denen das Archiv erstellt werden soll</param>
  1407. /// <param name="Console">true, gibt die Ausgabe in der Console wieder</param>
  1408. public static void createFromDirectory(string DirPath, string DestinationFile, FilePackElements.eVersion Version, FilePackElements.CreateSetting Settings, bool Console) {
  1409. createFromDirectory1(DirPath, DestinationFile, Version, Settings, Console);
  1410. }
  1411. private static string createFilepathFromDir(string DirPath) {
  1412. if (DirPath.EndsWith(IO.Path.DirectorySeparatorChar.ToString()))
  1413. DirPath = DirPath.Substring(0, DirPath.Length - (IO.Path.DirectorySeparatorChar.ToString().Length));
  1414. return DirPath + ".bfp";
  1415. }
  1416. private struct sFileInfo {
  1417. private string _Extension;
  1418. private byte _ExtensionIndex;
  1419. private string _FileName;
  1420. private string _AbsolutePath;
  1421. private string _Name;
  1422. private long _FileSize;
  1423. private FilePackElements.DataType _Type;
  1424. private string _Temp;
  1425. public string Extension {
  1426. get { return this._Extension; }
  1427. set { this._Extension = value; }
  1428. }
  1429. public string Temp {
  1430. get { return this._Temp; }
  1431. set { this._Temp = value; }
  1432. }
  1433. public byte ExtensionIndex {
  1434. get { return this._ExtensionIndex; }
  1435. set { this._ExtensionIndex = value; }
  1436. }
  1437. public string FileName {
  1438. get { return this._FileName; }
  1439. set { this._FileName = value; }
  1440. }
  1441. public string AbsolutePath {
  1442. get { return this._AbsolutePath; }
  1443. set { this._AbsolutePath = value; }
  1444. }
  1445. public string Name {
  1446. get { return this._Name; }
  1447. set { this._Name = value; }
  1448. }
  1449. public long FileSize {
  1450. get { return this._FileSize; }
  1451. set { this._FileSize = value; }
  1452. }
  1453. public FilePackElements.DataType Type {
  1454. get { return this._Type; }
  1455. set { this._Type = value; }
  1456. }
  1457. }
  1458. private static void createFromDirectory1(string DirPath, string Destination, FilePackElements.eVersion Version, FilePackElements.CreateSetting Settings, bool bCons) {
  1459. if (File.Exists(Destination)) {
  1460. throw new System.Fire.FilePack.Exception.Exception_ArchiveExists(Destination);
  1461. //return;
  1462. }
  1463. IO.DirectoryInfo di = new IO.DirectoryInfo(DirPath);
  1464. IO.FileStream fs = new IO.FileStream(Destination, FileMode.CreateNew);
  1465. IO.BinaryWriter bw = new IO.BinaryWriter(fs);
  1466. FilePackElements.eSet xsettings = 0;
  1467. System.Text.Encoding enc = System.Text.Encoding.UTF8;
  1468. if (Settings.DataGZip)
  1469. xsettings = xsettings | FilePackElements.eSet.Data_GZip;
  1470. if (Settings.Crypt)
  1471. xsettings = xsettings | FilePackElements.eSet.Crypt;
  1472. if (Settings.LockExport)
  1473. xsettings = xsettings | FilePackElements.eSet.ExportLocked;
  1474. if (Settings.TextGZip)
  1475. xsettings = xsettings | FilePackElements.eSet.Text_GZip;
  1476. if (Settings.UsePassword)
  1477. xsettings = xsettings | FilePackElements.eSet.UsePassword;
  1478. if (Settings.Extantions)
  1479. xsettings = xsettings | FilePackElements.eSet.Extantions;
  1480. FilePack.Cons("Create archive '" + di.Name + "' using password: " + (!string.IsNullOrEmpty(Settings.Password) & Settings.UsePassword ? "Yes" : "No"), bCons);
  1481. bw.Write(System.Fire.FilePack.FilePack.Signature);
  1482. bw.Write(Convert.ToByte(FilePackElements.eVersion.Version_1_0));
  1483. bw.Write(Convert.ToByte(xsettings));
  1484. bw.Write(Convert.ToByte(0));
  1485. // 0 Kommentar-Felder
  1486. bw.Write(FilePack.dateToBytes());
  1487. if (Settings.UsePassword & !string.IsNullOrEmpty(Settings.Password))
  1488. FilePack.writePW1(ref bw, Settings.Password);
  1489. string[] f = { };
  1490. if (DirPath.EndsWith(IO.Path.DirectorySeparatorChar.ToString()) == false)
  1491. DirPath += IO.Path.DirectorySeparatorChar;
  1492. getFileList(DirPath, ref f);
  1493. string[] ext = { };
  1494. sFileInfo[] FileInfos = { };
  1495. int FileInfoCount = 0;
  1496. // File Count
  1497. ushort fc = 0;
  1498. foreach (string s in f)
  1499. if (s != DirPath) {
  1500. FileInfo fi = new FileInfo(s);
  1501. string itemName = fi.FullName.Substring(DirPath.Length, fi.FullName.Length - DirPath.Length - fi.Extension.Length);
  1502. if (itemName.Length < 240)
  1503. fc += 1;
  1504. }
  1505. bw.Write(fc);
  1506. foreach (string s in f) {
  1507. if (s != DirPath) {
  1508. FileInfo fi = new FileInfo(s);
  1509. byte extIndex = 0;
  1510. if (Array.IndexOf(ext, fi.Extension.ToLower().Substring(1)) > -1) {
  1511. for (byte i = 0; i < ext.Length; i++) {
  1512. if (ext[i] == fi.Extension.ToLower().Substring(1)) {
  1513. extIndex = i;
  1514. break; // TODO: might not be correct. Was : Exit For
  1515. }
  1516. }
  1517. } else {
  1518. extIndex = (byte)ext.Length;
  1519. Array.Resize(ref ext, extIndex + 1);
  1520. ext[extIndex] = fi.Extension.ToLower().Substring(1);
  1521. }
  1522. string itemName = fi.FullName.Substring(DirPath.Length, fi.FullName.Length - DirPath.Length - ext[extIndex].Length - 1);
  1523. // Pfad der geschrieben wird
  1524. FilePackElements.DataType type = FilePack.getDataType(ext[extIndex]);
  1525. // Maximal 240 Dateiendungen
  1526. if (itemName.Length < 240) {
  1527. Array.Resize(ref FileInfos, FileInfoCount + 1);
  1528. FileInfos[FileInfoCount] = new sFileInfo();
  1529. FileInfos[FileInfoCount].AbsolutePath = fi.FullName;
  1530. FileInfos[FileInfoCount].Extension = ext[extIndex];
  1531. FileInfos[FileInfoCount].ExtensionIndex = extIndex;
  1532. FileInfos[FileInfoCount].FileName = fi.Name;
  1533. FileInfos[FileInfoCount].FileSize = fi.Length;
  1534. FileInfos[FileInfoCount].Name = itemName;
  1535. FileInfos[FileInfoCount].Temp = System.IO.Path.GetTempFileName();
  1536. FileInfos[FileInfoCount].Type = type;
  1537. FilePack.Cons("Packe '" + fi.Name + "'", bCons);
  1538. // Erstelle eine Temporäre Datei mit den Inhalten
  1539. byte[] data = File.ReadAllBytes(fi.FullName);
  1540. 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)) {
  1541. IO.MemoryStream mem = new IO.MemoryStream();
  1542. System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Compress);
  1543. gz.Write(data, 0, data.Length);
  1544. data = mem.ToArray();
  1545. gz.Close();
  1546. mem.Close();
  1547. gz.Dispose();
  1548. mem.Dispose();
  1549. }
  1550. if (Settings.Crypt) {
  1551. if (Settings.UsePassword) {
  1552. data = FilePack.Encode(data, Settings.Password);
  1553. } else {
  1554. data = FilePack.Encode(data, "");
  1555. }
  1556. FileInfos[FileInfoCount].FileSize = data.Length;
  1557. }
  1558. File.WriteAllBytes(FileInfos[FileInfoCount].Temp, data);
  1559. // Trage die Daten in die ArchivDatei ein
  1560. // Keyword Daten schreiben
  1561. //Dim NameLen() As Byte = BitConverter.GetBytes(CByte(enc.GetBytes(FileInfos(FileInfoCount).Name).Length))
  1562. byte[] FileSize = BitConverter.GetBytes(Convert.ToInt64(FileInfos[FileInfoCount].FileSize));
  1563. //Dim FileType() As Byte = BitConverter.GetBytes(CByte(FileInfos(FileInfoCount).Type))
  1564. byte[] FileNameBytes = enc.GetBytes(FileInfos[FileInfoCount].Name);
  1565. fs.WriteByte((byte)enc.GetBytes(FileInfos[FileInfoCount].Name).Length);
  1566. // NameLen
  1567. //bw.Write(NameLen)
  1568. bw.Write(FileSize);
  1569. // Länge
  1570. fs.WriteByte(Convert.ToByte(FileInfos[FileInfoCount].Type));
  1571. // Type
  1572. //bw.Write(FileType) ' Typ
  1573. if (Settings.Extantions) {
  1574. fs.WriteByte(Convert.ToByte(FileInfos[FileInfoCount].ExtensionIndex));
  1575. } else {
  1576. fs.WriteByte(Convert.ToByte(0));
  1577. }
  1578. bw.Write(FileNameBytes);
  1579. FileInfoCount += 1;
  1580. }
  1581. }
  1582. }
  1583. if (Settings.Extantions) {
  1584. bw.Write(Convert.ToByte(ext.Length));
  1585. // Dateiendung (Anzahl)
  1586. foreach (string e in ext) {
  1587. bw.Write(Convert.ToByte(e.Length + 70));
  1588. bw.Write(enc.GetBytes(e));
  1589. }
  1590. }
  1591. FilePack.Cons("Schreibe Daten", bCons);
  1592. if (FileInfos.Length > 0) {
  1593. foreach (sFileInfo s in FileInfos) {
  1594. bw.Write(File.ReadAllBytes(s.Temp));
  1595. File.Delete(s.Temp);
  1596. }
  1597. }
  1598. bw.Close();
  1599. fs.Close();
  1600. fs.Dispose();
  1601. }
  1602. /// <summary>
  1603. /// Erstellt ein FilePack auf Basis eines Verzeichnisses.
  1604. /// </summary>
  1605. /// <param name="DirPath">Das Verzeichnis, dass Archiviert werden soll</param>
  1606. /// <param name="Destination">Die Zieldatei</param>
  1607. /// <remarks></remarks>
  1608. public void Save(string DirPath, string Destination) {
  1609. this.Save(DirPath, Destination, false);
  1610. }
  1611. /// <summary>
  1612. /// Erstellt ein FilePack auf Basis eines Verzeichnisses.
  1613. /// </summary>
  1614. /// <param name="DirPath">Das Verzeichnis, dass Archiviert werden soll</param>
  1615. /// <param name="Destination">Die Zieldatei</param>
  1616. /// <param name="bCons">Soll die Statusmeldungen in der Output Console angezeigt werden</param>
  1617. /// <remarks></remarks>
  1618. public void Save(string DirPath, string Destination, bool bCons) {
  1619. if (File.Exists(Destination)) {
  1620. throw new System.Fire.FilePack.Exception.Exception_ArchiveExists(Destination);
  1621. //return;
  1622. }
  1623. IO.DirectoryInfo di = new IO.DirectoryInfo(DirPath);
  1624. IO.FileStream fs = new IO.FileStream(Destination, FileMode.CreateNew);
  1625. IO.BinaryWriter bw = new IO.BinaryWriter(fs);
  1626. System.Text.Encoding enc = System.Text.Encoding.UTF8;
  1627. byte bpw = (byte)(this._settings | FilePackElements.eSet.UsePassword);
  1628. bool bUsePW = (bpw == (byte)this._settings) && this._Password != "";
  1629. bool bCrypt = (this._settings | FilePackElements.eSet.Crypt) == this._settings;
  1630. bool bDataGZip = (this._settings | FilePackElements.eSet.Data_GZip) == this._settings;
  1631. bool bTextGZip = (this._settings | FilePackElements.eSet.Text_GZip) == this._settings;
  1632. bool bExtantions = (this._settings | FilePackElements.eSet.Extantions) == this._settings;
  1633. FilePack.Cons("Create archive '" + di.Name + "' using password: " + (bUsePW ? "Yes" : "No"), bCons);
  1634. FilePack.Cons("Using Filepack Version: " + this.SignatureVersion.ToString(), bCons);
  1635. bw.Write(Signature);
  1636. bw.Write(Convert.ToByte(this.SignatureVersion));
  1637. bw.Write(Convert.ToByte(this._settings));
  1638. bw.Write(Convert.ToByte(this._commentCount));
  1639. // n Kommentar-Felder
  1640. bw.Write(FilePack.dateToBytes());
  1641. // Datum eintragen
  1642. if (bUsePW)
  1643. writePW1(ref bw, this._Password);
  1644. string[] f = { };
  1645. if (DirPath.EndsWith(IO.Path.DirectorySeparatorChar.ToString()) == false)
  1646. DirPath += IO.Path.DirectorySeparatorChar;
  1647. getFileList(DirPath, ref f);
  1648. string[] ext = { };
  1649. sFileInfo[] FileInfos = { };
  1650. int FileInfoCount = 0;
  1651. bw.Write(Convert.ToByte(this.keyCount));
  1652. // Keyword Count
  1653. foreach (string s in f) {
  1654. if (s != DirPath) {
  1655. FileInfo fi = new FileInfo(s);
  1656. byte extIndex = 0;
  1657. if (Array.IndexOf(ext, fi.Extension.ToLower().Substring(1)) > -1) {
  1658. for (byte i = 0; i < ext.Length; i++) {
  1659. if (ext[i] == fi.Extension.ToLower().Substring(1)) {
  1660. extIndex = i;
  1661. break; // TODO: might not be correct. Was : Exit For
  1662. }
  1663. }
  1664. } else {
  1665. extIndex = (byte)ext.Length;
  1666. Array.Resize(ref ext, extIndex + 1);
  1667. ext[extIndex] = fi.Extension.ToLower().Substring(1);
  1668. }
  1669. string itemName = fi.FullName.Substring(DirPath.Length, fi.FullName.Length - DirPath.Length - ext[extIndex].Length - 1);
  1670. // Pfad der geschrieben wird
  1671. FilePackElements.DataType type = getDataType(ext[extIndex]);
  1672. // Maximal 240 Dateiendungen
  1673. if (itemName.Length < 240) {
  1674. Array.Resize(ref FileInfos, FileInfoCount + 1);
  1675. FileInfos[FileInfoCount] = new sFileInfo();
  1676. FileInfos[FileInfoCount].AbsolutePath = fi.FullName;
  1677. FileInfos[FileInfoCount].Extension = ext[extIndex];
  1678. FileInfos[FileInfoCount].ExtensionIndex = extIndex;
  1679. FileInfos[FileInfoCount].FileName = fi.Name;
  1680. FileInfos[FileInfoCount].FileSize = fi.Length;
  1681. FileInfos[FileInfoCount].Name = itemName;
  1682. FileInfos[FileInfoCount].Temp = System.IO.Path.GetTempFileName();
  1683. FileInfos[FileInfoCount].Type = type;
  1684. FilePack.Cons("Packe '" + fi.Name + "'", bCons);
  1685. // Erstelle eine Temporäre Datei mit den Inhalten
  1686. byte[] data = File.ReadAllBytes(fi.FullName);
  1687. 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)) {
  1688. IO.MemoryStream mem = new IO.MemoryStream();
  1689. System.IO.Compression.GZipStream gz = new System.IO.Compression.GZipStream(mem, IO.Compression.CompressionMode.Compress);
  1690. gz.Write(data, 0, data.Length);
  1691. data = mem.ToArray();
  1692. gz.Close();
  1693. mem.Close();
  1694. gz.Dispose();
  1695. mem.Dispose();
  1696. }
  1697. if (bCrypt) {
  1698. if (bUsePW) {
  1699. data = FilePack.Encode(data, this._Password);
  1700. } else {
  1701. data = FilePack.Encode(data, "");
  1702. }
  1703. FileInfos[FileInfoCount].FileSize = data.Length;
  1704. }
  1705. File.WriteAllBytes(FileInfos[FileInfoCount].Temp, data);
  1706. // Trage die Daten in die ArchivDatei ein
  1707. // Keyword Daten schreiben
  1708. //Dim NameLen() As Byte = BitConverter.GetBytes(CByte(enc.GetBytes(FileInfos(FileInfoCount).Name).Length))
  1709. byte[] FileSize = BitConverter.GetBytes(Convert.ToInt64(FileInfos[FileInfoCount].FileSize));
  1710. //Dim FileType() As Byte = BitConverter.GetBytes(CByte(FileInfos(FileInfoCount).Type))
  1711. byte[] FileNameBytes = enc.GetBytes(FileInfos[FileInfoCount].Name);
  1712. fs.WriteByte((byte)enc.GetBytes(FileInfos[FileInfoCount].Name).Length);
  1713. // NameLen
  1714. //bw.Write(NameLen)
  1715. bw.Write(FileSize);
  1716. // Länge
  1717. fs.WriteByte(Convert.ToByte(FileInfos[FileInfoCount].Type));
  1718. // Type
  1719. //bw.Write(FileType) ' Typ
  1720. if (bExtantions) {
  1721. fs.WriteByte(Convert.ToByte(FileInfos[FileInfoCount].ExtensionIndex));
  1722. } else {
  1723. fs.WriteByte(Convert.ToByte(0));
  1724. }
  1725. bw.Write(FileNameBytes);
  1726. FileInfoCount += 1;
  1727. }
  1728. }
  1729. }
  1730. if (bExtantions) {
  1731. bw.Write(Convert.ToByte(ext.Length));
  1732. // Dateiendung (Anzahl)
  1733. foreach (string e in ext) {
  1734. bw.Write(Convert.ToByte(e.Length + 70));
  1735. bw.Write(enc.GetBytes(e));
  1736. }
  1737. }
  1738. FilePack.Cons("Schreibe Daten", bCons);
  1739. if (FileInfos.Length > 0) {
  1740. foreach (sFileInfo s in FileInfos) {
  1741. bw.Write(File.ReadAllBytes(s.Temp));
  1742. File.Delete(s.Temp);
  1743. }
  1744. }
  1745. bw.Close();
  1746. fs.Close();
  1747. fs.Dispose();
  1748. }
  1749. private static FilePackElements.DataType getDataType(string FileExt) {
  1750. switch (FileExt) {
  1751. // Typ
  1752. case "jpg":
  1753. return FilePackElements.DataType.dtImage;
  1754. case "jpeg":
  1755. return FilePackElements.DataType.dtImage;
  1756. case "gif":
  1757. return FilePackElements.DataType.dtImage;
  1758. case "png":
  1759. return FilePackElements.DataType.dtImage;
  1760. case "bmp":
  1761. return FilePackElements.DataType.dtImage;
  1762. case "dds":
  1763. return FilePackElements.DataType.dtUnsuportImage;
  1764. case "tif":
  1765. return FilePackElements.DataType.dtUnsuportImage;
  1766. case "cr2":
  1767. return FilePackElements.DataType.dtUnsuportImage;
  1768. case "tiff":
  1769. return FilePackElements.DataType.dtUnsuportImage;
  1770. case "dwf":
  1771. return FilePackElements.DataType.dtUnsuportImage;
  1772. case "dwg":
  1773. return FilePackElements.DataType.dtUnsuportImage;
  1774. case "dxf":
  1775. return FilePackElements.DataType.dtUnsuportImage;
  1776. case "3ds":
  1777. return FilePackElements.DataType.dtUnsuportImage;
  1778. case "mov":
  1779. return FilePackElements.DataType.dtVideo;
  1780. case "mpg":
  1781. return FilePackElements.DataType.dtVideo;
  1782. case "mp4":
  1783. return FilePackElements.DataType.dtVideo;
  1784. case "wmv":
  1785. return FilePackElements.DataType.dtVideo;
  1786. case "avi":
  1787. return FilePackElements.DataType.dtVideo;
  1788. case "mpeg":
  1789. return FilePackElements.DataType.dtVideo;
  1790. case "txt":
  1791. return FilePackElements.DataType.dtString;
  1792. case "log":
  1793. return FilePackElements.DataType.dtString;
  1794. case "wav":
  1795. return FilePackElements.DataType.dtAudio;
  1796. case "mp3":
  1797. return FilePackElements.DataType.dtAudio;
  1798. case "ogg":
  1799. return FilePackElements.DataType.dtAudio;
  1800. case "wma":
  1801. return FilePackElements.DataType.dtAudio;
  1802. case "js":
  1803. return FilePackElements.DataType.dtSourceCode;
  1804. case "vbs":
  1805. return FilePackElements.DataType.dtSourceCode;
  1806. case "html":
  1807. return FilePackElements.DataType.dtSourceCode;
  1808. case "css":
  1809. return FilePackElements.DataType.dtSourceCode;
  1810. case "c":
  1811. return FilePackElements.DataType.dtSourceCode;
  1812. case "cpp":
  1813. return FilePackElements.DataType.dtSourceCode;
  1814. case "h":
  1815. return FilePackElements.DataType.dtSourceCode;
  1816. case "vb":
  1817. return FilePackElements.DataType.dtSourceCode;
  1818. case "cs":
  1819. return FilePackElements.DataType.dtSourceCode;
  1820. case "vbproj":
  1821. return FilePackElements.DataType.dtSourceCode;
  1822. case "csproj":
  1823. return FilePackElements.DataType.dtSourceCode;
  1824. case "settings":
  1825. return FilePackElements.DataType.dtSourceCode;
  1826. case "xml":
  1827. return FilePackElements.DataType.dtSourceCode;
  1828. case "xls":
  1829. return FilePackElements.DataType.dtSourceCode;
  1830. case "resx":
  1831. return FilePackElements.DataType.dtSourceCode;
  1832. case "vcxproj":
  1833. return FilePackElements.DataType.dtSourceCode;
  1834. case "php":
  1835. return FilePackElements.DataType.dtSourceCode;
  1836. case "php3":
  1837. return FilePackElements.DataType.dtSourceCode;
  1838. case "php4":
  1839. return FilePackElements.DataType.dtSourceCode;
  1840. case "php5":
  1841. return FilePackElements.DataType.dtSourceCode;
  1842. case "php6":
  1843. return FilePackElements.DataType.dtSourceCode;
  1844. case "sln":
  1845. return FilePackElements.DataType.dtSourceCode;
  1846. case "ini":
  1847. return FilePackElements.DataType.dtConfiguration;
  1848. case "inf":
  1849. return FilePackElements.DataType.dtConfiguration;
  1850. case "dll":
  1851. return FilePackElements.DataType.dtExecuteable;
  1852. case "exe":
  1853. return FilePackElements.DataType.dtExecuteable;
  1854. case "com":
  1855. return FilePackElements.DataType.dtExecuteable;
  1856. case "bas":
  1857. return FilePackElements.DataType.dtExecuteable;
  1858. case "lib":
  1859. return FilePackElements.DataType.dtExecuteable;
  1860. default:
  1861. return FilePackElements.DataType.dtBinaryData;
  1862. }
  1863. }
  1864. private static void getFileList(string sPath, ref string[] sFiles) {
  1865. FileSystemInfo[] FSIs = new DirectoryInfo(sPath).GetFileSystemInfos();
  1866. foreach (FileSystemInfo FSI in FSIs) {
  1867. if (sFiles.Length < FileLimit) {
  1868. if (FSI is DirectoryInfo) {
  1869. getFileList(FSI.FullName + IO.Path.DirectorySeparatorChar.ToString(), ref sFiles);
  1870. } else {
  1871. int x = sFiles.Length;
  1872. Array.Resize(ref sFiles, x + 1);
  1873. sFiles[x] = FSI.FullName;
  1874. }
  1875. }
  1876. }
  1877. }
  1878. #endregion
  1879. #region "Date Functions"
  1880. private const int BaseYear = 1950;
  1881. private static byte[] dateToBytes() {
  1882. return FilePack.bitsToBytes(FilePack.dateToBits());
  1883. }
  1884. private static byte[] dateToBytes(ref System.DateTime xDate) {
  1885. return FilePack.bitsToBytes(FilePack.dateToBits(xDate));
  1886. }
  1887. private static bool[] dateToBits() {
  1888. return FilePack.dateToBits(System.DateTime.UtcNow);
  1889. }
  1890. private static bool[] dateToBits(System.DateTime xDate) {
  1891. int xyear = xDate.Year - FilePack.BaseYear;
  1892. bool[] bits = new bool[40];
  1893. if (xDate.Kind != DateTimeKind.Utc)
  1894. xDate = xDate.ToUniversalTime();
  1895. // Year
  1896. for (int i = 0; i <= 8; i++) {
  1897. int x = (xyear | ((int)Math.Pow(2, i)));
  1898. bits[8 - i] = x == xyear;
  1899. }
  1900. // Month
  1901. for (int i = 0; i <= 4; i++) {
  1902. int x = (xDate.Month | (int)(Math.Pow(2, i)));
  1903. bits[13 - i] = x == xDate.Month;
  1904. }
  1905. // Day
  1906. for (int i = 0; i <= 5; i++) {
  1907. int x = (xDate.Day | (int)(Math.Pow(2, i)));
  1908. bits[19 - i] = x == xDate.Day;
  1909. }
  1910. // Hour
  1911. for (int i = 0; i <= 5; i++) {
  1912. int x = (xDate.Hour | (int)(Math.Pow(2, i)));
  1913. bits[25 - i] = x == xDate.Hour;
  1914. }
  1915. // Minute
  1916. for (int i = 0; i <= 6; i++) {
  1917. int x = (xDate.Minute | (int)(Math.Pow(2, i)));
  1918. bits[32 - i] = x == xDate.Minute;
  1919. }
  1920. // Seconds
  1921. for (int i = 0; i <= 6; i++) {
  1922. int x = (xDate.Second | (int)(Math.Pow(2, i)));
  1923. bits[39 - i] = x == xDate.Second;
  1924. }
  1925. return bits;
  1926. }
  1927. private static byte[] bitsToBytes(bool[] b) {
  1928. byte[] tmp = new byte[((int)Math.Ceiling((decimal)(b.Length / 8)))];
  1929. for (int i = 0; i < Math.Ceiling((decimal)(b.Length / 8)); i++) {
  1930. for (int j = 0; j <= 7; j++) {
  1931. if (b.Length > (i * 8) + j)
  1932. if (b[(i * 8) + j])
  1933. tmp[i] = (byte)(tmp[i] | (byte)(Math.Pow(2, j)));
  1934. }
  1935. }
  1936. return tmp;
  1937. }
  1938. private static bool[] bytesToBits(byte[] b) {
  1939. bool[] tmp = new bool[(b.Length * 8)];
  1940. for (int i = 0; i < b.Length; i++) {
  1941. for (int j = 0; j <= 7; j++) {
  1942. byte bIs = (byte)(b[i] | (byte)(Math.Pow(2, j)));
  1943. tmp[(i * 8) + j] = bIs == b[i];
  1944. }
  1945. }
  1946. return tmp;
  1947. }
  1948. private static System.DateTime bitsToDate(byte[] b) {
  1949. return FilePack.bitsToDate(FilePack.bytesToBits(b));
  1950. }
  1951. private static System.DateTime bitsToDate(bool[] b) {
  1952. int iDay = 0;
  1953. int iMonth = 0;
  1954. int iYear = 0;
  1955. int iHours = 0;
  1956. int iMinutes = 0;
  1957. int iSeconds = 0;
  1958. // Year
  1959. for (int i = 0; i <= 8; i++) {
  1960. if (b[8 - i] == true)
  1961. iYear = iYear | (int)(Math.Pow(2, i));
  1962. }
  1963. // Month
  1964. for (int i = 0; i <= 4; i++) {
  1965. if (b[13 - i] == true)
  1966. iMonth = iMonth | (int)(Math.Pow(2, i));
  1967. }
  1968. // Day
  1969. for (int i = 0; i <= 5; i++) {
  1970. if (b[19 - i] == true)
  1971. iDay = iDay | (int)(Math.Pow(2, i));
  1972. }
  1973. // Hour
  1974. for (int i = 0; i <= 5; i++) {
  1975. if (b[25 - i] == true)
  1976. iHours = iHours | (int)(Math.Pow(2, i));
  1977. }
  1978. // Minutes
  1979. for (int i = 0; i <= 6; i++) {
  1980. if (b[32 - i] == true)
  1981. iMinutes = iMinutes | (int)(Math.Pow(2, i));
  1982. }
  1983. // Seconds
  1984. for (int i = 0; i <= 6; i++) {
  1985. if (b[39 - i] == true)
  1986. iSeconds = iSeconds | (int)(Math.Pow(2, i));
  1987. }
  1988. return new System.DateTime(iYear + FilePack.BaseYear, iMonth, iDay, iHours, iMinutes, iSeconds, System.DateTimeKind.Utc);
  1989. }
  1990. #endregion
  1991. #region "Shared Functions"
  1992. /// <summary>
  1993. /// Überprüft ob das Archiv <para>Filepath</para> gültig ist
  1994. /// </summary>
  1995. /// <param name="Filepath">Gibt den Pfad des Archives an.</param>
  1996. /// <returns>Gibt bei erfolgreicher Prüfung true zurück. false falls das Archiv nicht gültig ist.</returns>
  1997. public static bool IsValide(string Filepath) {
  1998. if (File.Exists(Filepath)) {
  1999. FileStream tstream = new FileStream(Filepath, FileMode.Open);
  2000. if (tstream.Length < 17) {
  2001. tstream.Close();
  2002. tstream.Dispose();
  2003. return false;
  2004. } else {
  2005. BinaryReader tb = new BinaryReader(tstream);
  2006. byte[] s = tb.ReadBytes(10);
  2007. if (FilePack.checkSignature(s)) {
  2008. FilePackElements.eVersion SignatureVersion = (FilePackElements.eVersion)tb.ReadByte();
  2009. tb.Close();
  2010. tstream.Close();
  2011. tstream.Dispose();
  2012. switch (SignatureVersion) {
  2013. case FilePackElements.eVersion.Version_1_0:
  2014. return true;
  2015. default:
  2016. return false;
  2017. }
  2018. } else {
  2019. tb.Close();
  2020. tstream.Close();
  2021. tstream.Dispose();
  2022. return false;
  2023. }
  2024. }
  2025. } else {
  2026. return false;
  2027. }
  2028. }
  2029. /// <summary>
  2030. /// Gibt die Archiv-Version der angegebenen Datei zurück.
  2031. /// </summary>
  2032. /// <param name="Filepath">Gibt den Pfad des Archives an.</param>
  2033. /// <returns>Gibt die Archiv-Version der angegebenen Datei zurück.</returns>
  2034. public static FilePackElements.eVersion GetFileVersion(string Filepath) {
  2035. if (File.Exists(Filepath)) {
  2036. FileStream tstream = new FileStream(Filepath, FileMode.Open);
  2037. if (tstream.Length < 17) {
  2038. tstream.Close();
  2039. tstream.Dispose();
  2040. return FilePackElements.eVersion.Unsuported;
  2041. } else {
  2042. BinaryReader tb = new BinaryReader(tstream);
  2043. byte[] s = tb.ReadBytes(10);
  2044. if (FilePack.checkSignature(s)) {
  2045. FilePackElements.eVersion sv = (FilePackElements.eVersion)tb.ReadByte();
  2046. tb.Close();
  2047. tstream.Close();
  2048. tstream.Dispose();
  2049. return sv;
  2050. } else {
  2051. tb.Close();
  2052. tstream.Close();
  2053. tstream.Dispose();
  2054. return FilePackElements.eVersion.Unsuported;
  2055. }
  2056. }
  2057. } else {
  2058. return FilePackElements.eVersion.Unsuported;
  2059. }
  2060. }
  2061. /// <summary>
  2062. /// Überprüft das angegebene Archiv <para>Filepath</para> ob dieses mit einem Passwort geschützt ist.
  2063. /// </summary>
  2064. /// <param name="Filepath">Gibt den Pfad des Archives an.</param>
  2065. /// <returns>true, wenn das angegebene Archiv mit einem Passwort geschützt ist. false wenn das Archiv nicht mit einem Passwort geschützt ist.</returns>
  2066. public static bool IsPasswordProtectedFile(string Filepath) {
  2067. if (File.Exists(Filepath)) {
  2068. FileStream tstream = new FileStream(Filepath, FileMode.Open);
  2069. if (tstream.Length < 17) {
  2070. tstream.Close();
  2071. tstream.Dispose();
  2072. return false;
  2073. } else {
  2074. BinaryReader tb = new BinaryReader(tstream);
  2075. byte[] s = tb.ReadBytes(10);
  2076. if (FilePack.checkSignature(s)) {
  2077. tb.ReadByte();
  2078. FilePackElements.eSet xset = (FilePackElements.eSet)tb.ReadByte();
  2079. byte upw = (byte)(xset | FilePackElements.eSet.UsePassword);
  2080. tb.Close();
  2081. tstream.Close();
  2082. tstream.Dispose();
  2083. return (upw == (byte)xset);
  2084. } else {
  2085. tb.Close();
  2086. tstream.Close();
  2087. tstream.Dispose();
  2088. return false;
  2089. }
  2090. }
  2091. } else {
  2092. return false;
  2093. }
  2094. }
  2095. #endregion
  2096. }
  2097. }