~cszikszoy/do-plugins/fix-confluence

« back to all changes in this revision

Viewing changes to Dropbox/src/Dropbox.cs

  • Committer: Chris S.
  • Date: 2009-06-10 17:32:56 UTC
  • mfrom: (599.3.32 Dropbox)
  • Revision ID: chris@szikszoy.com-20090610173256-ndhy3yztbqjc4zs0
merge Dropbox plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// Dropbox.cs
 
3
// 
 
4
// GNOME Do is the legal property of its developers. Please refer to the
 
5
// COPYRIGHT file distributed with this
 
6
// source distribution.
 
7
// 
 
8
// This program is free software: you can redistribute it and/or modify
 
9
// it under the terms of the GNU General Public License as published by
 
10
// the Free Software Foundation, either version 3 of the License, or
 
11
// (at your option) any later version.
 
12
// 
 
13
// This program is distributed in the hope that it will be useful,
 
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
// GNU General Public License for more details.
 
17
// 
 
18
// You should have received a copy of the GNU General Public License
 
19
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
// 
 
21
 
 
22
using System;
 
23
using System.IO;
 
24
using System.Diagnostics;
 
25
 
 
26
using Do.Platform;
 
27
 
 
28
namespace Dropbox
 
29
{
 
30
        
 
31
        
 
32
        public class Dropbox
 
33
        {
 
34
                public static string BasePath;
 
35
                public static string PublicPath;
 
36
                public static string DoSharedPath;
 
37
                
 
38
                private static string cli_path = "/usr/bin/dropbox";
 
39
                private static string db_url = "https://www.getdropbox.com/";
 
40
                
 
41
                static Dropbox ()
 
42
                {
 
43
                        BasePath = DropboxConfig.BasePath;
 
44
                        PublicPath = Path.Combine (BasePath, "Public");
 
45
                        DoSharedPath = Path.Combine (PublicPath, "Do Shared Files");
 
46
                }
 
47
                
 
48
                public static bool IsRunning {
 
49
                        get {
 
50
                                return !Exec ("status").StartsWith ("Dropbox isn't running!");
 
51
                        }
 
52
                }
 
53
                
 
54
                public static bool HasCli {
 
55
                        get {
 
56
                                return File.Exists (cli_path);
 
57
                        }
 
58
                }
 
59
                
 
60
                public static void Start ()
 
61
                {
 
62
                        Exec ("start -i");
 
63
                }
 
64
                
 
65
                public static void Stop ()
 
66
                {
 
67
                        Exec ("stop");
 
68
                }
 
69
                
 
70
                public static string GetPubUrl (string path)
 
71
                {
 
72
                        string url = Exec (String.Format ("puburl \"{0}\"", path));
 
73
                        if (!url.StartsWith ("http")) { url = null; }
 
74
                        
 
75
                        return url;
 
76
                }
 
77
                
 
78
                public static string GetWebUrl ()
 
79
                {
 
80
                        return db_url + "home#";
 
81
                }
 
82
                
 
83
                public static string GetWebUrl (string path)
 
84
                {
 
85
                        return GetWebUrl () + path.Substring (BasePath.Length);
 
86
                }
 
87
                
 
88
                public static string GetRevisionsUrl (string path)
 
89
                {
 
90
                        return db_url + "revisions" + path.Substring (BasePath.Length);
 
91
                }
 
92
                
 
93
                private static string Exec (string args) 
 
94
                {
 
95
                        string stdout = "";
 
96
                        
 
97
                        try {
 
98
                                ProcessStartInfo cmd = new ProcessStartInfo ();
 
99
                                cmd.FileName = cli_path;
 
100
                                cmd.Arguments = args; 
 
101
                                cmd.UseShellExecute = false;
 
102
                                cmd.RedirectStandardOutput = true;
 
103
                                
 
104
                                Process run = Process.Start (cmd);
 
105
                                run.WaitForExit ();
 
106
                                
 
107
                                stdout = run.StandardOutput.ReadLine ();
 
108
                                
 
109
                        } catch (Exception e) {
 
110
                                Log<Dropbox>.Error ("Error running dropbox {0}: {1}", args, e.Message);
 
111
                                Log<Dropbox>.Debug (e.StackTrace);
 
112
                        }
 
113
                        
 
114
                        return stdout;
 
115
                }
 
116
                        
 
117
        }
 
118
}