forked from fdorg/flashdevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
163 lines (143 loc) · 6.38 KB
/
Program.cs
File metadata and controls
163 lines (143 loc) · 6.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
using System;
using System.Reflection;
using System.IO;
using ProjectManager.Projects;
using ProjectManager.Building;
using ProjectManager.Building.AS3;
using FDBuild.Building;
using System.Text;
namespace FDBuild
{
/// <summary>
/// FDBuild.exe is a command-line tool for compiling FlashDevelop project files
/// </summary>
public class Program
{
public static FDBuildOptions BuildOptions;
public static int Main(string[] args)
{
try { Console.OutputEncoding = Encoding.Default; }
catch { /* WineMod: not supported */ }
FDBuildOptions options = new FDBuildOptions(args);
BuildOptions = new FDBuildOptions(args);
// save current directory - ProjectBuilder might change it
if (Path.IsPathRooted(options.ProjectFile))
Environment.CurrentDirectory = Path.GetDirectoryName(options.ProjectFile);
string directory = Environment.CurrentDirectory;
string toolsDir = Path.GetDirectoryName(ProjectPaths.ApplicationDirectory);
string firstRunDir = Path.GetDirectoryName(toolsDir);
// try and automagically figure out flashdevelop's library path
// it should be at ..\..\Library
if (options.LibraryDir == null)
try
{
string libraryDir = Path.Combine(firstRunDir, "Library");
if (Directory.Exists(libraryDir))
options.LibraryDir = libraryDir;
}
catch { }
string swfmillPath = options.SwfmillPath ?? Path.Combine(toolsDir, "swfmill");
if (File.Exists(Path.Combine(swfmillPath, "swfmill.exe")))
SwfmillLibraryBuilder.ExecutablePath = Path.Combine(swfmillPath, "swfmill.exe");
else
SwfmillLibraryBuilder.ExecutablePath = "swfmill.exe"; // hope you have it in your environment path!
// figure user settings PlatformData
string platformsFile = Path.Combine("Settings", "Platforms");
if (File.Exists(Path.Combine(firstRunDir, ".local")))
{
PluginCore.PlatformData.Load(Path.Combine(firstRunDir, platformsFile));
}
else
{
string userAppDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string fdDir = Path.Combine(userAppDir, "FlashDevelop");
PluginCore.PlatformData.Load(Path.Combine(fdDir, platformsFile));
}
try
{
if (options.ProjectFile.Length > 0)
Build(Path.GetFullPath(options.ProjectFile), options);
else
{
// build everything in this directory
string[] files = Directory.GetFiles(directory, "*.fdp");
if (files.Length == 0)
{
options.DoHelp();
return 0;
}
foreach (string file in files)
Build(file, options);
}
return 0;
}
catch (BuildException exception)
{
Console.Error.WriteLine(exception.Message);
return 1;
}
catch (Exception exception)
{
Console.Error.WriteLine("Exception: " + exception.Message);
return 1;
}
finally
{
Environment.CurrentDirectory = directory;
if (options.PauseAtEnd)
{
Console.WriteLine();
Console.WriteLine("Press enter to continue...");
Console.ReadLine();
}
}
}
/// <summary>
/// Build from command line
/// </summary>
/// <param name="projectFile"></param>
/// <param name="options"></param>
public static void Build(string projectFile, FDBuildOptions options)
{
Project project = ProjectLoader.Load(projectFile);
project.TraceEnabled = !options.NoTrace;
project.TargetBuild = options.TargetBuild;
project.CurrentSDK = options.CompilerPath;
options.Language = project.Language.ToUpper();
ProjectBuilder builder = ProjectBuilder.Create(project, options.IpcName, options.CompilerPath);
builder.Build(options.ExtraClasspaths, options.NoTrace, options.NoPreBuild, options.NoPostBuild);
}
/// <summary>
/// Build from pre/post command: FDBuild
/// </summary>
/// <param name="projectFile"></param>
public static void BuildProject(string projectFile)
{
Project project = ProjectLoader.Load(projectFile);
Program.BuildOptions.Language = project.Language.ToUpper();
ProjectBuilder builder = ProjectBuilder.Create(project, Program.BuildOptions.IpcName, Program.BuildOptions.CompilerPath);
builder.BuildCommand(Program.BuildOptions.ExtraClasspaths, Program.BuildOptions.NoTrace);
}
/// <summary>
/// Build from pre/post command: mxmlc
/// </summary>
/// <param name="workingdir">the working directory for fsch, to have full optimization make this the same for all calls </param>
/// <param name="arguments">the mxmlc arguments</param>
public static void BuildMXMLC( string workingdir, string arguments )
{
//Project project = ProjectLoader.Load(projectFile);
//Program.BuildOptions.Language = project.Language.ToUpper();
AS3ProjectBuilder builder = new AS3ProjectBuilder(null, Program.BuildOptions.CompilerPath, Program.BuildOptions.IpcName);
builder.CompileWithMxmlc(workingdir, arguments, true);
}
/// <summary>
/// Build from pre/post command: compc
/// </summary>
/// <param name="workingdir">the working directory for fsch, to have full optimization make this the same for all calls </param>
/// <param name="arguments">the compc arguments</param>
public static void BuildCOMPC( string workingdir, string arguments )
{
new AS3ProjectBuilder(null, Program.BuildOptions.CompilerPath, Program.BuildOptions.IpcName);
}
}
}