示例#1
0
        public void StartFetcher(SparkleFetcherInfo info)
        {
            string tmp_path = Config.TmpPath;

            if (!Directory.Exists(tmp_path))
            {
                Directory.CreateDirectory(tmp_path);
                File.SetAttributes(tmp_path, File.GetAttributes(tmp_path) | FileAttributes.Hidden);
            }

            string canonical_name = Path.GetFileName(info.RemotePath);
            string backend        = info.Backend;

            if (string.IsNullOrEmpty(backend))
            {
                backend = SparkleFetcherBase.GetBackend(info.Address);
            }

            info.TargetDirectory = Path.Combine(tmp_path, canonical_name);

            try {
                this.fetcher = (SparkleFetcherBase)Activator.CreateInstance(
                    Type.GetType("SparkleLib." + backend + ".SparkleFetcher, SparkleLib." + backend), info);
            } catch (Exception e) {
                SparkleLogger.LogInfo("Controller",
                                      "Failed to load '" + backend + "' backend for '" + canonical_name + "' " + e.Message);

                FolderFetchError(Path.Combine(info.Address, info.RemotePath).Replace(@"\", "/"),
                                 new string [] { "Failed to load \"" + backend + "\" backend for \"" + canonical_name + "\"" });

                return;
            }

            this.fetcher.Finished += delegate(bool repo_is_encrypted, bool repo_is_empty, string [] warnings) {
                if (repo_is_encrypted && repo_is_empty)
                {
                    ShowSetupWindowEvent(PageType.CryptoSetup);
                }
                else if (repo_is_encrypted)
                {
                    ShowSetupWindowEvent(PageType.CryptoPassword);
                }
                else
                {
                    FinishFetcher();
                }
            };

            this.fetcher.Failed += delegate {
                FolderFetchError(this.fetcher.RemoteUrl.ToString(), this.fetcher.Errors);
                StopFetcher();
            };

            this.fetcher.ProgressChanged += delegate(double percentage, double speed) {
                FolderFetching(percentage, speed);
            };

            this.fetcher.Start();
        }
示例#2
0
        public void FinishFetcher()
        {
            this.watcher.EnableRaisingEvents = false;

            this.fetcher.Complete();
            string canonical_name = Path.GetFileNameWithoutExtension(this.fetcher.RemoteUrl.AbsolutePath);

            bool target_folder_exists = Directory.Exists(
                Path.Combine(this.config.FoldersPath, canonical_name));

            // Add a numbered suffix to the name if a folder with the same name
            // already exists. Example: "Folder (2)"
            int suffix = 1;

            while (target_folder_exists)
            {
                suffix++;
                target_folder_exists = Directory.Exists(
                    Path.Combine(this.config.FoldersPath, canonical_name + " (" + suffix + ")"));
            }

            string target_folder_name = canonical_name;

            if (suffix > 1)
            {
                target_folder_name += " (" + suffix + ")";
            }

            string target_folder_path = Path.Combine(this.config.FoldersPath, target_folder_name);

            try {
                ClearFolderAttributes(this.fetcher.TargetFolder);
                Directory.Move(this.fetcher.TargetFolder, target_folder_path);
            } catch (Exception e) {
                SparkleLogger.LogInfo("Controller", "Error moving directory: " + e.Message);
                return;
            }

            string backend = SparkleFetcherBase.GetBackend(this.fetcher.RemoteUrl.AbsolutePath);

            this.config.AddFolder(target_folder_name, this.fetcher.Identifier,
                                  this.fetcher.RemoteUrl.ToString(), backend);

            FolderFetched(this.fetcher.RemoteUrl.ToString(), this.fetcher.Warnings.ToArray());

            /* TODO
             * if (!string.IsNullOrEmpty (announcements_url)) {
             *  this.config.SetFolderOptionalAttribute (
             *      target_folder_name, "announcements_url", announcements_url);
             */

            AddRepository(target_folder_path);
            FolderListChanged();

            this.fetcher.Dispose();
            this.fetcher = null;

            this.watcher.EnableRaisingEvents = true;
        }
示例#3
0
        public void StopFetcher()
        {
            this.fetcher.Stop();
            this.fetcher.Dispose();

            this.fetcher = null;
            this.watcher.EnableRaisingEvents = true;
        }
示例#4
0
        public void StopFetcher()
        {
            this.fetcher.Stop();

            if (Directory.Exists(this.fetcher.TargetFolder))
            {
                try {
                    Directory.Delete(this.fetcher.TargetFolder, true);
                    SparkleLogger.LogInfo("Controller", "Deleted " + this.fetcher.TargetFolder);
                } catch (Exception e) {
                    SparkleLogger.LogInfo("Controller",
                                          "Failed to delete " + this.fetcher.TargetFolder + ": " + e.Message);
                }
            }

            this.fetcher.Dispose();
            this.fetcher = null;
        }
示例#5
0
        public void StopFetcher()
        {
            this.fetcher.Stop();

            if (Directory.Exists(this.fetcher.TargetFolder))
            {
                try {
                    Directory.Delete(this.fetcher.TargetFolder, true /* Recursive */);
                    SparkleLogger.LogInfo("Controller", "Deleted '" + this.fetcher.TargetFolder + "'");
                } catch (Exception e) {
                    SparkleLogger.LogInfo("Controller", "Failed to delete '" + this.fetcher.TargetFolder + "'", e);
                }
            }

            this.fetcher.Dispose();
            this.fetcher = null;

            this.watcher.EnableRaisingEvents = true;
        }
        public void FetchFolder(string server, string remote_folder)
        {
            server        = server.Trim();
            remote_folder = remote_folder.Trim();

            string tmp_path = SparkleConfig.DefaultConfig.TmpPath;

            if (!Directory.Exists(tmp_path))
            {
                Directory.CreateDirectory(tmp_path);
            }

            // Strip the '.git' from the name
            string canonical_name = Path.GetFileNameWithoutExtension(remote_folder);
            string tmp_folder     = Path.Combine(tmp_path, canonical_name);

            string backend = null;

/*            if (remote_folder.EndsWith (".hg")) {
 *              remote_folder = remote_folder.Substring (0, (remote_folder.Length - 3));
 *              fetcher       = new SparkleFetcherHg (server, remote_folder, tmp_folder);
 *              backend       = "Hg";
 *
 *          } else if (remote_folder.EndsWith (".scp")) {
 *              remote_folder = remote_folder.Substring (0, (remote_folder.Length - 4));
 *              fetcher = new SparkleFetcherScp (server, remote_folder, tmp_folder);
 *              backend = "Scp";
 *
 *          } else {*/
            this.fetcher = new SparkleFetcherGit(server, remote_folder, tmp_folder);
            backend      = "Git";
            //}

            bool target_folder_exists = Directory.Exists(
                Path.Combine(SparkleConfig.DefaultConfig.FoldersPath, canonical_name));

            // Add a numbered suffix to the nameif a folder with the same name
            // already exists. Example: "Folder (2)"
            int i = 1;

            while (target_folder_exists)
            {
                i++;
                target_folder_exists = Directory.Exists(
                    Path.Combine(SparkleConfig.DefaultConfig.FoldersPath, canonical_name + " (" + i + ")"));
            }

            string target_folder_name = canonical_name;

            if (i > 1)
            {
                target_folder_name += " (" + i + ")";
            }

            this.fetcher.Finished += delegate(string [] warnings) {
                // Needed to do the moving
                SparkleHelpers.ClearAttributes(tmp_folder);
                string target_folder_path = Path.Combine(
                    SparkleConfig.DefaultConfig.FoldersPath, target_folder_name);

                try {
                    Directory.Move(tmp_folder, target_folder_path);

                    SparkleConfig.DefaultConfig.AddFolder(target_folder_name, this.fetcher.RemoteUrl, backend);
                    AddRepository(target_folder_path);

                    if (FolderFetched != null)
                    {
                        FolderFetched(warnings);
                    }

                    if (FolderListChanged != null)
                    {
                        FolderListChanged();
                    }

                    this.fetcher.Dispose();

                    if (Directory.Exists(tmp_path))
                    {
                        Directory.Delete(tmp_path, true);
                    }
                } catch (Exception e) {
                    SparkleHelpers.DebugInfo("Controller", "Error moving folder: " + e.Message);
                }
            };


            this.fetcher.Failed += delegate {
                if (FolderFetchError != null)
                {
                    FolderFetchError(this.fetcher.RemoteUrl);
                }

                this.fetcher.Dispose();

                if (Directory.Exists(tmp_path))
                {
                    Directory.Delete(tmp_path, true);
                }
            };


            this.fetcher.ProgressChanged += delegate(double percentage) {
                if (FolderFetching != null)
                {
                    FolderFetching(percentage);
                }
            };


            this.fetcher.Start();
        }
示例#7
0
        public void FinishFetcher()
        {
            this.watcher.EnableRaisingEvents = false;

            this.fetcher.Complete();
            string canonical_name = Path.GetFileName(this.fetcher.RemoteUrl.AbsolutePath);

            if (canonical_name.EndsWith(".git"))
            {
                canonical_name = canonical_name.Replace(".git", "");
            }

            canonical_name = canonical_name.Replace("-crypto", "");
            canonical_name = canonical_name.Replace("_", " ");
            canonical_name = canonical_name.Replace("%20", " ");

            bool target_folder_exists = Directory.Exists(
                Path.Combine(Config.FoldersPath, canonical_name));

            // Add a numbered suffix to the name if a folder with the same name
            // already exists. Example: "Folder (2)"
            int suffix = 1;

            while (target_folder_exists)
            {
                suffix++;
                target_folder_exists = Directory.Exists(
                    Path.Combine(Config.FoldersPath, canonical_name + " (" + suffix + ")"));
            }

            string target_folder_name = canonical_name;

            if (suffix > 1)
            {
                target_folder_name += " (" + suffix + ")";
            }

            string target_folder_path = Path.Combine(Config.FoldersPath, target_folder_name);

            try {
                Directory.Move(this.fetcher.TargetFolder, target_folder_path);
            } catch (Exception e) {
                SparkleLogger.LogInfo("Controller", "Error moving directory, trying again...", e);

                try {
                    ClearDirectoryAttributes(this.fetcher.TargetFolder);
                    Directory.Move(this.fetcher.TargetFolder, target_folder_path);
                } catch (Exception x) {
                    SparkleLogger.LogInfo("Controller", "Error moving directory", x);

                    this.fetcher.Dispose();
                    this.fetcher = null;
                    this.watcher.EnableRaisingEvents = true;
                    return;
                }
            }

            string backend = SparkleFetcherBase.GetBackend(this.fetcher.RemoteUrl.ToString());

            Config.AddFolder(target_folder_name, this.fetcher.Identifier,
                             this.fetcher.RemoteUrl.ToString(), backend);

            if (this.fetcher.OriginalFetcherInfo.AnnouncementsUrl != null)
            {
                Config.SetFolderOptionalAttribute(target_folder_name, "announcements_url",
                                                  this.fetcher.OriginalFetcherInfo.AnnouncementsUrl);
            }

            RepositoriesLoaded = true;
            FolderFetched(this.fetcher.RemoteUrl.ToString(), this.fetcher.Warnings.ToArray());

            AddRepository(target_folder_path);
            FolderListChanged();

            this.fetcher.Dispose();
            this.fetcher = null;

            this.watcher.EnableRaisingEvents = true;
        }
示例#8
0
        public void StartFetcher(string address, string required_fingerprint,
                                 string remote_path, string announcements_url, bool fetch_prior_history)
        {
            if (announcements_url != null)
            {
                announcements_url = announcements_url.Trim();
            }

            string tmp_path = this.config.TmpPath;

            if (!Directory.Exists(tmp_path))
            {
                Directory.CreateDirectory(tmp_path);
                File.SetAttributes(tmp_path, File.GetAttributes(tmp_path) | FileAttributes.Hidden);
            }

            string canonical_name = Path.GetFileNameWithoutExtension(remote_path);
            string tmp_folder     = Path.Combine(tmp_path, canonical_name);
            string backend        = SparkleFetcherBase.GetBackend(remote_path);

            try {
                this.fetcher = (SparkleFetcherBase)Activator.CreateInstance(
                    Type.GetType("SparkleLib." + backend + ".SparkleFetcher, SparkleLib." + backend),
                    address, required_fingerprint, remote_path, tmp_folder, fetch_prior_history
                    );
            } catch (Exception e) {
                SparkleLogger.LogInfo("Controller",
                                      "Failed to load '" + backend + "' backend for '" + canonical_name + "' " + e.Message);

                FolderFetchError(Path.Combine(address, remote_path).Replace(@"\", "/"),
                                 new string [] { "Failed to load \"" + backend + "\" backend for \"" + canonical_name + "\"" });

                return;
            }


            this.fetcher.Finished += delegate(bool repo_is_encrypted, bool repo_is_empty, string [] warnings) {
                if (repo_is_encrypted && repo_is_empty)
                {
                    ShowSetupWindowEvent(PageType.CryptoSetup);
                }
                else if (repo_is_encrypted)
                {
                    ShowSetupWindowEvent(PageType.CryptoPassword);
                }
                else
                {
                    FinishFetcher();
                }
            };

            this.fetcher.Failed += delegate {
                FolderFetchError(this.fetcher.RemoteUrl.ToString(), this.fetcher.Errors);
                StopFetcher();
            };

            this.fetcher.ProgressChanged += delegate(double percentage) {
                FolderFetching(percentage);
            };

            this.fetcher.Start();
        }
示例#9
0
        public void FinishFetcher()
        {
            this.fetcher.Complete();
            string canonical_name = Path.GetFileNameWithoutExtension(this.fetcher.RemoteUrl.AbsolutePath);

            bool target_folder_exists = Directory.Exists(
                Path.Combine(SparkleConfig.DefaultConfig.FoldersPath, canonical_name));

            // Add a numbered suffix to the name if a folder with the same name
            // already exists. Example: "Folder (2)"
            int suffix = 1;

            while (target_folder_exists)
            {
                suffix++;
                target_folder_exists = Directory.Exists(
                    Path.Combine(
                        SparkleConfig.DefaultConfig.FoldersPath,
                        canonical_name + " (" + suffix + ")"
                        )
                    );
            }

            string target_folder_name = canonical_name;

            if (suffix > 1)
            {
                target_folder_name += " (" + suffix + ")";
            }

            string target_folder_path = Path.Combine(SparkleConfig.DefaultConfig.FoldersPath, target_folder_name);

            try {
                SparkleHelpers.ClearAttributes(this.fetcher.TargetFolder);
                Directory.Move(this.fetcher.TargetFolder, target_folder_path);

                string backend = SparkleFetcherBase.GetBackend(this.fetcher.RemoteUrl.AbsolutePath);
                SparkleConfig.DefaultConfig.AddFolder(target_folder_name, this.fetcher.RemoteUrl.ToString(), backend);

                if (FolderFetched != null)
                {
                    FolderFetched(this.fetcher.RemoteUrl.ToString(), this.fetcher.Warnings.ToArray());
                }

                /* TODO
                 * if (!string.IsNullOrEmpty (announcements_url)) {
                 *  SparkleConfig.DefaultConfig.SetFolderOptionalAttribute (
                 *      target_folder_name, "announcements_url", announcements_url);
                 */

                lock (this.repo_lock) {
                    AddRepository(target_folder_path);
                }

                if (FolderListChanged != null)
                {
                    FolderListChanged();
                }

                this.fetcher.Dispose();
                this.fetcher = null;
            } catch (Exception e) {
                SparkleHelpers.DebugInfo("Controller", "Error adding folder: " + e.Message);
            }
        }