~ubuntu-branches/ubuntu/intrepid/monodevelop/intrepid

« back to all changes in this revision

Viewing changes to Core/src/MonoDevelop.Projects/MonoDevelop.Projects/ProjectConvertTool.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2007-07-16 13:29:54 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20070716132954-pzjpp1tbvotxw30v
Tags: 0.14+dfsg-1ubuntu1
* Sync with Debian, remaining changes:
  + debian/control:
    - Build depend on firefox-dev, depend on firefox.
    - Adjust Maintainer field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
using System;
 
3
using System.IO;
 
4
using MonoDevelop.Core;
 
5
using MonoDevelop.Core.ProgressMonitoring;
 
6
 
 
7
namespace MonoDevelop.Projects
 
8
{
 
9
        class ProjectConvertTool: IApplication
 
10
        {
 
11
                public int Run (string[] arguments)
 
12
                {
 
13
                        if (arguments.Length == 0 || arguments [0] == "--help") {
 
14
                                Console.WriteLine ("");
 
15
                                Console.WriteLine ("Project Export Tool");
 
16
                                Console.WriteLine ("Usage: mdtool project-export <source-project-file> [-d:dest-path] [-f:format-name]");
 
17
                                Console.WriteLine ("");
 
18
                                Console.WriteLine ("Options");
 
19
                                Console.WriteLine (" -d:<dest-path>    Directory where the project will be exported.");
 
20
                                Console.WriteLine (" -f:<format-name>  Format to which export the project or solution.");
 
21
                                Console.WriteLine ("");
 
22
                                return 0;
 
23
                        }
 
24
                        
 
25
                        string projectFile = null;
 
26
                        string destPath = null;
 
27
                        string formatName = null;
 
28
                        
 
29
                        foreach (string s in arguments)
 
30
                        {
 
31
                                if (s.StartsWith ("-d:"))
 
32
                                        destPath = s.Substring (3);
 
33
                                else if (s.StartsWith ("-f:"))
 
34
                                        formatName = s.Substring (3);
 
35
                                else if (projectFile != null) {
 
36
                                        Console.WriteLine ("Only one project can be converted at a time");
 
37
                                        return 1;
 
38
                                }
 
39
                                else
 
40
                                        projectFile = s;
 
41
                        }
 
42
                        
 
43
                        if (projectFile == null) {
 
44
                                Console.WriteLine ("Project or solution file name not provided");
 
45
                                return 1;
 
46
                        }
 
47
                        
 
48
                        projectFile = Runtime.FileService.GetFullPath (projectFile);
 
49
                        if (!File.Exists (projectFile)) {
 
50
                                Console.WriteLine ("File {0} not found.", projectFile);
 
51
                                return 1;
 
52
                        }
 
53
                        
 
54
                        IProgressMonitor monitor = new ConsoleProgressMonitor ();
 
55
                        CombineEntry entry = Services.ProjectService.ReadCombineEntry (projectFile, monitor);
 
56
                        IFileFormat[] formats = Services.ProjectService.FileFormats.GetFileFormatsForObject (entry);
 
57
                        
 
58
                        if (formats.Length == 0) {
 
59
                                Console.WriteLine ("Can't convert file to any format: " + projectFile);
 
60
                                return 1;
 
61
                        }
 
62
                        
 
63
                        IFileFormat format = null;
 
64
                        
 
65
                        if (formatName == null) {
 
66
                                Console.WriteLine ();
 
67
                                Console.WriteLine ("Target formats:");
 
68
                                for (int n=0; n<formats.Length; n++)
 
69
                                        Console.WriteLine ("  {0}. {1}", n + 1, formats [n].Name);
 
70
                                Console.WriteLine ();
 
71
                                
 
72
                                int op = 0;
 
73
                                do {
 
74
                                        Console.Write ("Convert to format: ");
 
75
                                        string s = Console.ReadLine ();
 
76
                                        if (s.Length == 0)
 
77
                                                return 1;
 
78
                                        if (int.TryParse (s, out op)) {
 
79
                                                if (op > 0 && op <= formats.Length)
 
80
                                                        break;
 
81
                                        }
 
82
                                } while (true);
 
83
                                
 
84
                                format = formats [op - 1];
 
85
                        }
 
86
                        else {
 
87
                                foreach (IFileFormat f in formats) {
 
88
                                        if (f.Name == formatName)
 
89
                                                format = f;
 
90
                                }
 
91
                                if (format == null) {
 
92
                                        Console.WriteLine ("Unknown file format: " + formatName);
 
93
                                        return 1;
 
94
                                }
 
95
                        }
 
96
                        
 
97
                        if (destPath == null)
 
98
                                destPath = Path.GetDirectoryName (projectFile);
 
99
                        destPath = Runtime.FileService.GetFullPath (destPath);
 
100
                        
 
101
                        string ofile = Services.ProjectService.Export (monitor, projectFile, destPath, format);
 
102
                        if (ofile != null) {
 
103
                                Console.WriteLine ("Saved file: " + ofile);
 
104
                                return 0;
 
105
                        }
 
106
                        else {
 
107
                                Console.WriteLine ("Project export failed.");
 
108
                                return 1;
 
109
                        }
 
110
                }
 
111
        }
 
112
}