Пример #1
0
        public void FileAsync(string url)
        {
            try
            {

                Uri fileURI = new Uri(url);
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fileURI);
                request.Method = "GET";
                request.Proxy = null;

                RequestState state = new RequestState();
                state.Request = request;
                state.FileURI = fileURI;
                state.TransferStart = DateTime.Now;

                IAsyncResult result = request.BeginGetResponse(new AsyncCallback(ResponseCallback), state);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Пример #2
0
        private void Done(RequestState state)
        {
            string path = PluginSaveHelper.BuildSavePath(info, latest.CreationTime);
            File.WriteAllBytes(path, state.ResponseContent.ToArray());

            BuildVersion(path);
            EventProcessing(this, new PluginEventArgs(latest.ToString()));
        }
Пример #3
0
        private void Done(RequestState state)
        {
            string path = PluginSaveHelper.BuildSavePath(info, latest.CreationTime, ".zip");
            File.WriteAllBytes(path, state.ResponseContent.ToArray());

            string tmp = Path.Combine(Path.GetDirectoryName(path), "tmp");
            System.IO.Compression.ZipFile.ExtractToDirectory(path, tmp);
            File.Delete(path);
            string[] files = Directory.GetFiles(tmp, "*.exe");
            if (files.Length == 0)
                return;

            string newpath = PluginSaveHelper.BuildSavePath(info, latest.CreationTime);
            if (File.Exists(newpath))
            {
                File.Delete(newpath);
            }

            File.Move(files[0], newpath);

            BuildVersion(newpath);

            Directory.Delete(tmp, true);
            EventProcessing(this, new PluginEventArgs(latest.ToString()));
        }