Ejemplo n.º 1
0
 public void ClearHistory()
 {
     if (new DialogMessage(_view.TryFindResource("StrClearHistory") as String, String.Empty, DialogMessage.Buttons.YesNo)
     {
         Owner = _view
     }.ShowDialog() == true)
     {
         HistoryReocrds.Clear();
     }
 }
Ejemplo n.º 2
0
        public void SelectFile(ObjectRequest objectRequest)
        {
            using (System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog())
            {
                if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    String filePath   = openFileDialog.FileName;
                    String fileName   = Path.GetFileName(filePath);
                    String fileParent = Path.GetDirectoryName(filePath);
                    String pattern    = Regex.Replace(fileName, "_[0-1]?[0-9].pkg", "_[0-1]?[0-9].pkg");

                    if (!objectRequest.PsnName.ToUpper().Equals(fileName.ToUpper()))
                    {
                        if (new DialogMessage(_view.TryFindResource("StrOpenInconsistent") as String, String.Empty, DialogMessage.Buttons.YesNo)
                        {
                            Owner = _view
                        }.ShowDialog() == true)
                        {
                            HistoryReocrds.Add(objectRequest.PsnPath, filePath);
                            objectRequest.LocalPath = filePath;
                        }
                        else
                        {
                            return;
                        }
                    }
                    else if (Regex.IsMatch(filePath, "_[0-1]?[0-9].pkg", RegexOptions.IgnoreCase) && new DialogMessage(_view.TryFindResource("StrOpenRelated") as String, String.Empty, DialogMessage.Buttons.YesNo)
                    {
                        Owner = _view
                    }.ShowDialog() == true)
                    {
                        Dictionary <String, String> matches = Directory.GetFiles(fileParent)
                                                              .Where(path => Regex.IsMatch(path, pattern, RegexOptions.IgnoreCase))
                                                              .ToDictionary(localFilePath => objectRequest.PsnPath.Replace(fileName, Path.GetFileName(localFilePath)), localFilePath => localFilePath);
                        HistoryReocrds.AddAll(matches);
                    }
                    else
                    {
                        HistoryReocrds.Add(objectRequest.PsnPath, filePath);
                    }
                    objectRequest.LocalPath = filePath;
                }
                openFileDialog.Dispose();
            }
        }
Ejemplo n.º 3
0
        private async void Init()
        {
            SettingsHelper.InitSettings();
            HistoryReocrds.InitHistoryRecords();

            _view.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
            _view.MaxWidth  = SystemParameters.MaximizedPrimaryScreenWidth;
            _view.SetLbTitleVersion($" - {Assembly.GetExecutingAssembly().GetName().Version.ToString()}");
            SetIpPort();
            _view.LvSetItemSource(_list);

            await Aria2Manager.GetInstance().Init(b =>
            {
                if (b)
                {
                    _view.SetControlsEnable();
                    _view.SetBadge(Aria2Manager.GetInstance().GetDownloadItems().Count);
                }
                else
                {
                    ExceptionHelper.ShowErrorMsg(_view.FindResource("StrDownloadManagerConnectError") as String);
                }
            }, b =>
            {
                if (b)
                {
                    _view.SetBadge(Aria2Manager.GetInstance().GetDownloadItems().Count);
                }
            }, (psn, local) =>
            {
                if (!String.IsNullOrEmpty(psn) && !String.IsNullOrEmpty(local))
                {
                    _view.SetBadge(Aria2Manager.GetInstance().GetDownloadItems().Count);
                    HistoryReocrds.Add(psn, local);
                }
            });
        }
Ejemplo n.º 4
0
        private void HandleQuery(String query)
        {
            if (_headerFields.Count == 0 || !_headerFields.ContainsKey("Host"))
            {
                SendBadRequest();
                return;
            }

            String host;
            Int32  port;

            if (_requestMethod.ToUpper().Equals("CONNECT"))
            {
                String[] parts = _requestedPath.Split(new Char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length == 2)
                {
                    host = parts[0];
                    port = Int32.Parse(parts[1]);
                }
                else if (parts.Length == 1)
                {
                    host = parts[0];
                    port = 443;
                }
                else
                {
                    host = _requestedPath;
                    port = 80;
                }
            }
            else
            {
                String[] parts = _headerFields["Host"].Split(new Char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length == 2)
                {
                    host = parts[0];
                    port = Int32.Parse(parts[1]);
                }
                else
                {
                    host = parts[0];
                    port = 80;
                }

                if (_requestMethod.ToUpper().Equals("POST"))
                {
                    Int32 position = query.IndexOf("\r\n\r\n");
                    _requestPostBody = query.Substring(position + 4);
                }
            }

            String  psnPath       = _requestUrl;
            String  localPath     = String.Empty;
            Boolean isDownloading = false;
            Boolean isPackageFile = NetworkHelper.IsMatchExt(psnPath);

            if (isPackageFile)
            {
                localPath     = HistoryReocrds.GetLocalPath(psnPath);
                isDownloading = Aria2Manager.GetInstance().IsDownloading(psnPath);
            }

            if (!_requestMethod.ToUpper().Equals("CONNECT") && localPath != String.Empty)
            {
                SendLocalFile(localPath, _headerFields.ContainsKey("Range") ? _headerFields["Range"] : null, _headerFields.ContainsKey("Proxy-Connection") ? _headerFields["Proxy-Connection"] : null);
                isDownloading = true;
                _updateRequest(psnPath, localPath, isDownloading);
            }
            else
            {
                try
                {
                    _serverSocket = new Socket(SocketType.Stream, ProtocolType.Tcp);
                    if (_headerFields.ContainsKey("Proxy-Connection") && _headerFields["Proxy-Connection"].ToLower().Equals("keep-alive"))
                    {
                        _serverSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, 1);
                    }
                    _serverSocket.BeginConnect(host, port, OnConnected, _serverSocket);

                    if (isPackageFile)
                    {
                        _updateRequest(psnPath, localPath, isDownloading);
                    }
                }
                catch
                {
                    SendBadRequest();
                }
            }
        }
Ejemplo n.º 5
0
 private void Init()
 {
     _view.LvSetItemSource(HistoryReocrds.GetMatches().Select(match => new { Name = new Uri(match.Key).Segments.Last(), Local = match.Value, Psn = match.Key }));
 }