//Determine what the filepath of the issue should be public string GenerateFilename() { string libraryDir = Settings.Default.LibraryDir; string text = null; Query query = null; string str = CC.URLize(SeriesName); string text2 = CC.URLize(Name); string text3 = null; int num = 0; libraryDir += "\\"; libraryDir = libraryDir + PublisherName + "\\"; libraryDir = libraryDir + GroupName + "\\"; libraryDir = libraryDir + str + "\\"; libraryDir += str; if (SeriesType != 2) { query = CC.SQL.ExecQuery("SELECT DISTINCT series_vol FROM issues WHERE series_id=" + SeriesID); query.NextResult(); if (query.NextResult()) { libraryDir = libraryDir + " v" + SeriesVolume; } query.Close(); switch (Type) { case 0: libraryDir = libraryDir + " #" + Number.ToString("000"); break; case 1: libraryDir = libraryDir + " Annual " + Number; break; case 2: if (text2 != "") { libraryDir = libraryDir + " " + text2; } break; } if ((text2 != "") & (Type != 2)) { libraryDir = libraryDir + " (" + text2 + ")"; } } text3 = CC.GetArchiveType(FileName); text = libraryDir; if (FileName != libraryDir + text3) { while (File.Exists(text + text3)) { num++; text = libraryDir + " " + num; } return text + text3; } return FileName; }
public Exception Process() { FileStream fileStream = new FileStream(FileName, FileMode.Open); FileSize = (int)fileStream.Length; MD5 = CC.md5file(fileStream); fileStream.Close(); int num = -1; if (Settings.Default.FindDuplicates) { num = FindDuplicate(); } if (num == -1) { string archiveType; try { archiveType = CC.GetArchiveType(FileName); } catch (Exception result) { return result; } string text = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), "CarbonImport"); if (!Directory.Exists(text)) { Directory.CreateDirectory(text); } SaveChanges(); ArrayList arrayList = new ArrayList(); try { if (archiveType == ".cbr") { Unrar unrar = new Unrar(); unrar.ArchivePathName = FileName; unrar.Open(Unrar.OpenMode.List); while (unrar.ReadHeader()) { if (!unrar.CurrentFile.IsDirectory & CC.IsImageExt(unrar.CurrentFile.FileName)) { arrayList.Add(unrar.CurrentFile.FileName); } unrar.Skip(); } unrar.Close(); arrayList.Sort(); unrar.Open(Unrar.OpenMode.Extract); while (unrar.ReadHeader()) { if (unrar.CurrentFile.FileName == (string)arrayList[0]) { if (Settings.Default.ThumbGen) { text = Path.Combine(text, ID + Path.GetExtension(unrar.CurrentFile.FileName)); unrar.Extract(text); } break; } unrar.Skip(); } unrar.Close(); } else if (archiveType == ".cbz") { ZipFile zipFile = new ZipFile(FileName); foreach (ZipEntry item in zipFile) { if (item.IsFile & CC.IsImageExt(item.Name) && item.Name.Substring(0, 1) != "." && !item.Name.Contains("/") && !item.Name.Contains("/.")) { arrayList.Add(item.Name); } } zipFile.Close(); arrayList.Sort(); if (Settings.Default.ThumbGen) { text = Path.Combine(text, ID + Path.GetExtension((string)arrayList[0])); CC.unzip(FileName, (string)arrayList[0], text); } } if ((Path.GetExtension(text).ToLower() == ".png") | (Path.GetExtension(text).ToLower() == ".gif")) { text = CC.ConvertJPG(text); } Pages = arrayList.Count; SaveChanges(); } catch (Exception result2) { return result2; } if (Settings.Default.OrganizeMethod != 0) { OrganizeFile(); } if ((archiveType != ".pdf") & Settings.Default.ThumbGen) { try { String dst = Path.Combine(Application.StartupPath, Settings.Default.CoverDir) + "\\" + ID + ".jpg"; CC.CreateThumbnail(text, dst); File.Delete(text); } catch (Exception result3) { return result3; } } } return null; }