Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- namespace ZIPTimers
- {
- class Program
- {
- private static Dictionary<int, string> compresionTypes
- = new Dictionary<int, string>();
- //LZMA, LZMA2, PPMd, BZip2
- //Deflate, Deflate64, BZip2, LZMA,PPMd
- private static Dictionary<int, string> compresionTypesZip
- = new Dictionary<int, string>();
- private static Dictionary<int, string> archivesTypes
- = new Dictionary<int, string>();
- private static Dictionary<string, string> compresionSpeed
- = new Dictionary<string, string>();
- private static string TxtFiles = @"\txt";
- private static string SMALLBMP = @"\bmp small";
- private static string JPGBIG = @"\jpg big";
- private static string AUDIPMP3 = @"\audio mp3";
- private static string VAWMP3 = @"\video mpg";
- private static void Init()
- {
- compresionTypes.Add(1, "PPMd");
- compresionTypes.Add(2, "LZMA");
- compresionTypes.Add(3, "LZMA2");
- compresionTypes.Add(4, "BZip2");
- compresionTypesZip.Add(1, "Deflate");
- compresionTypesZip.Add(2, "Deflate64");
- compresionTypesZip.Add(3, "BZip2");
- compresionTypesZip.Add(4, "LZMA");
- compresionTypesZip.Add(5, "PPMd");
- archivesTypes.Add(1, "-t7z");
- archivesTypes.Add(2, "-tzip");
- compresionSpeed.Add("fast", "mx=3");
- compresionSpeed.Add("normal", "mx=5");
- compresionSpeed.Add("ultra", "mx=9");
- }
- private static void WriteCollectionOnScreen(Dictionary<int, string> collection)
- {
- foreach (var type in collection)
- {
- Console.WriteLine($"{type.Key}. {type.Value}");
- }
- }
- static void Main(string[] args)
- {
- Init();
- var mainDirectory = @"D:\Pliki testowe";
- var archiveDirectory = @"D:\Archive\test";
- Console.WriteLine("Archwizacja danych do formatu .7z!");
- WriteCollectionOnScreen(compresionTypes);
- Console.WriteLine("Archwizacja danych do formatu .zip!");
- WriteCollectionOnScreen(compresionTypesZip);
- Console.WriteLine("Wybierz rodzaj kompresji:");
- WriteCollectionOnScreen(archivesTypes);
- Console.WriteLine("Zadanie 1");
- foreach (var output in archivesTypes)
- {
- switch (output.Key)
- {
- case 1:
- foreach (var types in compresionTypes)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine($"Algorytm: {types}, output type: {output.Value}");
- Console.ForegroundColor = ConsoleColor.White;
- Execute7z(archiveDirectory, mainDirectory, types.Value, output.Key, "mx=9");
- }
- break;
- case 2:
- foreach (var types in compresionTypesZip)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine($"Algorytm: {types}, output type: {output.Value}");
- Console.ForegroundColor = ConsoleColor.White;
- Execute7z(archiveDirectory, mainDirectory, types.Value, output.Key, "mx=9");
- }
- break;
- }
- }
- Console.WriteLine("Zadanie 1b");
- foreach (var speeds in compresionSpeed)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine($"Algorytm: LZMA2, output type: -t7z");
- Console.ForegroundColor = ConsoleColor.White;
- Execute7z(archiveDirectory, mainDirectory, "LZMA2", 1, speeds.Value);
- }
- Console.WriteLine("Zadanie 2");
- var textDirectory = mainDirectory + TxtFiles;
- var archive = archiveDirectory + TxtFiles + @"\test";
- foreach (var output in archivesTypes)
- {
- switch (output.Key)
- {
- case 1:
- foreach (var types in compresionTypes)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine($"Algorytm: {types}, output type: {output.Value}");
- Console.ForegroundColor = ConsoleColor.White;
- Execute7z(archive, textDirectory, types.Value, output.Key, "mx=9");
- }
- break;
- case 2:
- foreach (var types in compresionTypesZip)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine($"Algorytm: {types}, output type: {output.Value}");
- Console.ForegroundColor = ConsoleColor.White;
- Execute7z(archive, textDirectory, types.Value, output.Key, "mx=9");
- }
- break;
- }
- }
- Console.WriteLine("Zadanie 3");
- var smallBMPDirectory = mainDirectory + SMALLBMP;
- var smallBMParchive = archiveDirectory + SMALLBMP + @"\test";
- foreach (var output in archivesTypes)
- {
- switch (output.Key)
- {
- case 1:
- foreach (var types in compresionTypes)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine($"Algorytm: {types}, output type: {output.Value}");
- Console.ForegroundColor = ConsoleColor.White;
- Execute7z(smallBMParchive, smallBMPDirectory, types.Value, output.Key, "mx=9");
- }
- break;
- case 2:
- foreach (var types in compresionTypesZip)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine($"Algorytm: {types}, output type: {output.Value}");
- Console.ForegroundColor = ConsoleColor.White;
- Execute7z(smallBMParchive, smallBMPDirectory, types.Value, output.Key, "mx=9");
- }
- break;
- }
- }
- foreach (var speeds in compresionSpeed)
- {
- var bigJpDirectory = mainDirectory + JPGBIG;
- var bigJppArchive = archiveDirectory + JPGBIG + @"\test";
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine($"Algorytm: LZMA2, output type: -t7z");
- Console.ForegroundColor = ConsoleColor.White;
- Execute7z(archiveDirectory, mainDirectory, "LZMA2", 1, speeds.Value);
- }
- Console.WriteLine("Zadanie 4");
- var mp3Directory = mainDirectory + VAWMP3;
- var mp3archive = archiveDirectory + VAWMP3 + @"\test";
- foreach (var output in archivesTypes)
- {
- switch (output.Key)
- {
- case 1:
- foreach (var types in compresionTypes)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine($"Algorytm: {types}, output type: {output.Value}");
- Console.ForegroundColor = ConsoleColor.White;
- Execute7z(mp3archive, mp3Directory, types.Value, output.Key, "mx=9");
- }
- break;
- case 2:
- foreach (var types in compresionTypesZip)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine($"Algorytm: {types}, output type: {output.Value}");
- Console.ForegroundColor = ConsoleColor.White;
- Execute7z(mp3archive, mp3Directory, types.Value, output.Key, "mx=9");
- }
- break;
- }
- }
- }
- static void Execute7z(string archiveDirectory, string mainDirectory, string algorithm, int output, string speed)
- {
- Process cmd = ProcessFactory.Create();
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Program 7z rozpoczyna pracę...");
- cmd.Start();
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- Console.ForegroundColor = ConsoleColor.Green;
- string commnad = $"7za a -t7z -m0={algorithm} -{speed} \"{archiveDirectory}\" \"{mainDirectory}\" ";
- if(output == 1)
- {
- commnad = $"7za a -t7z -m0={algorithm} -{speed} \"{archiveDirectory}\" \"{mainDirectory}\" ";
- }
- else
- {
- commnad = $"7za a -tzip -mm={algorithm} \"{archiveDirectory}\" \"{mainDirectory}\" -{speed}";
- }
- cmd.StandardInput.WriteLine(commnad);
- Console.WriteLine(commnad);
- Console.WriteLine("Archiwizuje...");
- cmd.StandardInput.Flush();
- cmd.StandardInput.Close();
- cmd.WaitForExit();
- stopwatch.Stop();
- TimeSpan ts = stopwatch.Elapsed;
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.WriteLine("Czas archiwizacji {0:00}:{1:00}:{2:00}.{3}",
- ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
- var cmdOutput = cmd.StandardOutput.ReadToEnd();
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Informacje zwrócone przez 7z:");
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine(cmdOutput);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement