Ejemplo n.º 1
0
        private void ListPrivateKeys()
        {
            Process process = new Process()
            {
                EnableRaisingEvents = true
            };

            process.StartInfo.WorkingDirectory       = SparkleConfig.DefaultConfig.TmpPath;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.CreateNoWindow         = true;

            process.StartInfo.FileName  = "ssh-add";
            process.StartInfo.Arguments = "-l";

            process.Start();

            // Reading the standard output HAS to go before
            // WaitForExit, or it will hang forever on output > 4096 bytes
            string keys_in_use = process.StandardOutput.ReadToEnd().Trim();

            process.WaitForExit();

            SparkleHelpers.DebugInfo("Auth",
                                     "The following keys will be available to SparkleShare: " + Environment.NewLine + keys_in_use);
        }
Ejemplo n.º 2
0
        // Creates a .desktop entry in autostart folder to
        // start SparkleShare automatically at login
        public override void EnableSystemAutostart()
        {
            string autostart_path   = SparkleHelpers.CombineMore(SparklePaths.HomePath, ".config", "autostart");
            string desktopfile_path = SparkleHelpers.CombineMore(autostart_path, "sparkleshare.desktop");

            if (!File.Exists(desktopfile_path))
            {
                if (!Directory.Exists(autostart_path))
                {
                    Directory.CreateDirectory(autostart_path);
                }

                TextWriter writer = new StreamWriter(desktopfile_path);
                writer.WriteLine("[Desktop Entry]\n" +
                                 "Type=Application\n" +
                                 "Name=SparkleShare\n" +
                                 "Exec=sparkleshare start\n" +
                                 "Icon=folder-sparkleshare\n" +
                                 "Terminal=false\n" +
                                 "X-GNOME-Autostart-enabled=true\n" +
                                 "Categories=Network");
                writer.Close();

                // Give the launcher the right permissions so it can be launched by the user
                UnixFileInfo file_info = new UnixFileInfo(desktopfile_path);
                file_info.Create(FileAccessPermissions.UserReadWriteExecute);

                SparkleHelpers.DebugInfo("Controller", "Created: " + desktopfile_path);
            }
        }
Ejemplo n.º 3
0
        // Creates a .desktop entry in autostart folder to
        // start SparkleShare automatically at login
        public override void CreateStartupItem()
        {
            string autostart_path = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                "autostart"
                );

            string desktopfile_path = Path.Combine(autostart_path, "sparkleshare.desktop");

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

            if (!File.Exists(desktopfile_path))
            {
                try {
                    File.WriteAllText(desktopfile_path,
                                      "[Desktop Entry]\n" +
                                      "Type=Application\n" +
                                      "Name=SparkleShare\n" +
                                      "Exec=sparkleshare start\n" +
                                      "Icon=folder-sparkleshare\n" +
                                      "Terminal=false\n" +
                                      "X-GNOME-Autostart-enabled=true\n" +
                                      "Categories=Network");

                    SparkleHelpers.DebugInfo("Controller", "Added SparkleShare to login items");
                } catch (Exception e) {
                    SparkleHelpers.DebugInfo("Controller", "Failed adding SparkleShare to login items: " + e.Message);
                }
            }
        }
