internal PatchFile Parse_Manual_Entry() { try { string version; string name; string url; if (!(String.IsNullOrEmpty(manual_ver_box.Text))) { version = manual_ver_box.Text; } else { MessageBox.Show("You appear to have left something empty."); return(null); } if (!(String.IsNullOrEmpty(manual_url_box.Text))) { url = manual_url_box.Text; } else { MessageBox.Show("You appear to have left something empty."); return(null); } if (!(String.IsNullOrEmpty(manual_name_box.Text))) { name = manual_name_box.Text; } else { MessageBox.Show("You appear to have left something empty."); return(null); } int bytes = WebDirectory.ParseFileSizeViaHTTP(url); return(new PatchFile(url, name, bytes, version)); } catch (Exception e) { LogHandler.LogErrors(e.ToString()); UpdatePatchNotes(e.ToString()); return(null); } }
/// <summary> /// Downloads single file at specified address then removes it from the directory's index. /// </summary> /// <param name="directory">Directory whose index to affect.</param> /// <param name="address">Location of file.</param> async Task DownloadFile(WebDirectory directory, string address) { try { string path = address.Substring(MasterUrl.Length); if (path.Contains('/')) { string[] splitPath = path.Split('/'); int tempLength = 0; if (splitPath.Length == 1) { tempLength = splitPath[0].Length; } else { for (int i = 0; i < splitPath.Length - 1; i++) { tempLength += splitPath[i].Length; } } string folderName = path.Substring(0, tempLength + 1); QueryDirectory(folderName); } UserInterface.UpdatePatchNotes(string.Format("Downloading File ({0}): " + (address.Remove(address.IndexOf(MasterUrl), MasterUrl.Length)), filesDownloaded)); await webClient.DownloadFileTaskAsync(new Uri(address), path); directory.NameIndex.RemoveAt(0); directory.AddressIndex.RemoveAt(0); } catch (Exception e) { LogHandler.LogErrors(e.ToString(), this); if (e.InnerException != null) { LogHandler.LogErrors(e.InnerException.ToString(), this); } } }
/// <summary> /// Relays patch creation from Interface. /// </summary> internal void RelayPatchGeneration() { if (!(String.IsNullOrEmpty(PatchHelper.MasterURL))) { QueryLocalDirectory(); webDirectory = GenerateDirectory(PatchHelper.MasterURL); ConstructIndex(webDirectory); webDirectory.GenerateSizeIndex(); ComparisonHandler.CacheDirectories (localDirectory, webDirectory, this); ComparisonHandler.RelayPatchCreation(); } }
/// <summary> /// Uses PaseFolderIndex() to generate an array of url locations for files and subdirectories. /// </summary> /// <param name="directory">Directory to be affected.</param> void ConstructIndex(WebDirectory directory) { string[] index = ParseFolderIndex(directory.URL, directory); if (index != null) { for (int i = 0; i < index.Length; i++) { directory.AddressIndex.Add(directory.URL + index[i]); directory.NameIndex.Add(index[i]); UserInterface.UpdateProgressBar(); } } for (int i = 0; i < directory.SubDirectories.Count; i++) { UserInterface.UpdatePatchNotes ("Parsing Subdirectory: \n" + directory.SubDirectories[i].URL); ConstructIndex(directory.SubDirectories[i]); } }
/// <summary> /// HTTP Web request gathers data based on url parameter to build the web directory object. /// </summary> /// <param name="url">Initial Parse Location</param> /// <param name="directory">Directory object containing properties and methods for indexing and parsing contained folders.</param> /// <returns>Returns a string array containing child resource locations parsed from html (href);</returns> internal string[] ParseFolderIndex(string url, WebDirectory directory) { try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Timeout = 3 * 60 * 1000; request.KeepAlive = true; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { List <string> fileLocations = new List <string>(); string line; using (StreamReader reader = new StreamReader(response.GetResponseStream())) { while ((line = reader.ReadLine()) != null) { int index = line.IndexOf("<a href="); if (index >= 0) { string[] segments; string[] temp; segments = temp = line.Substring(index).Split('\"'); if (!segments[1].Contains("/")) { fileLocations.Add(segments[1]); UserInterface.UpdatePatchNotes("Web File Found: " + segments[1]); UserInterface.UpdateProgressBar(); } else { if (segments[1] != "../") { directory.SubDirectories.Add(new WebDirectory(url + segments[1], this)); UserInterface.UpdatePatchNotes("Web Directory Found: " + segments[1].Replace("/", string.Empty)); } } } else if (line.Contains("</pre")) { break; } } } response.Dispose(); /// After ((line = reader.ReadLine()) != null) return(fileLocations.ToArray <string>()); } else { return(new string[0]); /// !(HttpStatusCode.OK) } } catch (Exception e) { LogHandler.LogErrors(e.ToString(), this); return(null); } }