public static void SendTorrent(string datatable, int index) { string path = null; string save = null; DataRow dr = null; switch (datatable) { case "others": try { dr = TorrentDataHandler.data.OthersTable.Rows.Find(index); } catch { return; } break; case "movies": try { dr = TorrentDataHandler.data.MoviesTable.Rows.Find(index); } catch { return; } break; case "music": try { dr = TorrentDataHandler.data.TorrentsTable.Rows.Find(index); } catch { return; } break; default: return; } try { if (dr != null) dr.BeginEdit(); else return; path = (dr["File Path"].Equals(DBNull.Value)) ? null : (string)dr["File Path"]; save = (dr["Save Structure"].Equals(DBNull.Value)) ? null : (string)dr["Save Structure"]; //Preliminary error checking if (path == null || !DirectoryHandler.GetFileExists(path)) { dr.SetColumnError(TorrentDataHandler.data.TorrentsTable.Columns["File Path"], "File does not exist"); dr.EndEdit(); return; } if (save == null || save == "") { dr.SetColumnError(TorrentDataHandler.data.TorrentsTable.Columns["Save Structure"], "Empty save structure"); dr.EndEdit(); return; } if (!DirectoryHandler.GetFileExists(SettingsHandler.GetTorrentClientFolder() + "\\uTorrent.exe")) { ErrorWindow ew = new ErrorWindow(); ew.IssueGeneralWarning("Be sure uTorrent folder is correct", "uTorrent.exe does not exist", null); dr.EndEdit(); return; } if ((bool)dr["Sent"]) { dr.EndEdit(); return; } } catch (Exception e) { if (dr != null) dr.RowError = ("General exception: " + e.Message); dr.EndEdit(); return; } try { Process sendTorrentProcess = new Process(); //torrentClient.exe /directory "C:\Save Path" "D:\Some folder\your.torrent" string fullArgument = "/directory " + "\"" + save + "\" " + "\"" + path + "\""; sendTorrentProcess.StartInfo.WorkingDirectory = SettingsHandler.GetTorrentClientFolder(); sendTorrentProcess.StartInfo.Arguments = fullArgument; sendTorrentProcess.StartInfo.FileName = SettingsHandler.GetTorrentClient(); sendTorrentProcess.Start(); sendTorrentProcess.Dispose(); sendTorrentProcess.Close(); dr["Sent"] = true; if (dr.HasErrors) dr.ClearErrors(); dr.EndEdit(); } catch (Exception e) { if (dr != null) dr.RowError = ("General exception: " + e.Message); dr.EndEdit(); return; } }
public static string GetHTMLLookUp(string value) { StreamReader sr = null; string[] ab = new string[2]; string a; string b; int c = 0; string[] lines = null; string replace; if (value == null) return value; try { sr = new StreamReader(System.Windows.Forms.Application.StartupPath + @"\HTML-Look-Up.txt"); while (!sr.EndOfStream) { ab = sr.ReadLine().Split(' '); a = ab[0]; b = ab[1]; if (value.Contains(a) || value.Contains(b)) { while (value.Contains(a)) { replace = sr.ReadLine(); value = value.Replace(a, replace); } while (value.Contains(b)) { replace = sr.ReadLine(); value = value.Replace(b, replace); } } else { sr.ReadLine(); } } } catch (FileNotFoundException) { ErrorWindow ew = new ErrorWindow(); ew.IssueGeneralWarning("HTML replacing will not occur", "Could not find HTML-Look-Up.txt...", null); } catch (Exception e) { ErrorWindow ew = new ErrorWindow(); ew.IssueGeneralWarning("Error..", lines[c], e.Message); } finally { if (sr != null) sr.Dispose(); } return value; }
//To be called only from DoWork public List<FileInfo> UnzipFiles(string[] zipFiles) { List<FileInfo> items = new List<FileInfo>(); List<FileInfo> fileinfos = new List<FileInfo>(); foreach (string zipfile in zipFiles) { try { fileinfos.Add(new FileInfo(zipfile)); } catch (Exception e) { LogError(e.Message + "\n" + e.StackTrace); } } FastZip fz = new FastZip(); ErrorWindow ew = new ErrorWindow(); string[] files = null; string filename; DirectoryInfo destination; int total = zipFiles.Length; double progress = 0; double count = 0; foreach (FileInfo zipfile in fileinfos) { filename = zipfile.Name; filename = filename.Replace(zipfile.Extension, ""); string dest = SettingsHandler.GetTorrentSaveFolder() + @"\[CSL]--Temp\" + filename + @"\"; destination = new DirectoryInfo(dest); if (!destination.Exists) { try { destination.Create(); } catch (Exception e) { LogError(e.Message + "\n" + e.StackTrace); } } try { fz.ExtractZip(zipfile.FullName, destination.FullName, ".torrent"); } catch (Exception) { ew.IssueGeneralWarning("No action necessary", "Warning: Could not unzip " + filename, zipfile.Name); } try { files = Directory.GetFiles(destination.FullName, "*.torrent", SearchOption.AllDirectories); } catch (DirectoryNotFoundException) { ew.IssueGeneralWarning("No action necessary", "Warning: " + filename + "was empty", zipfile.Name); } finally { foreach (string file in files) { try { items.Add(new FileInfo(file)); } catch (Exception e) { LogError(e.Message + "\n" + e.StackTrace); } } } try { zipfile.MoveTo(SettingsHandler.GetTorrentSaveFolder() + @"\[CSL] -- Processed Zips\" + zipfile.Name); } catch { } progress = (++count / total) * 100; if (progress <= 100 && progress >= 0) ReportProgress((int)progress); } return items; }
private void createDirectoriesToolStripMenuItem_Click(object sender, EventArgs e) { ErrorWindow ew = new ErrorWindow(); bool response = ew.IssueCreateEmptyDirectoriesWarning("Click OK to proceed", "This option will create the save structure\n directories of the current torrents"); if (response) { try { List<String> save_structures = new List<string>(); foreach (DataGridViewRow r in dgvh.dv.Rows) { try { save_structures.Add((string)r.Cells["Save Structure"].Value); } catch { } } DirectoryHandler.CreateEmptyDirectories(save_structures); } catch { } } }