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();
        }
Esempio n. 2
0
        public void FetchFolder(string url, string name)
        {
            SparkleHelpers.DebugInfo("Controller", "Formed URL: " + url);


            string host = url.Substring(url.IndexOf("@") + 1);

            if (host.Contains(":"))
            {
                host = host.Substring(0, host.IndexOf(":"));
            }
            else
            {
                host = host.Substring(0, host.IndexOf("/"));
            }


            DisableHostKeyCheckingForHost(host);


            // Strip the '.git' from the name
            string canonical_name = System.IO.Path.GetFileNameWithoutExtension(name);
            string tmp_folder     = SparkleHelpers.CombineMore(SparklePaths.SparkleTmpPath, canonical_name);

            SparkleFetcher fetcher = new SparkleFetcher(url, tmp_folder);


            bool folder_exists = Directory.Exists(
                SparkleHelpers.CombineMore(SparklePaths.SparklePath, canonical_name));

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

            while (folder_exists)
            {
                i++;
                folder_exists = Directory.Exists(
                    SparkleHelpers.CombineMore(SparklePaths.SparklePath, canonical_name + " (" + i + ")"));
            }

            string target_folder_name = canonical_name;

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


            fetcher.CloningFinished += delegate {
                EnableHostKeyCheckingForHost(host);

                SparkleHelpers.ClearAttributes(tmp_folder);

                try {
                    string target_folder_path = SparkleHelpers.CombineMore(SparklePaths.SparklePath,
                                                                           target_folder_name);

                    Directory.Move(tmp_folder, target_folder_path);
                } catch (Exception e) {
                    SparkleHelpers.DebugInfo("Controller", "Error moving folder: " + e.Message);
                }


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

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


            fetcher.CloningFailed += delegate {
                EnableHostKeyCheckingForHost(host);

                if (Directory.Exists(tmp_folder))
                {
                    SparkleHelpers.ClearAttributes(tmp_folder);
                    Directory.Delete(tmp_folder, true);

                    SparkleHelpers.DebugInfo("Config",
                                             "Deleted temporary directory: " + tmp_folder);
                }


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


            fetcher.Start();
        }
Esempio n. 3
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);
            }
        }