private void Check() { Log.Add("Receiving server stat...", LogType.Info); if (!HHClient.Request(Settings.ServerStat)) { return; } Log.Add("Receiving client settings...", LogType.Info); if (!HHClient.Request(Settings.ClientLogin)) { return; } ServerStart(); if (!HHClient.Request(Settings.ClientStart, "", true)) { return; } else { Log.Add("Client started.", LogType.Info, true); } HathDownloader.Start(); KeepAlive.Elapsed += new System.Timers.ElapsedEventHandler(KeepAlive_Elapsed); KeepAlive.Interval = 1000; KeepAlive.Start(); }
private void HathFileOpener_FileOk(object sender, System.ComponentModel.CancelEventArgs e) { foreach (string name in HathFileOpener.FileNames) { HathDownloader.Add(new HathParser(File.ReadAllText(@name)).Parse()); if (Settings.DeleteHathDl) { File.Delete(name); } } }
private void Check() { if (Cmd.States.Dev) { ServerStart(); } else { UpdateStats.Elapsed += new System.Timers.ElapsedEventHandler(UpdateStats_Elapsed); UpdateStats.Interval = 1000; UpdateStats.Start(); Log.Add("Receiving server stat...", LogType.Info); if (!HHClient.Request(Settings.ServerStat)) { return; } Log.Add("Receiving client settings...", LogType.Info); if (!HHClient.Request(Settings.ClientLogin)) { return; } barControl1.Set(Settings.MaxSpeed); ServerStart(); if (!HHClient.Request(Settings.ClientStart, "", true)) { return; } else { Log.Add("Client started.", LogType.Info, true); } /* * if (!new RemoveFiles(Client.(LoginInfo)).Do()) * { * Log.Add("Cannot receive info!", LogType.CriticalError, true); * return; * } */ HathDownloader.Start(); KeepAlive.Elapsed += new System.Timers.ElapsedEventHandler(KeepAlive_Elapsed); KeepAlive.Interval = 1000; KeepAlive.Start(); } }
public static bool Download(HathUri Uri, CopyInfo CInfo = null) { SHA1Managed Hasher = new SHA1Managed(); string hash = BitConverter.ToString(Hasher.ComputeHash(Encoding.ASCII.GetBytes(Uri.FileName))).Replace("-", "").ToLower(); string fileDir = string.Format("{0}{1}/{2}/", Settings.Cache, hash.Substring(0, 1), hash.Substring(1, 1)); try { Directory.CreateDirectory(Path.GetDirectoryName(fileDir + Uri.FileName)); using (WebClient client = new WebClient()) { using (Stream streamRemote = client.OpenRead(new Uri(Uri.Url))) { int contentSize = 0; byte[] byteBuffer; int rec = 0; int iByteSize = 0; if (client.ResponseHeaders.Get("Content-Length") == "1009,1009" || client.ResponseHeaders.Get("Content-Length") == "28658,28658") { contentSize = 1009; } else { try { contentSize = int.Parse(client.ResponseHeaders.Get("Content-Length")); } catch { Log.Add("Server sent corrupt Content-Length header... " + client.BaseAddress, LogType.Warning, true); return(false); } } if (contentSize >= 0 && (contentSize != 28658 && contentSize != 1009)) { byteBuffer = new byte[contentSize]; } else { if (contentSize == 28658 || contentSize == 1009) { if (HHClient.Request(Settings.MoreFiles, "", true)) { Log.Add("Requested more files.", LogType.Info, true); if (Download(Uri)) { return(true); } } } return(false); } try { while ((iByteSize = streamRemote.Read(byteBuffer, rec, byteBuffer.Length - rec)) > 0) { rec += iByteSize; MainStats.TriggerByteDownload(iByteSize); } } catch { return(false); } using (Stream streamLocal = new FileStream(fileDir + Uri.FileName, FileMode.Create, FileAccess.ReadWrite, FileShare.Write)) { streamLocal.Write(byteBuffer, 0, byteBuffer.Length); streamLocal.Close(); } streamRemote.Close(); if (CInfo != null) { File.Copy(fileDir + Uri.FileName, CInfo.Location + CInfo.FileName); } if (Settings.CopyDlToGalleries) { HathDownloader.CopyIsMissing(fileDir + Uri.FileName, Uri.FileName); } SqlManager.InsertFile(new FileData(Uri.FileName, contentSize)); MainStats.TriggerFileDownload(Uri.FileName, contentSize); if (Uri.UriType == HathUriType.Proxy || Uri.UriType == HathUriType.HathDl) { PendingRegister.AddFile(Uri.FileName); } } } return(true); } catch { return(false); } }
public static bool Request(string param, string add = "", bool FirstLineOnly = false) { string hash = ""; if (param != Settings.ServerStat) { string toHash = String.Format("hentai@home-{0}-{1}-{2}-{3}-{4}", param, add, Settings.UserID, Stat.CorrectedTime, Settings.UserKey); SHA1Managed Hasher = new SHA1Managed(); hash = BitConverter.ToString(Hasher.ComputeHash(Encoding.ASCII.GetBytes(toHash))).Replace("-", "").ToLower(); } NameValueCollection Items = new NameValueCollection(); Items.Add("clientbuild", Settings.ClientBuild); Items.Add("act", param); if (param != Settings.ServerStat) { Items.Add("add", add); Items.Add("cid", Settings.UserID); Items.Add("acttime", Stat.Option("server_time")); Items.Add("actkey", hash); } string Response = new Http() { Url = Settings.ApiAddress, Method = HttpMethod.Get, PostItems = Items }.Send(); if (string.IsNullOrEmpty(Response)) // check if returned string is empty... { return(false); } //Log.Add(Response, LogType.Debug, false); ResponseData TempResponse = ParseResponse(Response, FirstLineOnly); LastResponse = TempResponse; RawResponse = Response; if (TempResponse.Head == "OK") { if (param == Settings.DownloadList) { HathDownloader.Tokens(RawResponse); } else if (param == Settings.ServerStat) { Stat = TempResponse; } else if (param == Settings.ClientLogin) { SettingsResponse = TempResponse; Settings.Port = Convert.ToInt32(TempResponse.Option("port")); Settings.RequestServer = TempResponse.Option("request_server"); Settings.MaxSpeed = Convert.ToInt32(TempResponse.Option("throttle_bytes")); Settings.AuthorizedHosts = TempResponse.Option("rpc_server_ip").Replace("::ffff:", "").Split(';'); MainStats.MaximumSize = Convert.ToInt64(TempResponse.Option("disklimit_bytes")); } return(true); } else { if (TempResponse.Head == "KEY_EXPIRED") { Request(Settings.ServerStat, ""); return(Request(param, "", FirstLineOnly)); } if (TempResponse.Head == "CLIENT_NOT_QUALIFIED") { return(false); } else { Log.Add("- - -\n" + TempResponse.Head + "\n- - -", LogType.Warning, false); } } return(false); }