Ejemplo n.º 4
0
        public override void CreateStartupItem()
        {
            // There aren't any bindings in MonoMac to support this yet, so
            // we call out to an applescript to do the job
            Process process = new Process();

            process.EnableRaisingEvents = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.FileName       = "osascript";
            process.StartInfo.CreateNoWindow = true;

            string app_path = Path.GetDirectoryName(NSBundle.MainBundle.ResourcePath);

            app_path = Path.GetDirectoryName(app_path);

            process.StartInfo.Arguments = "-e 'tell application \"System Events\" to " +
                                          "make login item at end with properties {path:\"" + app_path + "\", hidden:false}'";

            process.Exited += delegate {
                SparkleHelpers.DebugInfo("Controller", "Added " + app_path + " to login items");
            };

            try {
                process.Start();
            } catch (Exception e) {
                SparkleHelpers.DebugInfo("Controller", "Failed adding " + app_path + " to login items: " + e.Message);
            }
        }
        public List <SparkleChangeSet> GetLog()
        {
            List <SparkleChangeSet> list = new List <SparkleChangeSet> ();

            foreach (SparkleRepoBase repo in Repositories)
            {
                List <SparkleChangeSet> change_sets = repo.GetChangeSets(50);

                if (change_sets != null)
                {
                    list.AddRange(change_sets);
                }
                else
                {
                    SparkleHelpers.DebugInfo("Log", "Could not create log for " + repo.Name);
                }
            }

            list.Sort((x, y) => (x.Timestamp.CompareTo(y.Timestamp)));
            list.Reverse();

            if (list.Count > 100)
            {
                return(list.GetRange(0, 100));
            }
            else
            {
                return(list.GetRange(0, list.Count));
            }
        }
Ejemplo n.º 6
0
        // Creates the SparkleShare folder in the user's home folder
        public override bool CreateSparkleShareFolder()
        {
            if (!Directory.Exists(SparklePaths.SparklePath))
            {
                Directory.CreateDirectory(SparklePaths.SparklePath);
                SparkleHelpers.DebugInfo("Controller", "Created '" + SparklePaths.SparklePath + "'");

                string icon_file_path = SparkleHelpers.CombineMore(Defines.DATAROOTDIR, "icons", "hicolor",
                                                                   "48x48", "apps", "folder-sparkleshare.png");

                string gvfs_command_path = SparkleHelpers.CombineMore(Path.VolumeSeparatorChar.ToString(),
                                                                      "usr", "bin", "gvfs-set-attribute");

                // Add a special icon to the SparkleShare folder
                if (File.Exists(gvfs_command_path))
                {
                    Process process = new Process();

                    process.StartInfo.RedirectStandardOutput = true;
                    process.StartInfo.UseShellExecute        = false;

                    process.StartInfo.FileName  = "gvfs-set-attribute";
                    process.StartInfo.Arguments = SparklePaths.SparklePath + " metadata::custom-icon " +
                                                  "file://" + icon_file_path;
                    process.Start();
                }

                return(true);
            }

            return(false);
        }
Ejemplo n.º 7
0
        // Merges the fetched changes
        private void Rebase()
        {
            if (HasLocalChanges)
            {
                Add();

                string commit_message = FormatCommitMessage();
                Commit(commit_message);
            }

            SparkleGit git = new SparkleGit(LocalPath, "rebase FETCH_HEAD");

            git.StartInfo.RedirectStandardOutput = false;

            git.Start();
            git.WaitForExit();

            if (git.ExitCode != 0)
            {
                SparkleHelpers.DebugInfo("Git", "[" + Name + "] Conflict detected, trying to get out...");

                while (HasLocalChanges)
                {
                    ResolveConflict();
                }

                SparkleHelpers.DebugInfo("Git", "[" + Name + "] Conflict resolved");
                OnConflictResolved();
            }
        }
Ejemplo n.º 8
0
        // Uploads the user's public key to the server
        public bool AcceptInvitation(string server, string folder, string token)
        {
            // The location of the user's public key for SparkleShare
            string public_key_file_path = SparkleHelpers.CombineMore(SparklePaths.HomePath, ".ssh",
                                                                     "sparkleshare." + UserEmail + ".key.pub");

            if (!File.Exists(public_key_file_path))
            {
                return(false);
            }

            StreamReader reader     = new StreamReader(public_key_file_path);
            string       public_key = reader.ReadToEnd();

            reader.Close();

            string url = "https://" + server + "/?folder=" + folder +
                         "&token=" + token + "&pubkey=" + public_key;

            SparkleHelpers.DebugInfo("WebRequest", url);

            HttpWebRequest  request  = (HttpWebRequest)WebRequest.Create(url);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            if (response.StatusCode == HttpStatusCode.OK)
            {
                response.Close();
                return(true);
            }
            else
            {
                response.Close();
                return(false);
            }
        }
