public void Run(ZipFile zip, ProgressCallback callback, out bool wasChanged) { var entries = zip.ToArray(); wasChanged = false; for (var index = 0; index < entries.Length; index++) { callback(zip, (index + 1), entries.Length); var entry = entries[index]; foreach (var op in _operations) { OperationResult result; if (entry.IsDirectory) { result = op.HandleDirectory(entry, zip); } else { result = op.HandleFile(entry, zip); } if (result == OperationResult.Removed) { Console.WriteLine("Removed: {0}", entry.FileName); wasChanged = true; break; } if (result == OperationResult.Changed) { wasChanged = true; } } } }
private void Upload() { //get file name string image = null; this.Invoke(new MethodInvoker(delegate { if (ImageList.SelectedIndex == 0) { CloseOnError("You need to select a version!"); return; } image = ImageList.Items[ImageList.SelectedIndex] + ".rim"; })); //connect to brick try { if (!mybrick.Connect()) { throw new NXTNotConnected(); } } catch (SocketException) { CloseOnError("Brick is busy! Perform a soft reset by turning the brick off for a few seconds."); return; } catch (Win32Exception) { CloseOnError("Brick is busy! Perform a soft reset by turning the brick off for a few seconds."); return; } catch (NullReferenceException) { CloseOnError("Not connected to a brick!"); return; } catch (Exception ex) { CloseOnError(ex.Message); return; } try { //create temporary directory string temp = "tmp"; if (Directory.Exists(temp)) { Directory.Delete(temp, true); } Directory.CreateDirectory(temp); //create vault directory if (!Directory.Exists(vaultdir)) { Directory.CreateDirectory(vaultdir); } //download file, if need to if (vaultfiles != null) { System.Net.WebClient webs = new System.Net.WebClient(); webs.DownloadFile("http://ehsandev.com/robotics/images/" + image, vaultdir + image); } //load zip ZipFile zip = new ZipFile(vaultdir + image); ZipEntry[] files = zip.ToArray(); Progress.Invoke(new MethodInvoker(delegate { Progress.Maximum = files.Length + 2; })); //keep brick alive mybrick.link.KeepAlive(); //remove all NXT user files WipeBrick(); //download files foreach (ZipEntry file in files) { AddProgress(1); SetStatus("Extracting " + file.FileName + "..."); file.Extract(temp + "/", ExtractExistingFileAction.OverwriteSilently); SetStatus("Uploading " + file.FileName + "..."); mybrick.UploadFile(temp + "/" + file.FileName, file.FileName); } //clean up Directory.Delete(temp, true); } catch (Exception ex) { CloseOnError(ex.Message); return; } //return successfully CloseOnError(null); }