public void CancelTask() { try { if (repo.Active) { repo.CancelDownloads(); Active = false; Status = "Task cancelled"; ComicConvert.ImgsToCbz(repo.Location, OutputFileName); if (TaskCancelled != null) { TaskCancelled.Invoke(this, new EventArgs()); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } Active = false; Status = "Task cancelled"; if (TaskCancelled != null) { TaskCancelled.Invoke(this, new EventArgs()); } }
public void OnMultipleDownloadsCompleted(object sender, EventArgs e) { ComicConvert.ImgsToCbz(repo.Location, OutputFileName); Active = false; Status = "Finished"; if (TaskCompleted != null) { TaskCompleted.Invoke(this, new EventArgs()); } }
public void Naming() { var dir = Path.GetFullPath("TestFilesSMBC"); var myCbz = "MyTestFile_2"; // check it worked Assert.IsTrue(ComicConvert.ImgsToCbz(dir, myCbz)); Assert.IsTrue(File.Exists(myCbz + ".zip")); File.Delete(myCbz + ".zip"); myCbz = "MyTestFile_2.zip"; Assert.IsTrue(ComicConvert.ImgsToCbz(dir, myCbz)); Assert.IsTrue(File.Exists(myCbz)); File.Delete(myCbz); }
public void OnSingleDownloadCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { NumberDownloaded += 1; // update status, don't contradict MultipleDownloadsCompleted if (NumberDownloaded != NumberToDownload) { Status = String.Format("Downloading {0}", repo.CurrentlyDownloadingUrl); } // efficient dumping behaviour if (NumberDownloaded % 10 == 0) { ComicConvert.ImgsToCbz(repo.Location, OutputFileName); } if (FileDownloaded != null) { FileDownloaded.Invoke(sender, e); } }
public void ImgsToCbz() { var dir = Path.GetFullPath("TestFilesSMBC"); var myCbz = "MyTestFile_2.cbz"; // check it worked Assert.IsTrue(ComicConvert.ImgsToCbz(dir, myCbz)); Assert.IsTrue(File.Exists(myCbz)); // check sizes indicate compression var combinedSizeOfFiles = Directory.GetFiles(dir).Select <string, long> (x => (new FileInfo(x)).Length).Sum(); var sizeOfMyCbz = (new FileInfo(myCbz)).Length; Assert.Greater(combinedSizeOfFiles, sizeOfMyCbz); Assert.Greater(sizeOfMyCbz, combinedSizeOfFiles / 2); // clean up File.Delete(myCbz); }
public void EmptyFilesNotIncluded() { var dir = Path.GetFullPath("TestFilesSMBC"); var myCbz = "MyTestFile_2.cbz"; // create once with no empty files Assert.IsTrue(ComicConvert.ImgsToCbz(dir, myCbz)); Assert.IsTrue(File.Exists(myCbz)); var sizeBefore = (new FileInfo(myCbz)).Length; File.Delete(myCbz); // create some empty files var origNum = Directory.GetFiles(dir).Where <string> (x => x.Contains(".gif")).Count(); for (int i = 0; i < 10; i++) { File.Create(Path.Combine(dir, String.Format("blank_{0}.txt", i))); } Assert.AreEqual(10 + origNum, Directory.GetFiles(dir).Where <string> (x => x.Contains(".gif") || x.Contains(".txt")).Count()); // create again with empty files Assert.IsTrue(ComicConvert.ImgsToCbz(dir, myCbz)); Assert.IsTrue(File.Exists(myCbz)); var sizeAfter = (new FileInfo(myCbz)).Length; Assert.AreEqual(sizeBefore, sizeAfter); // unzip it and count var tempDir = "MyTestFile_2"; ComicConvert.CbzToImgs(myCbz); Assert.AreEqual(origNum, Directory.GetFiles(tempDir).Where <string> (x => x.Contains(".gif") || x.Contains(".txt")).Count()); // clean up foreach (var x in Directory.GetFiles(tempDir)) { File.Delete(x); } Directory.Delete(tempDir); File.Delete(myCbz); }
public void AddToCbz() { var dir = Path.GetFullPath("TestFilesSMBC"); var myCbz = "MyTestFile_2.cbz"; var fileName = "extra.gif"; // check original compression worked Assert.IsTrue(ComicConvert.ImgsToCbz(dir, myCbz)); Assert.IsTrue(File.Exists(myCbz)); var sizeBefore = (new FileInfo(myCbz)).Length; // check adding Assert.IsTrue(ComicConvert.AddToCbz(fileName, myCbz)); // check sizes indicate added file var sizeAfter = (new FileInfo(myCbz)).Length; Assert.Greater(sizeAfter, sizeBefore); // clean up File.Delete(myCbz); }
public void DownloadAndAdd() { // Add to existing: var dir = Path.GetFullPath("TestFilesSMBC"); var myCbz = "MyTestFile_2.cbz"; var urls = new List <string> (); urls.Add("http://www.smbc-comics.com/comics/20061111.gif"); // check original compression worked Assert.IsTrue(ComicConvert.ImgsToCbz(dir, myCbz)); Assert.IsTrue(File.Exists(myCbz)); var sizeBefore = (new FileInfo(myCbz)).Length; // download and add using (var repo = new Repository()) { // add a turnstile AutoResetEvent auto = new AutoResetEvent(false); // event handler allows program to progress (in case of cancel failure) repo.MultipleDownloadsCompleted += delegate(object sender, EventArgs e) { auto.Set(); }; repo.DownloadAndAdd(urls, myCbz); // hold on until test finished auto.WaitOne(); } // check sizes indicate added file var sizeAfter = (new FileInfo(myCbz)).Length; Assert.Greater(sizeAfter, sizeBefore); // clean up File.Delete(myCbz); // Create new: // download and add using (var repo = new Repository()) { // add a turnstile AutoResetEvent auto = new AutoResetEvent(false); // event handler allows program to progress (in case of cancel failure) repo.MultipleDownloadsCompleted += delegate(object sender, EventArgs e) { auto.Set(); }; repo.DownloadAndAdd(urls, myCbz); // hold on until test finished auto.WaitOne(); } // check file was made Assert.IsTrue(File.Exists(myCbz)); // check file size > 0 but less than before var sizeOne = (new FileInfo(myCbz)).Length; Assert.Greater(sizeOne, 0, "Fresh-made zip file has non-zero size"); Assert.Less(sizeOne, sizeBefore, "Zip file with only one entry smaller than with 100 entries"); // delete file again File.Delete(myCbz); }