// Spludlow Software // Copyright © Samuel P. Ludlow 2020 All Rights Reserved // Distributed under the terms of the GNU General Public License version 3 // Distributed WITHOUT ANY WARRANTY; without implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE // https://www.spludlow.co.uk/LICENCE.TXT // The Spludlow logo is a registered trademark of Samuel P. Ludlow and may not be used without permission // v1.14 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace Spludlow { public class Compress { public static void ReCompress(string storeArchiveFilename) { ReCompress(storeArchiveFilename, Spludlow.Config.Get("Spludlow.Compress")); } public static void ReCompress(string storeArchiveFilename, string workAddress) { Spludlow.Call.Queue(workAddress, "Spludlow", "Spludlow.Compress", "RecieveReCompress", new object[] { Environment.MachineName, storeArchiveFilename }); } public static string ExtractedItem(string directory) { string[] items = Directory.GetDirectories(directory); if (items.Length == 1) return items[0]; if (items.Length > 1) throw new ApplicationException("ExtractedItem; More than one directory:\t" + directory); items = Directory.GetFiles(directory); if (items.Length == 1) return items[0]; if (items.Length > 1) throw new ApplicationException("ExtractedItem; More than one file:\t" + directory); throw new ApplicationException("ExtractedItem; No directory or file:\t" + directory); } public static void RecieveReCompress(string host, string remoteFilename) { using (Spludlow.TempDirectory tempDir0 = new TempDirectory()) { using (Spludlow.TempDirectory tempDir1 = new TempDirectory("@Spludlow.Temp1")) { Spludlow.SpeedProfile speed = new SpeedProfile("RecieveReCompress"); string localFilename = tempDir0 + @"\" + Path.GetFileName(remoteFilename); speed.Reset(); Spludlow.Call.Download(host, remoteFilename, localFilename); speed.Submit("Download"); long startSize = Spludlow.Io.Files.FileLength(localFilename); speed.Reset(); Spludlow.Archive.Extract(localFilename, tempDir1.Path); speed.Submit("Extract"); File.Delete(localFilename); string source = ExtractedItem(tempDir1.Path); localFilename = tempDir0.Path + @"\" + Path.GetFileName(source) + ".7z"; speed.Reset(); Spludlow.Archive.Create(localFilename, source); speed.Submit("Archive"); long endSize = Spludlow.Io.Files.FileLength(localFilename); speed.Reset(); Spludlow.Call.Upload(host, localFilename, remoteFilename); speed.Submit("Upload"); string sizeText = remoteFilename + ", " + Spludlow.Text.DataSize(startSize) + " -> " + Spludlow.Text.DataSize(endSize); speed.LogFinish("RecieveReCompress; Finihsed. " + sizeText + ", Speed Report"); } } } } }