Ejemplo n.º 9
0
        // Creates a folder in the user's home folder to store configuration
        private void CreateConfigurationFolders()
        {
            if (!Directory.Exists(SparklePaths.SparkleTmpPath))
            {
                Directory.CreateDirectory(SparklePaths.SparkleTmpPath);
            }

            string config_path     = SparklePaths.SparkleConfigPath;
            string local_icon_path = SparklePaths.SparkleLocalIconPath;

            if (!Directory.Exists(config_path))
            {
                // Create a folder to store settings
                Directory.CreateDirectory(config_path);
                SparkleHelpers.DebugInfo("Config", "Created '" + config_path + "'");

                // Create a folder to store the avatars
                Directory.CreateDirectory(local_icon_path);
                SparkleHelpers.DebugInfo("Config", "Created '" + local_icon_path + "'");

                string notify_setting_file = SparkleHelpers.CombineMore(config_path, "sparkleshare.notify");

                // Enable notifications by default
                if (!File.Exists(notify_setting_file))
                {
                    File.Create(notify_setting_file);
                }
            }
        }
Ejemplo n.º 10
0
        // Install the user's name and email and some config into
        // the newly cloned repository
        private void InstallConfiguration()
        {
            string repo_config_file_path = SparkleHelpers.CombineMore(TargetFolder, ".git", "config");
            string config = File.ReadAllText(repo_config_file_path);

            string n = Environment.NewLine;

            config = config.Replace("[core]" + n,
                                    "[core]" + n +
                                    "\tquotepath = false" + n + // Show special characters in the logs
                                    "\tpackedGitLimit = 128m" + n +
                                    "\tautocrlf = false" + n +
                                    "\tsafecrlf = false" + n +
                                    "\tpackedGitWindowSize = 128m" + n);

            config = config.Replace("[remote \"origin\"]" + n,
                                    "[pack]" + n +
                                    "\tdeltaCacheSize = 128m" + n +
                                    "\tpackSizeLimit = 128m" + n +
                                    "\twindowMemory = 128m" + n +
                                    "[remote \"origin\"]" + n);

            // Be case sensitive explicitly to work on Mac
            config = config.Replace("ignorecase = true", "ignorecase = false");

            // Ignore permission changes
            config = config.Replace("filemode = true", "filemode = false");

            // Write the config to the file
            File.WriteAllText(repo_config_file_path, config);
            SparkleHelpers.DebugInfo("Fetcher", "Added configuration to '" + repo_config_file_path + "'");
        }
Ejemplo n.º 11
0
        // Installs a launcher so the user can launch SparkleShare
        // from the Internet category if needed
        public override void InstallLauncher()
        {
            string apps_path        = SparkleHelpers.CombineMore(SparklePaths.HomePath, ".local", "share", "applications");
            string desktopfile_path = SparkleHelpers.CombineMore(apps_path, "sparkleshare.desktop");

            if (!File.Exists(desktopfile_path))
            {
                if (!Directory.Exists(apps_path))
                {
                    Directory.CreateDirectory(apps_path);
                }

                TextWriter writer = new StreamWriter(desktopfile_path);
                writer.WriteLine("[Desktop Entry]\n" +
                                 "Type=Application\n" +
                                 "Name=SparkleShare\n" +
                                 "Comment=Share documents\n" +
                                 "Exec=sparkleshare start\n" +
                                 "Icon=folder-sparkleshare\n" +
                                 "Terminal=false\n" +
                                 "Categories=Network;");
                writer.Close();

                // Give the launcher the right permissions so it can be launched by the user
                UnixFileInfo file_info = new UnixFileInfo(desktopfile_path);
                file_info.FileAccessPermissions = FileAccessPermissions.UserReadWriteExecute;

                SparkleHelpers.DebugInfo("Controller", "Created '" + desktopfile_path + "'");
            }
        }
Ejemplo n.º 12
0
        // Generates and installs an RSA keypair to identify this system
        public void GenerateKeyPair()
        {
            string keys_path     = Path.GetDirectoryName(SparkleConfig.DefaultConfig.FullPath);
            string key_file_name = "sparkleshare." + CurrentUser.Email + ".key";
            string key_file_path = Path.Combine(keys_path, key_file_name);

            if (File.Exists(key_file_path))
            {
                SparkleHelpers.DebugInfo("Auth", "Keypair exists ('" + key_file_name + "'), leaving it untouched");
                return;
            }
            else
            {
                if (!Directory.Exists(keys_path))
                {
                    Directory.CreateDirectory(keys_path);
                }
            }

            Process process = new Process()
            {
                EnableRaisingEvents = true
            };

            process.StartInfo.WorkingDirectory       = keys_path;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.FileName       = "ssh-keygen";
            process.StartInfo.CreateNoWindow = true;

            string computer_name = System.Net.Dns.GetHostName();

            if (computer_name.EndsWith(".local"))
            {
                computer_name = computer_name.Replace(".local", "");
            }

            process.StartInfo.Arguments = "-t rsa " +                       // crypto type
                                          "-P \"\" " +                      // password (none)
                                          "-C \"" + computer_name + "\" " + // key comment
                                          "-f " + key_file_name;            // file name

            process.Start();
            process.WaitForExit();

            if (process.ExitCode == 0)
            {
                SparkleHelpers.DebugInfo("Auth", "Created keypair '" + key_file_name + "'");
            }
            else
            {
                SparkleHelpers.DebugInfo("Auth", "Could not create keypair '" + key_file_name + "'");
            }

            // Create an easily accessible copy of the public
            // key in the user's SparkleShare folder
            File.Copy(key_file_path + ".pub", Path.Combine(SparklePath, CurrentUser.Name + "'s link code.txt"), true);
        }
Ejemplo n.º 13
0
        // Stages the made changes
        private void Add()
        {
            SparkleGit git = new SparkleGit(LocalPath, "add --all");

            git.Start();
            git.WaitForExit();

            SparkleHelpers.DebugInfo("Git", "[" + Name + "] Changes staged");
        }
Ejemplo n.º 14
0
        // Gets the avatar for a specific email address and size
        public static string GetAvatar(string email, int size)
        {
            string avatar_path = SparkleHelpers.CombineMore(SparklePaths.SparkleLocalIconPath,
                                                            size + "x" + size, "status");

            if (!Directory.Exists(avatar_path))
            {
                Directory.CreateDirectory(avatar_path);
                SparkleHelpers.DebugInfo("Config", "Created '" + avatar_path + "'");
            }

            string avatar_file_path = SparkleHelpers.CombineMore(avatar_path, "avatar-" + email);

            if (File.Exists(avatar_file_path))
            {
                return(avatar_file_path);
            }
            else
            {
                // Let's try to get the person's gravatar for next time
                WebClient web_client = new WebClient();
                Uri       uri        = new Uri("http://www.gravatar.com/avatar/" + GetMD5(email) +
                                               ".jpg?s=" + size + "&d=404");

                string tmp_file_path = SparkleHelpers.CombineMore(SparklePaths.SparkleTmpPath, email + size);

                if (!File.Exists(tmp_file_path))
                {
                    web_client.DownloadFileAsync(uri, tmp_file_path);

                    web_client.DownloadFileCompleted += delegate {
                        if (File.Exists(avatar_file_path))
                        {
                            File.Delete(avatar_file_path);
                        }

                        FileInfo tmp_file_info = new FileInfo(tmp_file_path);

                        if (tmp_file_info.Length > 255)
                        {
                            File.Move(tmp_file_path, avatar_file_path);
                        }
                    };
                }

                // Fall back to a generic icon if there is no gravatar
                if (File.Exists(avatar_file_path))
                {
                    return(avatar_file_path);
                }
                else
                {
                    return(null);
                }
            }
        }
