private void DownloadComplete(LauncherData.LauncherVersion theVersion, byte[] arFileBytes) { App.Current.Dispatcher.BeginInvoke(new System.Windows.Forms.MethodInvoker(delegate() { string strUpdateDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + Path.DirectorySeparatorChar + "Updates"; string strFilename = Path.GetFileName(theVersion.Location); if (!Directory.Exists(strUpdateDirectory)) { Directory.CreateDirectory(strUpdateDirectory); } if (File.Exists(strUpdateDirectory + Path.DirectorySeparatorChar + strFilename)) { File.Delete(strUpdateDirectory + Path.DirectorySeparatorChar + strFilename); } FileStream outFile = new FileStream(strUpdateDirectory + Path.DirectorySeparatorChar + strFilename, FileMode.CreateNew, FileAccess.Write); BinaryWriter writeME = new BinaryWriter(outFile); writeME.Write(arFileBytes); writeME.Close(); outFile.Close(); if (OnDownloadComplete != null) { OnDownloadComplete(this, new DownloadCompleteEventArgs(strUpdateDirectory + Path.DirectorySeparatorChar + strFilename)); } }), System.Windows.Threading.DispatcherPriority.Normal); }
public void UpdateToLatestVersion(Dispatcher myDispatcher, LauncherData.LauncherVersion theVersion) { myDispatcher.BeginInvoke(new System.Windows.Forms.MethodInvoker(delegate() { //open a webrequest WebRequest req = WebRequest.Create("http://swganh.hooni.us" + theVersion.Location); req.Method = "GET"; //wrap our object togethers DownloadRequest theRequest = new DownloadRequest { Request = req, Version = theVersion }; //and initialise an array to hold our bytes[] arFileBytes = new byte[theVersion.FileSize]; //and a counter to record the download progress nBytesRead = 0; //start the download req.BeginGetResponse(new AsyncCallback(DownloadStarted), theRequest); }), System.Windows.Threading.DispatcherPriority.Normal); }