Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5.  
  6. namespace ZIPTimers
  7. {
  8. class Program
  9. {
  10. private static Dictionary<int, string> compresionTypes
  11. = new Dictionary<int, string>();
  12. //LZMA, LZMA2, PPMd, BZip2
  13.  
  14. //Deflate, Deflate64, BZip2, LZMA,PPMd
  15. private static Dictionary<int, string> compresionTypesZip
  16. = new Dictionary<int, string>();
  17.  
  18. private static Dictionary<int, string> archivesTypes
  19. = new Dictionary<int, string>();
  20.  
  21. private static Dictionary<string, string> compresionSpeed
  22. = new Dictionary<string, string>();
  23.  
  24. private static string TxtFiles = @"\txt";
  25.  
  26. private static string SMALLBMP = @"\bmp small";
  27. private static string JPGBIG = @"\jpg big";
  28.  
  29. private static string AUDIPMP3 = @"\audio mp3";
  30. private static string VAWMP3 = @"\video mpg";
  31. private static void Init()
  32. {
  33. compresionTypes.Add(1, "PPMd");
  34. compresionTypes.Add(2, "LZMA");
  35. compresionTypes.Add(3, "LZMA2");
  36. compresionTypes.Add(4, "BZip2");
  37.  
  38. compresionTypesZip.Add(1, "Deflate");
  39. compresionTypesZip.Add(2, "Deflate64");
  40. compresionTypesZip.Add(3, "BZip2");
  41. compresionTypesZip.Add(4, "LZMA");
  42. compresionTypesZip.Add(5, "PPMd");
  43.  
  44. archivesTypes.Add(1, "-t7z");
  45. archivesTypes.Add(2, "-tzip");
  46.  
  47. compresionSpeed.Add("fast", "mx=3");
  48. compresionSpeed.Add("normal", "mx=5");
  49. compresionSpeed.Add("ultra", "mx=9");
  50. }
  51. private static void WriteCollectionOnScreen(Dictionary<int, string> collection)
  52. {
  53. foreach (var type in collection)
  54. {
  55. Console.WriteLine($"{type.Key}. {type.Value}");
  56. }
  57. }
  58. static void Main(string[] args)
  59. {
  60. Init();
  61. var mainDirectory = @"D:\Pliki testowe";
  62. var archiveDirectory = @"D:\Archive\test";
  63.  
  64. Console.WriteLine("Archwizacja danych do formatu .7z!");
  65. WriteCollectionOnScreen(compresionTypes);
  66. Console.WriteLine("Archwizacja danych do formatu .zip!");
  67. WriteCollectionOnScreen(compresionTypesZip);
  68. Console.WriteLine("Wybierz rodzaj kompresji:");
  69. WriteCollectionOnScreen(archivesTypes);
  70.  
  71. Console.WriteLine("Zadanie 1");
  72. foreach (var output in archivesTypes)
  73. {
  74. switch (output.Key)
  75. {
  76. case 1:
  77. foreach (var types in compresionTypes)
  78. {
  79. Console.ForegroundColor = ConsoleColor.Red;
  80. Console.WriteLine($"Algorytm: {types}, output type: {output.Value}");
  81. Console.ForegroundColor = ConsoleColor.White;
  82. Execute7z(archiveDirectory, mainDirectory, types.Value, output.Key, "mx=9");
  83. }
  84. break;
  85. case 2:
  86. foreach (var types in compresionTypesZip)
  87. {
  88. Console.ForegroundColor = ConsoleColor.Red;
  89. Console.WriteLine($"Algorytm: {types}, output type: {output.Value}");
  90. Console.ForegroundColor = ConsoleColor.White;
  91. Execute7z(archiveDirectory, mainDirectory, types.Value, output.Key, "mx=9");
  92. }
  93. break;
  94.  
  95. }
  96. }
  97. Console.WriteLine("Zadanie 1b");
  98. foreach (var speeds in compresionSpeed)
  99. {
  100. Console.ForegroundColor = ConsoleColor.Red;
  101. Console.WriteLine($"Algorytm: LZMA2, output type: -t7z");
  102. Console.ForegroundColor = ConsoleColor.White;
  103. Execute7z(archiveDirectory, mainDirectory, "LZMA2", 1, speeds.Value);
  104. }
  105. Console.WriteLine("Zadanie 2");
  106. var textDirectory = mainDirectory + TxtFiles;
  107. var archive = archiveDirectory + TxtFiles + @"\test";
  108. foreach (var output in archivesTypes)
  109. {
  110. switch (output.Key)
  111. {
  112. case 1:
  113. foreach (var types in compresionTypes)
  114. {
  115. Console.ForegroundColor = ConsoleColor.Red;
  116. Console.WriteLine($"Algorytm: {types}, output type: {output.Value}");
  117. Console.ForegroundColor = ConsoleColor.White;
  118. Execute7z(archive, textDirectory, types.Value, output.Key, "mx=9");
  119. }
  120. break;
  121. case 2:
  122. foreach (var types in compresionTypesZip)
  123. {
  124. Console.ForegroundColor = ConsoleColor.Red;
  125. Console.WriteLine($"Algorytm: {types}, output type: {output.Value}");
  126. Console.ForegroundColor = ConsoleColor.White;
  127. Execute7z(archive, textDirectory, types.Value, output.Key, "mx=9");
  128. }
  129. break;
  130.  
  131. }
  132. }
  133. Console.WriteLine("Zadanie 3");
  134. var smallBMPDirectory = mainDirectory + SMALLBMP;
  135. var smallBMParchive = archiveDirectory + SMALLBMP + @"\test";
  136. foreach (var output in archivesTypes)
  137. {
  138. switch (output.Key)
  139. {
  140. case 1:
  141. foreach (var types in compresionTypes)
  142. {
  143. Console.ForegroundColor = ConsoleColor.Red;
  144. Console.WriteLine($"Algorytm: {types}, output type: {output.Value}");
  145. Console.ForegroundColor = ConsoleColor.White;
  146. Execute7z(smallBMParchive, smallBMPDirectory, types.Value, output.Key, "mx=9");
  147. }
  148. break;
  149. case 2:
  150. foreach (var types in compresionTypesZip)
  151. {
  152. Console.ForegroundColor = ConsoleColor.Red;
  153. Console.WriteLine($"Algorytm: {types}, output type: {output.Value}");
  154. Console.ForegroundColor = ConsoleColor.White;
  155. Execute7z(smallBMParchive, smallBMPDirectory, types.Value, output.Key, "mx=9");
  156. }
  157. break;
  158.  
  159. }
  160. }
  161.  
  162. foreach (var speeds in compresionSpeed)
  163. {
  164. var bigJpDirectory = mainDirectory + JPGBIG;
  165. var bigJppArchive = archiveDirectory + JPGBIG + @"\test";
  166. Console.ForegroundColor = ConsoleColor.Red;
  167. Console.WriteLine($"Algorytm: LZMA2, output type: -t7z");
  168. Console.ForegroundColor = ConsoleColor.White;
  169. Execute7z(archiveDirectory, mainDirectory, "LZMA2", 1, speeds.Value);
  170. }
  171.  
  172. Console.WriteLine("Zadanie 4");
  173. var mp3Directory = mainDirectory + VAWMP3;
  174. var mp3archive = archiveDirectory + VAWMP3 + @"\test";
  175. foreach (var output in archivesTypes)
  176. {
  177. switch (output.Key)
  178. {
  179. case 1:
  180. foreach (var types in compresionTypes)
  181. {
  182. Console.ForegroundColor = ConsoleColor.Red;
  183. Console.WriteLine($"Algorytm: {types}, output type: {output.Value}");
  184. Console.ForegroundColor = ConsoleColor.White;
  185. Execute7z(mp3archive, mp3Directory, types.Value, output.Key, "mx=9");
  186. }
  187. break;
  188. case 2:
  189. foreach (var types in compresionTypesZip)
  190. {
  191. Console.ForegroundColor = ConsoleColor.Red;
  192. Console.WriteLine($"Algorytm: {types}, output type: {output.Value}");
  193. Console.ForegroundColor = ConsoleColor.White;
  194. Execute7z(mp3archive, mp3Directory, types.Value, output.Key, "mx=9");
  195. }
  196. break;
  197.  
  198. }
  199. }
  200. }
  201.  
  202. static void Execute7z(string archiveDirectory, string mainDirectory, string algorithm, int output, string speed)
  203. {
  204. Process cmd = ProcessFactory.Create();
  205.  
  206.  
  207. Console.ForegroundColor = ConsoleColor.Red;
  208. Console.WriteLine("Program 7z rozpoczyna pracę...");
  209. cmd.Start();
  210.  
  211. Stopwatch stopwatch = new Stopwatch();
  212. stopwatch.Start();
  213. Console.ForegroundColor = ConsoleColor.Green;
  214. string commnad = $"7za a -t7z -m0={algorithm} -{speed} \"{archiveDirectory}\" \"{mainDirectory}\" ";
  215. if(output == 1)
  216. {
  217. commnad = $"7za a -t7z -m0={algorithm} -{speed} \"{archiveDirectory}\" \"{mainDirectory}\" ";
  218. }
  219. else
  220. {
  221. commnad = $"7za a -tzip -mm={algorithm} \"{archiveDirectory}\" \"{mainDirectory}\" -{speed}";
  222. }
  223. cmd.StandardInput.WriteLine(commnad);
  224. Console.WriteLine(commnad);
  225. Console.WriteLine("Archiwizuje...");
  226. cmd.StandardInput.Flush();
  227. cmd.StandardInput.Close();
  228. cmd.WaitForExit();
  229. stopwatch.Stop();
  230. TimeSpan ts = stopwatch.Elapsed;
  231. Console.ForegroundColor = ConsoleColor.Yellow;
  232. Console.WriteLine("Czas archiwizacji {0:00}:{1:00}:{2:00}.{3}",
  233. ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
  234. var cmdOutput = cmd.StandardOutput.ReadToEnd();
  235.  
  236. Console.ForegroundColor = ConsoleColor.Red;
  237. Console.WriteLine("Informacje zwrócone przez 7z:");
  238. Console.ForegroundColor = ConsoleColor.White;
  239. Console.WriteLine(cmdOutput);
  240. }
  241.  
  242. }
  243. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement