public void StartDownload(JsonDownloadInfo download) { DebugHandler.TraceMessage("StartDownload Called.", DebugSource.TASK, DebugType.ENTRY_EXIT); DebugHandler.TraceMessage(download.ToString(), DebugSource.TASK, DebugType.PARAMETERS); try { string xdccMessage = "/msg " + download.bot + " xdcc send #" + download.pack; IrcClient.SetCustomDownloadDir(Path.Combine(IrcSettings.fullfilepath, download.fullfilepath)); SendMessage(xdccMessage); } catch (Exception e) { DebugHandler.TraceMessage(e.ToString(), DebugSource.TASK, DebugType.WARNING); } }
public void AddFileToFileHistory(JsonDownloadInfo downloadInfo) { DebugHandler.TraceMessage("AddFileToFileHistory Called", DebugSource.TASK, DebugType.ENTRY_EXIT); DebugHandler.TraceMessage(downloadInfo.ToString(), DebugSource.TASK, DebugType.PARAMETERS); if (!File.Exists(Path.Combine(fileHistoryPath, fileName))) { JsonDownloadHistory downloadHistoryObj = new JsonDownloadHistory() { animeInfo = downloadInfo.animeInfo }; downloadHistoryObj.downloadHistory.Add(downloadInfo); JsonDownloadHistoryList list = new JsonDownloadHistoryList(); if (!list.downloadHistorylist.Contains(downloadHistoryObj)) { list.downloadHistorylist.Add(downloadHistoryObj); using (var fileStream = File.Open(Path.Combine(fileHistoryPath, fileName), FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite)) { using (var streamWriter = new StreamWriter(fileStream)) { streamWriter.Write(list.ToJson()); } } } } else { JsonDownloadHistoryList list = GetCurrentFileHistory(); bool animeAlreadyExists = false; bool fileAlreadyExists = false; int listIndex = 0; foreach (JsonDownloadHistory downloadHistoryObject in list.downloadHistorylist) { if (downloadHistoryObject.animeInfo.anime_id == downloadInfo.animeInfo.anime_id) { animeAlreadyExists = true; int downloadIndex = 0; foreach (JsonDownloadInfo info in downloadHistoryObject.downloadHistory) { if (info.id == downloadInfo.id || info.filename == downloadInfo.filename || (info.pack == downloadInfo.pack && info.bot == downloadInfo.bot)) { list.downloadHistorylist[listIndex].downloadHistory[downloadIndex] = downloadInfo; fileAlreadyExists = true; break; } downloadIndex++; } if (!fileAlreadyExists) { list.downloadHistorylist[listIndex].downloadHistory.Add(downloadInfo); } break; } listIndex++; } if (!fileAlreadyExists && !animeAlreadyExists) { JsonDownloadHistory downloadHistoryObj = new JsonDownloadHistory() { animeInfo = downloadInfo.animeInfo }; downloadHistoryObj.downloadHistory.Add(downloadInfo); list.downloadHistorylist.Add(downloadHistoryObj); } using (var fileStream = File.Open(Path.Combine(fileHistoryPath, fileName), FileMode.Truncate, FileAccess.ReadWrite, FileShare.ReadWrite)) { using (var streamWriter = new StreamWriter(fileStream)) { streamWriter.Write(list.ToJson()); } } } }
public string AddDownload(JsonDownloadInfo download) { DebugHandler.TraceMessage("AddDownload Called.", DebugSource.TASK, DebugType.ENTRY_EXIT); DebugHandler.TraceMessage(download.ToString(), DebugSource.TASK, DebugType.PARAMETERS); try { if (download.filesize.Contains(".")) { download.filesize = ((int)(double.Parse(download.filesize, System.Globalization.CultureInfo.InvariantCulture) * 1024)).ToString(); } if (UtilityMethods.GetFreeSpace(IrcSettings.fullfilepath) > (int.Parse(download.filesize) * 1024 * 1024)) { download.downloadIndex = DownloadQueue.Count - 1; if (!DownloadQueue.Contains(download) || CurrentlyDownloading != download) { DownloadQueue.Add(download); DebugHandler.TraceMessage("Added download to queue: " + download.ToString(), DebugSource.TASK, DebugType.INFO); JsonSuccess succes = new JsonSuccess() { message = "Succesfully added download to download queue." }; return(succes.ToJson()); } else { DebugHandler.TraceMessage("Could not add download: " + download.ToString() + ", already exist in queue or is already being downloaded ", DebugSource.TASK, DebugType.WARNING); JsonError error = new JsonError() { type = "file_already_being_downloaded_error", errormessage = "Could not add download: " + download.ToString() + ", already exist in queue or is already being downloaded ", errortype = "warning", exception = "none" }; return(error.ToJson()); } } else { DebugHandler.TraceMessage("Could not add download with filesize: " + download.filesize + " due to insufficient space required: " + (UtilityMethods.GetFreeSpace(IrcSettings.fullfilepath) / 1024 / 1024).ToString(), DebugSource.TASK, DebugType.WARNING); JsonError error = new JsonError() { type = "unsufficient_space_error", errormessage = "Could not add download with filesize: " + download.filesize + " due to insufficient space required: " + (UtilityMethods.GetFreeSpace(IrcSettings.fullfilepath) / 1024 / 1024).ToString(), errortype = "warning" }; return(error.ToJson()); } } catch (Exception e) { DebugHandler.TraceMessage("Could not add download with filesize: " + e.ToString(), DebugSource.TASK, DebugType.ERROR); JsonError error = new JsonError() { type = "add_download_error", errormessage = "Could not add download to queue.", errortype = "exception", exception = e.ToString() }; return(error.ToJson()); } }