protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (disposing)
            {
                if (_logger != null)
                    _logger.Dispose();
                _logger = null;
            }
        }
 public static void AddProgressLogger(ProgressLogger prog)
 {
     Write(new LogEntry(prog, null));
 }
 public ProgressWebClient(string message)
 {
     _logger = new ProgressLogger(1, message);
 }
        private static string[] InstallUpdate(string path)
        {
            //Extract ZIP's into a seperate folder
            //Install everything else as a plugin

            var info = new FileInfo(path);

            var ext = info.Extension.ToLower();
            if (ext == ".zip")
            {
                //Extract into a temporary directory incase of zip exceptions that could potentially corrupt our installation
                var tmp = ExtractZip(info);
                if (!String.IsNullOrEmpty(tmp))
                {
                    //Read package
                    var pkgFile = Path.Combine(tmp, "package.json");
                    if (File.Exists(pkgFile))
                    {
                        var pkg = Newtonsoft.Json.JsonConvert.DeserializeObject<UpdatePackage>(File.ReadAllText(pkgFile));
                        if (pkg != null && pkg.Instructions != null && pkg.Instructions.Length > 0)
                        {
                            //Verify first then install
                            using (var logger = new ProgressLogger(pkg.Instructions.Length, "Verifying package"))
                            {
                                foreach (var ins in pkg.Instructions)
                                {
                                    if (String.IsNullOrEmpty(ins.PackageFileName)) throw new RepositoryError("Invalid source file");
                                    if (String.IsNullOrEmpty(ins.DestinationFileName)) ins.DestinationFileName = ins.PackageFileName; //If not provided then it means it's the same

                                    var relPath = ins.PackageFileName.Split(ins.DirectorySeperator);
                                    relPath = new string[] { tmp }.Concat(relPath).ToArray();
                                    var from = Path.Combine(relPath);

                                    if (!File.Exists(from)) throw new RepositoryError("Source file {0} does not exist", ins.PackageFileName);

                                    var toPath = ins.PackageFileName.Split(ins.DirectorySeperator);
                                    toPath = new string[] { Environment.CurrentDirectory }.Concat(toPath).ToArray();
                                    var to = Path.Combine(toPath);

                                    if (IsChild(to) == null) throw new RepositoryError("Destination file {0} is not within the TDSM install directory", ins.DestinationFileName);
                                }
                            }

                            using (var logger = new ProgressLogger(pkg.Instructions.Length, "Installing package"))
                            {
                                foreach (var ins in pkg.Instructions)
                                {
                                    var relPath = ins.PackageFileName.Split(ins.DirectorySeperator);
                                    relPath = new string[] { tmp }.Concat(relPath).ToArray();
                                    var from = Path.Combine(relPath);

                                    var toPath = ins.PackageFileName.Split(ins.DirectorySeperator);
                                    toPath = new string[] { Environment.CurrentDirectory }.Concat(toPath).ToArray();
                                    var to = IsChild(Path.Combine(toPath));

                                    if (File.Exists(to)) File.Delete(to);
                                    File.Move(from, to);
                                }
                            }

                            ProgramLog.Admin.Log("Cleaning up");
                            Directory.Delete(tmp, true);
                            File.Delete(path);

                            return pkg.PluginsToLoad;
                        }
                        else
                        {
                            throw new RepositoryError("No install instructions");
                        }
                    }
                    else
                    {
                        throw new RepositoryError("package.json is missing");
                    }
                }
                else
                {
                    throw new RepositoryError("Failed to extract package");
                }
            }
            else if (ext == ".lua" || ext == ".dll")
            {
                //Move and replace targets
                var dest = Path.Combine(Globals.PluginPath, info.Name);
                if (File.Exists(dest)) File.Delete(dest);
                File.Move(info.FullName, dest);

                return new string[] { dest };
            }
            else throw new RepositoryError("No package support for {0}", ext ?? "<unknown>");
        }