示例#1
0
        private void StopClient()
        {
            try
            {
                if (!IsStopping)
                {
                    IsStopping = true;
                }
                else
                {
                    return;
                }

                HttpServer.Stop = true;

                if (!HHClient.Request(Settings.ClientStop, "", true))
                {
                    Log.Add("Failed to stop client!", LogType.CriticalError, true);
                }

                for (int i = 12000; i >= 0; i--)
                {
                    this.BeginInvoke(new MethodInvoker(delegate
                    {
                        this.Text = string.Format("Closing in... {0}", i / 100.0);
                    }));
                    Thread.Sleep(10);
                }
            }
            catch { }

            Process.GetCurrentProcess().Kill();
        }
示例#2
0
        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();
        }
示例#3
0
        private static void Worker()
        {
            if (Quoque.Count == 0)
            {
                return;
            }

            Dictionary <string, string> TmpList = new Dictionary <string, string> {
            };

            foreach (HathFileInfo Item in Quoque)
            {
                foreach (HathFile fl in Item.FileList)
                {
                    if (fl.Token == null && !TmpList.ContainsKey(fl.FileName))
                    {
                        TmpList.Add(fl.FileName, "");
                    }

                    if (TmpList.Count >= 20)
                    {
                        break;
                    }
                }
            }

            StringBuilder sb = new StringBuilder();

            foreach (KeyValuePair <string, string> kvp in TmpList)
            {
                sb.AppendFormat("{0};", kvp.Key);
            }

            if (!HHClient.Request(Settings.DownloadList, sb.ToString(), true))
            {
                Log.Add("Client not yet qualified to perform Hath Downloads...", LogType.Info, true);
                return;
            }
            else
            {
                Thread.Sleep(2500);
            }

            Log.Add("Started processing HathDl quoque...", LogType.Info, true);
            try
            {
                foreach (HathFile File in FilesWithTokens)
                {
                    Cache.Download(new HathUri(new string[] { Settings.RequestServer, File.FileName, File.Token, File.Token.Split('-')[0], File.FileID.ToString(), File.FileNameOriginal }, HathUriType.HathDl), new CopyInfo(Settings.Downloads + File.GalleryName + "/", File.FileNameOriginal));
                }
            }
            catch { }
            FilesWithTokens = new List <HathFile> {
            };

            Log.Add("Finished processing HathDl quoque.", LogType.Info, true);
        }
示例#4
0
        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();
            }
        }
示例#5
0
        private static void ChechUpdate()
        {
            if (Files.Count < 50 || (Files.Count % 10) == 1)
            {
                return;
            }

            string add = string.Join(";", Files.ToArray());

            if (HHClient.Request(Settings.FileRegister, add, true))
            {
                Log.Add("Notified server about new files.", LogType.Info, true);
            }

            Files = new List <string> {
            };
        }
示例#6
0
        private void KeepAlive_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            KeepAliveTick++;
            if (KeepAliveTick <= 300)
            {
                MainStats.TriggerKeepAlive(KeepAliveTick);
                return;
            }

            KeepAliveTick = 0;

            if (HHClient.Request(Settings.StillAlive, "", true))
            {
                Log.Add("Keep alive: OK", LogType.Info, true);
            }
            else
            {
                Log.Add("Keep alive: FAIL", LogType.Info, true);
            }
        }
示例#7
0
        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);
            }
        }