Ejemplo n.º 15
0
 public override void Stop()
 {
     try {
         this.git.Close();
         this.git.Kill();
         this.git.Dispose();
     } catch (Exception e) {
         SparkleHelpers.DebugInfo("Fetcher", "Failed to dispose properly: " + e.Message);
     }
 }
Ejemplo n.º 16
0
        // Generates and installs an RSA keypair to identify this system
        public void GenerateKeyPair()
        {
            string keys_path     = Path.GetDirectoryName(SparkleConfig.DefaultConfig.FullPath);
            string key_file_name = "sparkleshare." + UserEmail + ".key";
            string key_file_path = Path.Combine(keys_path, key_file_name);

            if (File.Exists(key_file_path))
            {
                SparkleHelpers.DebugInfo("Config", "Key already exists ('" + key_file_name + "'), " +
                                         "leaving it untouched");
                return;
            }

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

            if (!File.Exists(key_file_name))
            {
                Process process = new Process()
                {
                    EnableRaisingEvents = true
                };

                process.StartInfo.WorkingDirectory       = keys_path;
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.FileName = "ssh-keygen";

                // -t is the crypto type
                // -P is the password (none)
                // -f is the file name to store the private key in
                process.StartInfo.Arguments = "-t rsa -P \"\" -f " + key_file_name;

                process.Start();
                process.WaitForExit();

                SparkleHelpers.DebugInfo("Config", "Created private key '" + key_file_name + "'");
                SparkleHelpers.DebugInfo("Config", "Created public key  '" + key_file_name + ".pub'");

                // Add some restrictions to what the key can
                // do when uploaded to the server
                // string public_key = File.ReadAllText (key_file_path + ".pub");
                // public_key = "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty " + public_key;
                // File.WriteAllText (key_file_path + ".pub", public_key);

                // Create an easily accessible copy of the public
                // key in the user's SparkleShare folder
                File.Copy(key_file_path + ".pub",
                          Path.Combine(SparklePath, UserName + "'s key.txt"),
                          true); // Overwriting is allowed
            }
        }
Ejemplo n.º 17
0
        new public void Start()
        {
            SparkleHelpers.DebugInfo("Cmd", "git " + StartInfo.Arguments);

            try {
                base.Start();
            } catch (Exception e) {
                SparkleHelpers.DebugInfo("Cmd", "There's a problem running Git: " + e.Message);
                Environment.Exit(-1);
            }
        }
Ejemplo n.º 18
0
        private void StopSSH()
        {
            if (this.ssh_agent_pid == 0)
            {
                return;
            }

            try {
                Process.GetProcessById(this.ssh_agent_pid).Kill();
            } catch (ArgumentException e) {
                SparkleHelpers.DebugInfo("SSH", "Could not stop ssh-agent: " + e.Message);
            }
        }
Ejemplo n.º 19
0
        // Commits the made changes
        private void Commit(string message)
        {
            SparkleGit git = new SparkleGit(LocalPath,
                                            "commit -m \"" + message + "\" " +
                                            "--author=\"" + SparkleConfig.DefaultConfig.User.Name +
                                            " <" + SparkleConfig.DefaultConfig.User.Email + ">\"");

            git.Start();
            git.StandardOutput.ReadToEnd();
            git.WaitForExit();

            SparkleHelpers.DebugInfo("Commit", "[" + Name + "] " + message);
        }
Ejemplo n.º 20
0
        private void WriteUserInfo(string user_name, string user_email)
        {
            string global_config_file_path = Path.Combine(SparklePaths.SparkleConfigPath, "config");

            // Write the user's information to a text file
            TextWriter writer = new StreamWriter(global_config_file_path);

            writer.WriteLine("[user]\n" +
                             "\tname  = " + user_name + "\n" +
                             "\temail = " + user_email);
            writer.Close();

            SparkleHelpers.DebugInfo("Config", "Updated '" + global_config_file_path + "'");
        }
