public static DbFile UploadSingleFile(FileInfo fi, Crypto.EncryptionMode encryptionMode) { DbFile dbf = null; try { dbf = new DbFile(); dbf.Id = fi.FullName; dbf.DateLastWriteTime = fi.LastWriteTimeUtc; dbf.Name = fi.Name; dbf.Tag = null; dbf.Category = null; dbf.EncryptionMode = encryptionMode; dbf.Size = fi.Length; dbf.Checksum = Checksum.Calculate(fi); if (UploadProcess(dbf) == false) { Logger.Warn(LOGNAME, "File has not been uploaded"); } else { Logger.Info(LOGNAME, "Link: " + dbf.DownloadLink); } } catch (Exception ex) { Logger.Error(LOGNAME, ex.Message, ex); } return(dbf); }
private static void ModeUpload(string filepath, Crypto.EncryptionMode encryptionMode, string savepath) { try { DbFile dbf = FileUploader.UploadSingleFile(new FileInfo(filepath), encryptionMode); string nzblPath = filepath + Utilities.EXT_NZBL; if (string.IsNullOrEmpty(savepath) == false) { if (Directory.Exists(savepath)) { nzblPath = Path.Combine(savepath, new FileInfo(filepath).Name + Utilities.EXT_NZBL); } else { nzblPath = savepath; } } if (dbf != null) { File.WriteAllBytes(nzblPath, Utilities.HexToBytes(dbf.DownloadLink)); } } catch (Exception ex) { Logger.Error(LOGNAME, ex.Message, ex); } }
//Constructor for upload public UsenetChunk(BinaryReader br, string filename, Guid fileId, string chunkExt, int chunkNumber, int totalChunks, Crypto.EncryptionMode encryptionMode) { Br = br; Filename = filename; FileId = fileId; ChunkExt = chunkExt; ChunkNumber = chunkNumber; TotalChunks = totalChunks; EncryptionMode = encryptionMode; }
//Constructor for download public UsenetChunk(BinaryWriter bw, string filename, Guid fileId, string chunkExt, int chunkNumber, byte passNumber, int totalChunks, Crypto.EncryptionMode encryptionMode) { Bw = bw; Filename = filename; FileId = fileId; ChunkExt = chunkExt; ChunkNumber = chunkNumber; TotalChunks = totalChunks; PassNumber = passNumber; EncryptionMode = encryptionMode; }
public Dictionary <string, DownloadLinkFileInfo> DicoOfPassNumberPerExtension; //key: fileExtension - value: DownloadLinkFileInfo #endregion public DownloadLink(byte version, Guid id, string name, string checksum, uint postDate, Crypto.EncryptionMode encryptionMode, Dictionary <string, DownloadLinkFileInfo> dicoOfPassNumberPerExtension) { try { Version = version; Id = id; Name = name; Checksum = checksum; PostDate = postDate; EncryptionMode = encryptionMode; DicoOfPassNumberPerExtension = dicoOfPassNumberPerExtension; } catch (Exception ex) { Logger.Error(LOGNAME, ex.Message, ex); } }
private static void Menu() { bool loop = true; string dlLink = null; string outputDir = null; while (loop) { Console.WriteLine(SEP); Console.WriteLine("Available options: "); Console.WriteLine("[1] Backup"); Console.WriteLine("[2] Restore"); Console.WriteLine("[3] Upload single file"); Console.WriteLine("[4] Download single file"); Console.WriteLine("[5] Sync files to NzbLite.com"); Console.WriteLine("[6] Convert Link to Nzb"); Console.WriteLine("[7] Clean local datatabase"); Console.WriteLine("Choose an option: "); string input = Console.ReadLine(); Console.WriteLine(SEP); switch (input) { case "1": ModeBackup(); loop = false; break; case "2": if (Settings.Settings.Current.Folders == null) { Logger.Error(LOGNAME, "You have to define at least 1 SettingFolder", null); return; } Console.WriteLine("List of available folders to restore: "); for (int i = 0; i < Settings.Settings.Current.Folders.Count; i++) { Console.WriteLine((i + 1) + " " + Settings.Settings.Current.Folders[i].Path); } Console.WriteLine("Select a folder to restore: "); string v = Console.ReadLine(); int n = -1; if (Int32.TryParse(v, out n) == false || n > Settings.Settings.Current.Folders.Count) { Logger.Error(LOGNAME, "Invalid input", null); return; } SettingFolder sf = Settings.Settings.Current.Folders[n - 1]; ModeRestore(sf); loop = false; break; case "3": Console.WriteLine("Enter filepath to upload:"); string filepath = Console.ReadLine(); Console.WriteLine("Encrypt file with XOR (y/n):"); string encrypted = Console.ReadLine(); if (string.IsNullOrEmpty(filepath) || File.Exists(filepath) == false) { Console.WriteLine("File not found !"); continue; } Crypto.EncryptionMode encryptionMode = Crypto.EncryptionMode.NONE; if (encrypted != null && encrypted.ToLower() == "y") { encryptionMode = Crypto.EncryptionMode.XOR; } Console.WriteLine("Enter .nzbl save path:"); string savepath = Console.ReadLine(); ModeUpload(filepath, encryptionMode, savepath); break; case "4": Console.WriteLine("Enter Link:"); dlLink = Console.ReadLine(); Console.WriteLine("Enter outputDir (" + Utilities.FolderDownload + "):"); outputDir = Console.ReadLine(); if (string.IsNullOrEmpty(outputDir)) { outputDir = Utilities.FolderDownload; } ModeDownload(dlLink, outputDir); break; case "5": ModeSync(); break; case "6": Console.WriteLine("Enter Link:"); dlLink = Console.ReadLine(); Console.WriteLine("Enter outputDir (" + Utilities.FolderDownload + "):"); outputDir = Console.ReadLine(); if (string.IsNullOrEmpty(outputDir)) { outputDir = Utilities.FolderDownload; } ModeConvert(dlLink, outputDir); break; case "7": if (Db.Load(null, false) == false) { Logger.Error(LOGNAME, "An error occurred while loading database", null); return; } if (Db.Clean() == false) { Logger.Error(LOGNAME, "An error occurred while cleaning database", null); return; } Console.WriteLine("Database successfully cleaned"); break; } } }