public static int DownloadBinaryInit(string xml, out string xmlresponse) { return(Web.XMLFUSRequest("https://neofussvr.sslcs.cdngc.net/NF_DownloadBinaryInitForMass.do", xml, out xmlresponse)); }
public static int DownloadBinary( string path, string file, string saveTo, string size, bool GUI = true) { long num = 0; HttpWebRequest wr = KiesRequest.Create("http://cloud-neofussvr.sslcs.cdngc.net/NF_DownloadBinaryForMass.do?file=" + path + file); wr.Method = "GET"; wr.Headers["Authorization"] = Imports.GetAuthorization(Web.Nonce).Replace("Authorization: ", "").Replace("nonce=\"", "nonce=\"" + Web.Nonce); wr.Timeout = 25000; wr.ReadWriteTimeout = 25000; if (System.IO.File.Exists(saveTo)) { long length = new FileInfo(saveTo).Length; if (long.Parse(size) == length) { Logger.WriteLog("File already downloaded.", false); return(200); } Logger.WriteLog("File exists. Resuming download...", false); wr.AddRange((int)length); num = length; } using (HttpWebResponse responseFus = (HttpWebResponse)wr.GetResponseFUS()) { if (responseFus == null) { Logger.WriteLog("Error downloading: response is null", false); return(901); } if (responseFus.StatusCode != HttpStatusCode.OK && responseFus.StatusCode != HttpStatusCode.PartialContent) { Logger.WriteLog("Error downloading: " + (object)(int)responseFus.StatusCode, false); } else { long total = long.Parse(responseFus.GetResponseHeader("content-length")) + num; if (!System.IO.File.Exists(saveTo) || new FileInfo(saveTo).Length != total) { byte[] buffer = new byte[8192]; Stopwatch sw = new Stopwatch(); Utility.ResetSpeed(num); try { Utility.PreventDeepSleep(Utility.PDSMode.Start); using (BinaryWriter binaryWriter = new BinaryWriter((Stream) new FileStream(saveTo, FileMode.Append))) { int count; do { Utility.PreventDeepSleep(Utility.PDSMode.Continue); if (GUI) { if (Web.form.PauseDownload) { break; } } num += (long)(count = responseFus.GetResponseStream().Read(buffer, 0, buffer.Length)); if (count > 0) { binaryWriter.Write(buffer, 0, count); if (GUI) { int dlspeed = Utility.DownloadSpeed(num, sw); if (dlspeed != -1) { Web.form.lbl_speed.Invoke((Delegate)((Action)(() => Web.form.lbl_speed.Text = dlspeed.ToString() + "kB/s"))); } } } if (GUI) { Web.form.SetProgressBar(Utility.GetProgress(num, total)); } else { CmdLine.SetProgress(Utility.GetProgress(num, total)); } }while (count > 0); } } catch (IOException ex) { Logger.WriteLog("Error: Can't access output file " + saveTo, false); if (GUI) { Web.form.PauseDownload = true; } Logger.WriteLog(ex.ToString(), false); return(-1); } catch (WebException ex) { Logger.WriteLog("Error: Connection interrupted", false); Web.SetReconnect(); } finally { Utility.PreventDeepSleep(Utility.PDSMode.Stop); if (GUI) { Web.form.lbl_speed.Invoke((Delegate)((Action)(() => Web.form.lbl_speed.Text = "0kB/s"))); } } } } return((int)responseFus.StatusCode); } }
public static Firmware UpdateCheck(string model, string region, string pda, string csc, string phone, string data, bool BinaryNature, bool AutoFetch = false) { string str; Firmware firmware = new Firmware(); Logger.WriteLog("Checking firmware for " + model + "/" + region + "/" + pda + "/" + csc + "/" + phone + "/" + data, false); int htmlstatus = Web.GenerateNonce(); if (htmlstatus != 200) { Logger.WriteLog("Error: Could not generate Nonce. Status code " + htmlstatus, false); firmware.ConnectionError = true; return(firmware); } htmlstatus = Web.DownloadBinaryInform(Xml.GetXmlBinaryInform(model, region, pda, csc, phone, data, BinaryNature), out str); if ((htmlstatus != 200) || (Utility.GetXMLStatusCode(str) != 200)) { Logger.WriteLog(string.Concat(new object[] { "Error: Could not send BinaryInform. Status code ", htmlstatus, "/", Utility.GetXMLStatusCode(str) }), false); Utility.CheckHTMLXMLStatus(htmlstatus, Utility.GetXMLStatusCode(str)); return(firmware); } firmware.Version = Xml.GetXMLValue(str, "FUSBody/Results/LATEST_FW_VERSION/Data", null, null); firmware.Model = Xml.GetXMLValue(str, "FUSBody/Put/DEVICE_MODEL_NAME/Data", null, null); firmware.DisplayName = Xml.GetXMLValue(str, "FUSBody/Put/DEVICE_MODEL_DISPLAYNAME/Data", null, null); firmware.OS = Xml.GetXMLValue(str, "FUSBody/Put/LATEST_OS_VERSION/Data", null, null); firmware.LastModified = Xml.GetXMLValue(str, "FUSBody/Put/LAST_MODIFIED/Data", null, null); firmware.Filename = Xml.GetXMLValue(str, "FUSBody/Put/BINARY_NAME/Data", null, null); firmware.Size = Xml.GetXMLValue(str, "FUSBody/Put/BINARY_BYTE_SIZE/Data", null, null); string str3 = Xml.GetXMLValue(str, "FUSBody/Put/BINARY_CRC/Data", null, null); if (!string.IsNullOrEmpty(str3)) { firmware.CRC = BitConverter.GetBytes(Convert.ToUInt32(str3)).Reverse <byte>().ToArray <byte>(); } firmware.Model_Type = Xml.GetXMLValue(str, "FUSBody/Put/DEVICE_MODEL_TYPE/Data", null, null); firmware.Path = Xml.GetXMLValue(str, "FUSBody/Put/MODEL_PATH/Data", null, null); firmware.Region = Xml.GetXMLValue(str, "FUSBody/Put/DEVICE_LOCAL_CODE/Data", null, null); firmware.BinaryNature = int.Parse(Xml.GetXMLValue(str, "FUSBody/Put/BINARY_NATURE/Data", null, null)); if (Xml.GetXMLValue(str, "FUSBody/Put/LOGIC_OPTION_FACTORY/Data", null, null) == "1") { firmware.LogicValueFactory = Xml.GetXMLValue(str, "FUSBody/Put/LOGIC_VALUE_FACTORY/Data", null, null); } if (Xml.GetXMLValue(str, "FUSBody/Put/LOGIC_OPTION_HOME/Data", null, null) == "1") { firmware.LogicValueHome = Xml.GetXMLValue(str, "FUSBody/Put/LOGIC_VALUE_HOME/Data", null, null); } if (!AutoFetch) { if ((pda + "/" + csc + "/" + phone + "/" + pda) == firmware.Version) { Logger.WriteLog("\nCurrent firmware is latest:", false); } else { Logger.WriteLog("\nNewer firmware available:", false); } } Logger.WriteLog("Model: " + firmware.Model, false); Logger.WriteLog("Version: " + firmware.Version, false); Logger.WriteLog("OS: " + firmware.OS, false); Logger.WriteLog("Filename: " + firmware.Filename, false); Logger.WriteLog("Size: " + firmware.Size + " bytes", false); if ((firmware.BinaryNature == 1) && !string.IsNullOrEmpty(firmware.LogicValueFactory)) { Logger.WriteLog("LogicValue: " + firmware.LogicValueFactory, false); } else if (!string.IsNullOrEmpty(firmware.LogicValueHome)) { Logger.WriteLog("LogicValue: " + firmware.LogicValueHome, false); } Logger.WriteLog("\n", false); return(firmware); }