3 using System.Diagnostics;
7 public abstract class ABuilder
15 public abstract bool BuildLibrary(Package pkg, Library lib);
17 public abstract string GetPawnCompilerName();
19 public bool CompilePlugin(Package pkg, Plugin pl)
21 string local_dir = Config.PathFormat("{0}/{1}/addons/sourcemod/scripting", cfg.pkg_path, pkg.GetBaseFolder());
23 string filepath = null;
24 if (pl.Folder != null)
26 filepath = Config.PathFormat("{0}/{1}", pl.Folder, pl.Source);
33 ProcessStartInfo info = new ProcessStartInfo();
34 info.WorkingDirectory = local_dir;
35 info.FileName = Config.PathFormat("{0}/{1}", local_dir, GetPawnCompilerName());
36 info.Arguments = filepath + ".sp";
37 info.UseShellExecute = false;
38 info.RedirectStandardOutput = true;
39 info.RedirectStandardError = true;
41 Process p = Process.Start(info);
42 string output = p.StandardOutput.ReadToEnd() + "\n";
43 output += p.StandardError.ReadToEnd();
47 Console.WriteLine("Debug: wd = " + info.WorkingDirectory + " fn = " + info.FileName + " arg = " + info.Arguments);
48 Console.WriteLine(output);
50 string binary = Config.PathFormat("{0}/{1}/addons/sourcemod/scripting/{2}.smx", cfg.pkg_path, pkg.GetBaseFolder(), pl.Source);
51 if (!File.Exists(binary))
53 Console.WriteLine("Could not find binary: " + binary);
60 new_loc = Config.PathFormat("{0}/{1}/addons/sourcemod/plugins/disabled/{2}.smx", cfg.pkg_path, pkg.GetBaseFolder(), pl.Source);
64 new_loc = Config.PathFormat("{0}/{1}/addons/sourcemod/plugins/{2}.smx", cfg.pkg_path, pkg.GetBaseFolder(), pl.Source);
69 if (File.Exists(new_loc))
73 File.Move(binary, new_loc);
75 catch (System.Exception e)
77 Console.WriteLine(e.Message);
84 public bool CopyFile(Package pkg, string source, string dest)
86 string from = Config.PathFormat("{0}/{1}",
89 string to = Config.PathFormat("{0}/{1}/{2}",
94 File.Copy(from, to, true);
99 /** dest can be null to mean root base folder */
100 public void CopyFolder(Package pkg, string source, string dest, string [] omits)
102 string from_base = Config.PathFormat("{0}/{1}", cfg.source_path, source);
103 string to_base = null;
107 to_base = Config.PathFormat("{0}/{1}",
109 pkg.GetBaseFolder());
113 to_base = Config.PathFormat("{0}/{1}/{2}",
119 string [] files = Directory.GetFiles(from_base);
122 for (int i=0; i<files.Length; i++)
124 file = Path.GetFileName(files[i]);
129 for (int j=0; j<omits.Length; j++)
131 if (file.CompareTo(omits[j]) == 0)
142 dest = Config.PathFormat("{0}/{1}", to_base, file);
143 File.Copy(files[i], dest, true);
147 public void BuildPackage(Package pkg)
149 string path = Config.PathFormat("{0}/{1}", cfg.pkg_path, pkg.GetBaseFolder());
151 if (!Directory.Exists(path))
153 Directory.CreateDirectory(path);
156 /* Create all dirs */
157 string [] paths = pkg.GetFolders();
158 for (int i=0; i<paths.GetLength(0); i++)
160 path = Config.PathFormat("{0}/{1}/{2}", cfg.pkg_path, pkg.GetBaseFolder(), paths[i]);
161 if (!Directory.Exists(path))
163 Directory.CreateDirectory(path);
167 /* Do primitive copies */
168 pkg.OnCopyFolders(this);
169 pkg.OnCopyFiles(this);
172 Library [] libs = pkg.GetLibraries();
173 for (int i=0; i<libs.Length; i++)
175 if (!BuildLibrary(pkg, libs[i]))
177 throw new System.Exception("Failed to compile library: " + libs[i].binary_name);
182 Plugin [] plugins = pkg.GetPlugins();
185 for (int i=0; i<plugins.Length; i++)
187 if (!CompilePlugin(pkg, plugins[i]))
189 throw new System.Exception("Failed to compile plugin: " + plugins[i].Source);