4
using MonoDevelop.Core;
5
using MonoDevelop.Core.ProgressMonitoring;
7
namespace MonoDevelop.Projects
9
class ProjectConvertTool: IApplication
11
public int Run (string[] arguments)
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 ("");
25
string projectFile = null;
26
string destPath = null;
27
string formatName = null;
29
foreach (string s in arguments)
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");
43
if (projectFile == null) {
44
Console.WriteLine ("Project or solution file name not provided");
48
projectFile = Runtime.FileService.GetFullPath (projectFile);
49
if (!File.Exists (projectFile)) {
50
Console.WriteLine ("File {0} not found.", projectFile);
54
IProgressMonitor monitor = new ConsoleProgressMonitor ();
55
CombineEntry entry = Services.ProjectService.ReadCombineEntry (projectFile, monitor);
56
IFileFormat[] formats = Services.ProjectService.FileFormats.GetFileFormatsForObject (entry);
58
if (formats.Length == 0) {
59
Console.WriteLine ("Can't convert file to any format: " + projectFile);
63
IFileFormat format = null;
65
if (formatName == null) {
67
Console.WriteLine ("Target formats:");
68
for (int n=0; n<formats.Length; n++)
69
Console.WriteLine (" {0}. {1}", n + 1, formats [n].Name);
74
Console.Write ("Convert to format: ");
75
string s = Console.ReadLine ();
78
if (int.TryParse (s, out op)) {
79
if (op > 0 && op <= formats.Length)
84
format = formats [op - 1];
87
foreach (IFileFormat f in formats) {
88
if (f.Name == formatName)
92
Console.WriteLine ("Unknown file format: " + formatName);
98
destPath = Path.GetDirectoryName (projectFile);
99
destPath = Runtime.FileService.GetFullPath (destPath);
101
string ofile = Services.ProjectService.Export (monitor, projectFile, destPath, format);
103
Console.WriteLine ("Saved file: " + ofile);
107
Console.WriteLine ("Project export failed.");