Ejemplo n.º 21
0
        public SparkleInvite(string xml_file_path)
        {
            XmlDocument xml_document = new XmlDocument();
            XmlNode     node;

            string address           = "";
            string remote_path       = "";
            string accept_url        = "";
            string announcements_url = "";
            string fingerprint       = "";

            try {
                xml_document.Load(xml_file_path);

                node = xml_document.SelectSingleNode("/sparkleshare/invite/address/text()");
                if (node != null)
                {
                    address = node.Value;
                }

                node = xml_document.SelectSingleNode("/sparkleshare/invite/remote_path/text()");
                if (node != null)
                {
                    remote_path = node.Value;
                }

                node = xml_document.SelectSingleNode("/sparkleshare/invite/accept_url/text()");
                if (node != null)
                {
                    accept_url = node.Value;
                }

                node = xml_document.SelectSingleNode("/sparkleshare/invite/announcements_url/text()");
                if (node != null)
                {
                    announcements_url = node.Value;
                }

                node = xml_document.SelectSingleNode("/sparkleshare/invite/fingerprint/text()");
                if (node != null)
                {
                    fingerprint = node.Value;
                }

                Initialize(address, remote_path, accept_url, announcements_url, fingerprint);
            } catch (XmlException e) {
                SparkleHelpers.DebugInfo("Invite", "Invalid XML: " + e.Message);
                return;
            }
        }
Ejemplo n.º 22
0
        // Git doesn't track empty directories, so this method
        // fills them all with a hidden empty file.
        //
        // It also prevents git repositories from becoming
        // git submodules by renaming the .git/HEAD file
        private void PrepareDirectories(string path)
        {
            try {
                foreach (string child_path in Directory.GetDirectories(path))
                {
                    if (SparkleHelpers.IsSymlink(child_path))
                    {
                        continue;
                    }

                    if (child_path.EndsWith(".git"))
                    {
                        if (child_path.Equals(Path.Combine(LocalPath, ".git")))
                        {
                            continue;
                        }

                        string HEAD_file_path = Path.Combine(child_path, "HEAD");

                        if (File.Exists(HEAD_file_path))
                        {
                            File.Move(HEAD_file_path, HEAD_file_path + ".backup");
                            SparkleHelpers.DebugInfo("Git", "[" + Name + "] Renamed " + HEAD_file_path);
                        }

                        continue;
                    }

                    PrepareDirectories(child_path);
                }

                if (Directory.GetFiles(path).Length == 0 &&
                    Directory.GetDirectories(path).Length == 0 &&
                    !path.Equals(LocalPath))
                {
                    if (!File.Exists(Path.Combine(path, ".empty")))
                    {
                        try {
                            File.WriteAllText(Path.Combine(path, ".empty"), "I'm a folder!");
                            File.SetAttributes(Path.Combine(path, ".empty"), FileAttributes.Hidden);
                        } catch {
                            SparkleHelpers.DebugInfo("Git", "[" + Name + "] Failed adding empty folder " + path);
                        }
                    }
                }
            } catch (IOException e) {
                SparkleHelpers.DebugInfo("Git", "Failed preparing directory: " + e.Message);
            }
        }
Ejemplo n.º 23
0
        // Generates and installs an RSA keypair to identify this system
        public void GenerateKeyPair()
        {
            string keys_path     = SparklePaths.SparkleKeysPath;
            string key_file_name = "sparkleshare." + UserEmail + ".key";
            string key_file_path = Path.Combine(keys_path, key_file_name);


            if (File.Exists(key_file_path))
            {
                SparkleHelpers.DebugInfo("Config", "Key already exists ('" + key_file_name + "'), " +
                                         "leaving it untouched");
                return;
            }


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

            if (!File.Exists(key_file_name))
            {
                Process process = new Process()
                {
                    EnableRaisingEvents = true
                };

                process.StartInfo.WorkingDirectory       = keys_path;
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.FileName = "ssh-keygen";

                // -t is the crypto type
                // -P is the password (none)
                // -f is the file name to store the private key in
                process.StartInfo.Arguments = "-t rsa -P \"\" -f " + key_file_name;

                process.Start();

                process.Exited += delegate {
                    SparkleHelpers.DebugInfo("Config", "Created private key '" + key_file_name + "'");
                    SparkleHelpers.DebugInfo("Config", "Created public key  '" + key_file_name + ".pub'");

                    File.Copy(key_file_path + ".pub",
                              Path.Combine(SparklePath, UserName + "'s key.txt"));
                };
            }
        }
