private AddContentResource ( string v ) : void | ||
v | string | |
Результат | void |
public static int Main (string [] args) { MXap mxap = new MXap (); bool help = false; bool clean = false; List<string> resources = new List<string>(); List<string> aresources = new List<string>(); List<string> cresources = new List<string>(); string resourceFile = null; string aresourceFile = null; string cresourceFile = null; mxap.Cd = Directory.GetCurrentDirectory (); var p = new OptionSet () { { "h|?|help", v => help = v != null }, { "generate-html:", v => mxap.GenerateHtml = ParseBool (v, mxap.GenerateHtml) }, { "include-mdb:", v => mxap.IncludeMdb = ParseBool (v, mxap.IncludeMdb) }, { "application-name=", v => mxap.ApplicationName = v }, { "generate-manifest:", v => mxap.GenerateManifest = ParseBool (v, mxap.GenerateManifest) }, { "use-existing-manifest", v => mxap.GenerateManifest = v == null }, { "entry-point-type=", v => mxap.EntryPointType = v }, { "cs-sources=", v => mxap.CSSources = v }, { "res-sources=", v => resourceFile = v }, { "ares-sources=", v => aresourceFile = v }, { "cres-sources=", v => cresourceFile = v }, { "desktop:", v => mxap.Desktop = ParseBool (v, mxap.Desktop) }, { "builddirhack=", v => mxap.TopBuildDir = v }, { "r=|reference=", v => mxap.ExternalAssemblies.Add (v) }, { "pkg=", "Use assemblies listed in .pc files to build. They won't be included in the xap, so this is only useful for extra system libraries.", v => mxap.Packages.Add (v) }, { "l:|list-generated:", v => mxap.ListGenerated = ParseBool (v, mxap.ListGenerated) }, { "v:|verbose:", v => mxap.Verbose = ParseBool (v, mxap.Verbose) }, { "res=|resource=", "-res=filename[,resource name]", v => resources.Add (v) }, { "ares=|assembly-resource=", "-ares=filename[,resource name]", v => aresources.Add (v) }, { "cres=|content-resource=", "-cres=filename[,resource name]", v => cresources.Add (v) }, { "d:|define:", "-d:name", v => mxap.Defines.Add (v) }, { "clean", "Removes generated files. Use with caution!", v => clean = v != null }, { "out=|output-dir=", v => mxap.OutputDir = v }, { "inplace:", "Don't use a temporary directory", v => mxap.InPlace = ParseBool (v, mxap.InPlace) }, { "runtime-version=|rv=", String.Format ("Select the Silverlight Runtime Version (2 = {0}, 3 = {1} 4 = {2}, or use the full version string)", RuntimeVersion2, RuntimeVersion3, RuntimeVersion4), v => mxap.SetRuntimeVersion (v) }, { "warnaserror", "Treats all warnings as errors", v => mxap.WarnAsErrorArg = v != null ? "-warnaserror+" : null } }; List<string> extra = null; try { extra = p.Parse(args); } catch (OptionException){ Console.WriteLine ("Try `mxap --help' for more information."); return 1; } if (help){ ShowHelp (p); return 0; } if (clean) { DoClean (mxap.ApplicationName); return 0; } if (extra.Count > 0) mxap.Cd = Path.GetFullPath (extra [0]); if (mxap.TopBuildDir == null && mxap.ExternalAssemblies.Count > 0) { Console.Error.WriteLine ("--reference requires --builddirhack"); return 1; } if (mxap.OutputDir == null) mxap.OutputDir = mxap.Cd; else mxap.OutputDir = Path.GetFullPath (mxap.OutputDir); Directory.SetCurrentDirectory (mxap.Cd); mxap.WorkingDir = mxap.Cd; if (mxap.Verbose) Console.WriteLine ("Using source directory " + mxap.WorkingDir); if (!mxap.InPlace) { mxap.TmpDir = Path.Combine (Path.GetTempPath(), Path.GetRandomFileName ()); if (mxap.Verbose) Console.WriteLine ("Using temporary directory " + mxap.TmpDir); Directory.CreateDirectory (mxap.TmpDir); RecursiveCopy (mxap.WorkingDir, "", mxap.TmpDir); } if (resourceFile != null) foreach (string res in File.ReadAllLines (resourceFile)) mxap.AddResource (res); if (aresourceFile != null) foreach (string res in File.ReadAllLines (aresourceFile)) mxap.AddAssemblyResource (res); if (cresourceFile != null) foreach (string res in File.ReadAllLines (cresourceFile)) mxap.AddContentResource (res); foreach (string res in resources) { mxap.AddResource (res); } foreach (string res in aresources) { mxap.AddAssemblyResource (res); } foreach (string res in cresources) { mxap.AddContentResource (res); } if (!mxap.InPlace) { Directory.SetCurrentDirectory (mxap.TmpDir); mxap.WorkingDir = mxap.TmpDir; } foreach (string pkg in mxap.Packages) { string ret; mxap.RunProcess ("pkg-config", "--libs " + pkg, out ret); if (ret != null) { string [] libs = ret.Trim (new Char [] {' ', '\n', '\r', '\t'}).Replace("-r:", "").Split (new Char [] { ' ', '\t'}); mxap.PackageAssemblies.AddRange (libs); } } mxap.ReferenceAssemblies.AddRange (Directory.GetFiles (mxap.WorkingDir, "*.dll")); mxap.XamlFiles.AddRange (Directory.GetFiles (mxap.WorkingDir, "*.xaml")); mxap.ExternalPartManifests.AddRange (Directory.GetFiles (mxap.WorkingDir, "*.extmap.xml")); if (mxap.CSSources == null) { mxap.CSharpFiles.AddRange (Directory.GetFiles (mxap.WorkingDir, "*.cs")); } else { mxap.CSharpFiles.AddRange (File.ReadAllLines (mxap.CSSources)); } if (mxap.IncludeMdb) mxap.MdbFiles.AddRange (Directory.GetFiles (mxap.WorkingDir, "*.mdb")); if (mxap.XamlFiles.Count == 0 || mxap.CSharpFiles.Count == 0) { Console.Error.WriteLine ("No XAML files or C# files found"); ShowHelp (p); return 1; } // Make sure we didn't add the Application assembly into the referenced assemblies DirectoryInfo info = new DirectoryInfo (mxap.WorkingDir); if (mxap.ReferenceAssemblies.Contains (Path.Combine (mxap.WorkingDir, info.Name + ".dll"))) mxap.ReferenceAssemblies.Remove (Path.Combine (mxap.WorkingDir, info.Name + ".dll")); if (!mxap.Run ()) return 1; if (mxap.Verbose) Console.WriteLine ("Using Output directory " + mxap.OutputDir); if (!Directory.Exists (mxap.OutputDir)) { Console.WriteLine ("warning: output directory doesn't exist, defaulting to source directory " + mxap.Cd + " ..."); mxap.OutputDir = mxap.Cd; } if (!mxap.InPlace || mxap.Cd != mxap.OutputDir) { string app = mxap.ApplicationName; File.Copy (Path.Combine (mxap.WorkingDir, app + ".dll"), Path.Combine (mxap.OutputDir, app + ".dll"), true); File.Copy (Path.Combine (mxap.WorkingDir, app + ".dll.mdb"), Path.Combine (mxap.OutputDir, app + ".dll.mdb"), true); File.Copy (Path.Combine (mxap.WorkingDir, app + ".g.resources"), Path.Combine (mxap.OutputDir, app + ".g.resources"), true); File.Copy (Path.Combine (mxap.WorkingDir, app + ".html"), Path.Combine (mxap.OutputDir, app + ".html"), true); File.Copy (Path.Combine (mxap.WorkingDir, app + ".xap"), Path.Combine (mxap.OutputDir, app + ".xap"), true); File.Copy (Path.Combine (mxap.WorkingDir, "AppManifest.xaml"), Path.Combine (mxap.OutputDir, "AppManifest.xaml"), true); foreach (string file in Directory.GetFiles (mxap.WorkingDir, "*.g.cs")) File.Copy (file, Path.Combine (mxap.OutputDir, Path.GetFileName (file)), true); if (!mxap.InPlace) Directory.Delete (mxap.TmpDir, true); } return 0; }
public static int Main(string [] args) { MXap mxap = new MXap(); bool help = false; bool clean = false; List <string> resources = new List <string>(); List <string> aresources = new List <string>(); List <string> cresources = new List <string>(); string resourceFile = null; string aresourceFile = null; string cresourceFile = null; mxap.Cd = Directory.GetCurrentDirectory(); var p = new OptionSet() { { "h|?|help", v => help = v != null }, { "generate-html:", v => mxap.GenerateHtml = ParseBool(v, mxap.GenerateHtml) }, { "include-mdb:", v => mxap.IncludeMdb = ParseBool(v, mxap.IncludeMdb) }, { "application-name=", v => mxap.ApplicationName = v }, { "generate-manifest:", v => mxap.GenerateManifest = ParseBool(v, mxap.GenerateManifest) }, { "use-existing-manifest", v => mxap.GenerateManifest = v == null }, { "entry-point-type=", v => mxap.EntryPointType = v }, { "cs-sources=", v => mxap.CSSources = v }, { "res-sources=", v => resourceFile = v }, { "ares-sources=", v => aresourceFile = v }, { "cres-sources=", v => cresourceFile = v }, { "desktop:", v => mxap.Desktop = ParseBool(v, mxap.Desktop) }, { "builddirhack=", v => mxap.TopBuildDir = v }, { "r=|reference=", v => mxap.ExternalAssemblies.Add(v) }, { "pkg=", "Use assemblies listed in .pc files to build. They won't be included in the xap, so this is only useful for extra system libraries.", v => mxap.Packages.Add(v) }, { "l:|list-generated:", v => mxap.ListGenerated = ParseBool(v, mxap.ListGenerated) }, { "v:|verbose:", v => mxap.Verbose = ParseBool(v, mxap.Verbose) }, { "res=|resource=", "-res=filename[,resource name]", v => resources.Add(v) }, { "ares=|assembly-resource=", "-ares=filename[,resource name]", v => aresources.Add(v) }, { "cres=|content-resource=", "-cres=filename[,resource name]", v => cresources.Add(v) }, { "d:|define:", "-d:name", v => mxap.Defines.Add(v) }, { "clean", "Removes generated files. Use with caution!", v => clean = v != null }, { "out=|output-dir=", v => mxap.OutputDir = v }, { "inplace:", "Don't use a temporary directory", v => mxap.InPlace = ParseBool(v, mxap.InPlace) }, { "runtime-version=|rv=", String.Format("Select the Silverlight Runtime Version (2 = {0}, 3 = {1} 4 = {2}, or use the full version string)", RuntimeVersion2, RuntimeVersion3, RuntimeVersion4), v => mxap.SetRuntimeVersion(v) }, { "prefix=", "Prefix to use to set libpath", v => mxap.Prefix = v }, { "warnaserror", "Treats all warnings as errors", v => mxap.WarnAsErrorArg = v != null ? "-warnaserror+" : null } }; List <string> extra = null; try { extra = p.Parse(args); } catch (OptionException) { Console.WriteLine("Try `mxap --help' for more information."); return(1); } if (help) { ShowHelp(p); return(0); } if (clean) { DoClean(mxap.ApplicationName); return(0); } if (extra.Count > 0) { mxap.Cd = Path.GetFullPath(extra [0]); } if (mxap.OutputDir == null) { mxap.OutputDir = mxap.Cd; } else { mxap.OutputDir = Path.GetFullPath(mxap.OutputDir); } Directory.SetCurrentDirectory(mxap.Cd); mxap.WorkingDir = mxap.Cd; if (mxap.Verbose) { Console.WriteLine("Using source directory " + mxap.WorkingDir); } if (!mxap.InPlace) { mxap.TmpDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); if (mxap.Verbose) { Console.WriteLine("Using temporary directory " + mxap.TmpDir); } Directory.CreateDirectory(mxap.TmpDir); RecursiveCopy(mxap.WorkingDir, "", mxap.TmpDir); } if (resourceFile != null) { foreach (string res in File.ReadAllLines(resourceFile)) { mxap.AddResource(res); } } if (aresourceFile != null) { foreach (string res in File.ReadAllLines(aresourceFile)) { mxap.AddAssemblyResource(res); } } if (cresourceFile != null) { foreach (string res in File.ReadAllLines(cresourceFile)) { mxap.AddContentResource(res); } } foreach (string res in resources) { mxap.AddResource(res); } foreach (string res in aresources) { mxap.AddAssemblyResource(res); } foreach (string res in cresources) { mxap.AddContentResource(res); } if (!mxap.InPlace) { Directory.SetCurrentDirectory(mxap.TmpDir); mxap.WorkingDir = mxap.TmpDir; } foreach (string pkg in mxap.Packages) { string ret; mxap.RunProcess("pkg-config", "--libs " + pkg, out ret); if (ret != null) { string [] libs = ret.Trim(new Char [] { ' ', '\n', '\r', '\t' }).Replace("-r:", "").Split(new Char [] { ' ', '\t' }); mxap.PackageAssemblies.AddRange(libs); } } mxap.ReferenceAssemblies.AddRange(Directory.GetFiles(mxap.WorkingDir, "*.dll")); mxap.XamlFiles.AddRange(Directory.GetFiles(mxap.WorkingDir, "*.xaml")); mxap.ExternalPartManifests.AddRange(Directory.GetFiles(mxap.WorkingDir, "*.extmap.xml")); if (mxap.CSSources == null) { mxap.CSharpFiles.AddRange(Directory.GetFiles(mxap.WorkingDir, "*.cs")); } else { mxap.CSharpFiles.AddRange(File.ReadAllLines(mxap.CSSources)); } if (mxap.IncludeMdb) { mxap.MdbFiles.AddRange(Directory.GetFiles(mxap.WorkingDir, "*.mdb")); } if (mxap.XamlFiles.Count == 0 || mxap.CSharpFiles.Count == 0) { Console.Error.WriteLine("No XAML files or C# files found"); ShowHelp(p); return(1); } // Make sure we didn't add the Application assembly into the referenced assemblies DirectoryInfo info = new DirectoryInfo(mxap.WorkingDir); if (mxap.ReferenceAssemblies.Contains(Path.Combine(mxap.WorkingDir, info.Name + ".dll"))) { mxap.ReferenceAssemblies.Remove(Path.Combine(mxap.WorkingDir, info.Name + ".dll")); } if (!mxap.Run()) { return(1); } if (mxap.Verbose) { Console.WriteLine("Using Output directory " + mxap.OutputDir); } if (!Directory.Exists(mxap.OutputDir)) { Console.WriteLine("warning: output directory doesn't exist, defaulting to source directory " + mxap.Cd + " ..."); mxap.OutputDir = mxap.Cd; } if (!mxap.InPlace || mxap.Cd != mxap.OutputDir) { string app = mxap.ApplicationName; File.Copy(Path.Combine(mxap.WorkingDir, app + ".dll"), Path.Combine(mxap.OutputDir, app + ".dll"), true); File.Copy(Path.Combine(mxap.WorkingDir, app + ".dll.mdb"), Path.Combine(mxap.OutputDir, app + ".dll.mdb"), true); File.Copy(Path.Combine(mxap.WorkingDir, app + ".g.resources"), Path.Combine(mxap.OutputDir, app + ".g.resources"), true); File.Copy(Path.Combine(mxap.WorkingDir, app + ".html"), Path.Combine(mxap.OutputDir, app + ".html"), true); File.Copy(Path.Combine(mxap.WorkingDir, app + ".xap"), Path.Combine(mxap.OutputDir, app + ".xap"), true); File.Copy(Path.Combine(mxap.WorkingDir, "AppManifest.xaml"), Path.Combine(mxap.OutputDir, "AppManifest.xaml"), true); foreach (string file in Directory.GetFiles(mxap.WorkingDir, "*.g.cs")) { File.Copy(file, Path.Combine(mxap.OutputDir, Path.GetFileName(file)), true); } if (!mxap.InPlace) { Directory.Delete(mxap.TmpDir, true); } } return(0); }