Ejemplo n.º 24
0
        // Recursively gets a folder's size in bytes
        private double CalculateSizes(DirectoryInfo parent)
        {
            if (!Directory.Exists(parent.FullName))
            {
                return(0);
            }

            if (parent.Name.Equals("rebase-apply"))
            {
                return(0);
            }

            double size = 0;

            try {
                foreach (FileInfo file in parent.GetFiles())
                {
                    if (!file.Exists)
                    {
                        return(0);
                    }

                    if (file.Name.Equals(".empty"))
                    {
                        File.SetAttributes(file.FullName, FileAttributes.Hidden);
                    }

                    size += file.Length;
                }
            } catch (Exception e) {
                SparkleHelpers.DebugInfo("Local", "Error calculating size: " + e.Message);
                return(0);
            }


            try {
                foreach (DirectoryInfo directory in parent.GetDirectories())
                {
                    size += CalculateSizes(directory);
                }
            } catch (Exception e) {
                SparkleHelpers.DebugInfo("Local", "Error calculating size: " + e.Message);
                return(0);
            }

            return(size);
        }
Ejemplo n.º 25
0
        private void StartSSH()
        {
            string auth_sock = Environment.GetEnvironmentVariable("SSH_AUTH_SOCK");

            if (!string.IsNullOrEmpty(auth_sock))
            {
                SparkleHelpers.DebugInfo("Controller", "Using existing ssh-agent with PID=" + this.ssh_agent_pid);
                return;
            }

            Process process = new Process();

            process.StartInfo.FileName               = "ssh-agent";
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.CreateNoWindow         = true;

            process.Start();

            string output = process.StandardOutput.ReadToEnd();

            process.WaitForExit();

            Match auth_sock_match = new Regex(@"SSH_AUTH_SOCK=([^;\n\r]*)").Match(output);
            Match ssh_pid_match   = new Regex(@"SSH_AGENT_PID=([^;\n\r]*)").Match(output);

            if (auth_sock_match.Success)
            {
                Environment.SetEnvironmentVariable("SSH_AUTH_SOCK", auth_sock_match.Groups [1].Value);
            }

            if (ssh_pid_match.Success)
            {
                string ssh_pid = ssh_pid_match.Groups [1].Value;

                Int32.TryParse(ssh_pid, out this.ssh_agent_pid);
                Environment.SetEnvironmentVariable("SSH_AGENT_PID", ssh_pid);

                SparkleHelpers.DebugInfo("Controller", "ssh-agent started, PID=" + ssh_pid);
            }
            else
            {
                SparkleHelpers.DebugInfo("Controller", "ssh-agent started, PID=Unknown");
            }
        }
Ejemplo n.º 26
0
        public override bool CreateSparkleShareFolder()
        {
            if (!Directory.Exists(SparkleConfig.DefaultConfig.FoldersPath))
            {
                Directory.CreateDirectory(SparkleConfig.DefaultConfig.FoldersPath);
                Directory.CreateDirectory(SparkleConfig.DefaultConfig.TmpPath);

                SparkleHelpers.DebugInfo("Config", "Created \"" +
                                         SparkleConfig.DefaultConfig.FoldersPath + "\"");

                // TODO: Set a custom SparkleShare folder icon

                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 27
0
        public void StopFetcher()
        {
            this.fetcher.Stop();

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

            this.fetcher.Dispose();
            this.fetcher = null;
        }
Ejemplo n.º 28
0
        public bool Accept()
        {
            if (string.IsNullOrEmpty(AcceptUrl))
            {
                return(true);
            }

            try {
                WebRequest request = WebRequest.Create(AcceptUrl);

                request.Method      = "POST";
                request.ContentType = "application/x-www-form-urlencoded";
                string  post_data  = "pubkey=" + SparkleConfig.DefaultConfig.User.PublicKey;
                byte [] post_bytes = Encoding.UTF8.GetBytes(post_data);
                request.ContentLength = post_bytes.Length;

                Stream data_stream = request.GetRequestStream();
                data_stream.Write(post_bytes, 0, post_bytes.Length);
                data_stream.Close();

                WebResponse response = request.GetResponse();
                response.Close();


                if ((response as HttpWebResponse).StatusCode == HttpStatusCode.OK)
                {
                    SparkleHelpers.DebugInfo("Invite", "Uploaded public key to " + AcceptUrl);
                    return(true);
                }
                else
                {
                    SparkleHelpers.DebugInfo("Invite", "Failed uploading public key to " + AcceptUrl);
                    return(false);
                }
            } catch (WebException e) {
                SparkleHelpers.DebugInfo("Invite", "Failed uploading public key to " + AcceptUrl + ": " + e.Message);

                return(false);
            }
        }
Ejemplo n.º 29
0
        // The following private methods are
        // delegates used by the previous method

        private void AddPageFetchedDelegate(string remote_url, string [] warnings)
        {
            SyncingFolder = "";

            // Create a local plugin for succesfully added projects, so
            // so the user can easily use the same host again
            if (SelectedPluginIndex == 0)
            {
                SparklePlugin new_plugin;
                Uri           uri = new Uri(remote_url);

                try {
                    string address = remote_url.Replace(uri.AbsolutePath, "");

                    new_plugin = SparklePlugin.Create(
                        uri.Host, address, address, "", "", "/path/to/project");

                    if (new_plugin != null)
                    {
                        Plugins.Insert(1, new_plugin);
                        SparkleHelpers.DebugInfo("Controller", "Added plugin for " + uri.Host);
                    }
                } catch {
                    SparkleHelpers.DebugInfo("Controller", "Failed adding plugin for " + uri.Host);
                }
            }

            if (ChangePageEvent != null)
            {
                ChangePageEvent(PageType.Finished, warnings);
            }

            Program.Controller.FolderFetched    -= AddPageFetchedDelegate;
            Program.Controller.FolderFetchError -= AddPageFetchErrorDelegate;
            Program.Controller.FolderFetching   -= SyncingPageFetchingDelegate;
        }
Ejemplo n.º 30
0
        // Creates the SparkleShare folder in the user's home folder
        public override bool CreateSparkleShareFolder()
        {
            if (!Directory.Exists(SparkleConfig.DefaultConfig.FoldersPath))
            {
                Directory.CreateDirectory(SparkleConfig.DefaultConfig.FoldersPath);
                SparkleHelpers.DebugInfo("Controller", "Created '" + SparkleConfig.DefaultConfig.FoldersPath + "'");

                string gvfs_command_path =
                    new string [] { Path.VolumeSeparatorChar.ToString(),
                                    "usr", "bin", "gvfs-set-attribute" }.Combine();

                // Add a special icon to the SparkleShare folder
                if (File.Exists(gvfs_command_path))
                {
                    Process process = new Process();

                    process.StartInfo.RedirectStandardOutput = true;
                    process.StartInfo.UseShellExecute        = false;
                    process.StartInfo.FileName = "gvfs-set-attribute";

                    // Clear the custom (legacy) icon path
                    process.StartInfo.Arguments = "-t unset " + SparkleConfig.DefaultConfig.FoldersPath + " metadata::custom-icon";
                    process.Start();
                    process.WaitForExit();

                    // Give the SparkleShare folder an icon name, so that it scales
                    process.StartInfo.Arguments = SparkleConfig.DefaultConfig.FoldersPath + " metadata::custom-icon-name 'folder-sparkleshare'";
                    process.Start();
                    process.WaitForExit();
                }

                return(true);
            }

            return(false);
        }