Exemple #1
0
        public void Translate(IDictionary<CarbonFileResult, CarbonFile> files)
        {
            this.targetDirectory = this.config.Current.ProjectRoot.ToDirectory(this.config.Current.TargetDirectory ?? new CarbonDirectory(string.Empty));
            this.targetDirectory.Create();

            var project = new TempProject
                              {
                                  Name = this.config.Current.ProjectName,
                                  TemplateFile = this.config.Current.ProjectTemplate,
                                  FileSourceRoot = this.config.Current.IntermediateSubDirectory.GetPath(),
                                  FileTargetRoot = this.config.Current.TargetSubDirectory.GetPath(),
                                  RootNameSpace = this.config.Current.RootNameSpace
                              };

            IList<Task> tasks = new List<Task>();
            foreach (CarbonFileResult sourceFile in files.Keys)
            {
                CarbonFile targetFile = files[sourceFile];
                if (this.config.Current.ProcessParrallel)
                {
                    CarbonFile closure = sourceFile.Absolute;
                    tasks.Add(Task.Factory.StartNew(() => this.TranslateFile(project, closure, targetFile)));
                }
                else
                {
                    this.TranslateFile(project, sourceFile.Absolute, targetFile);
                }
            }

            Task.WaitAll(tasks.ToArray());

            this.targetDirectory.Create();
            CarbonFile outFile = this.targetDirectory.ToFile(project.Name + this.config.Current.IntermediateProjectExtension);
            JsonExtensions.SaveToFile(outFile, project, false, Formatting.Indented);
        }
        // -------------------------------------------------------------------
        // Constructor
        // -------------------------------------------------------------------
        public AddonContent(CarbonFile file, CarbonDirectory rootDirectory)
        {
            this.File = file;

            this.RootDirectory = rootDirectory;

            this.SubContent = new List<AddonContent>();
        }
        public void Initialize(CarbonDirectory source, CarbonDirectory target)
        {
            this.Source = source;
            this.Target = target;

            this.ScannedEntries = new Dictionary<string, AddonEntry>();
            this.FullContentList = new List<CompileContent>();
        }
Exemple #4
0
        // -------------------------------------------------------------------
        // Constructor
        // -------------------------------------------------------------------
        public Main(IFactory factory)
            : base(factory)
        {
            this.data = factory.Resolve<IMainData>();
            this.simulations = new List<Simulation>();
            this.simulationFiles = new List<CarbonFile>();

            this.dataPath = new CarbonDirectory(string.Empty);
        }
Exemple #5
0
        protected override bool RegisterCommandLineArguments()
        {
            // -I Bridge -I Partials -I Overrides -o ..\..\..\ -t ..\..\..\SMC.template -p ..\..\..\SharpMC.jtlproj
            ICommandLineSwitchDefinition definition = this.Arguments.Define("p", "projectLocation", x => this.projectDirectory = new CarbonDirectory(x));
            definition.Required = true;
            definition.RequireArgument = true;
            definition.Description = "The project location containing " + Constants.ConfigFileName;

            return true;
        }
Exemple #6
0
        public void Save(CarbonDirectory path)
        {
            path.Create();
            CarbonFile target = path.ToFile(FileGeneric);
            JsonExtensions.SaveToFile(target, this.Generic, false, Formatting.Indented);

            foreach (D3Class @class in this.classes)
            {
                CarbonFile classTarget = path.ToFile(@class.Name + ExtensionClass);
                JsonExtensions.SaveToFile(classTarget, @class, false, Formatting.Indented);
            }
        }
Exemple #7
0
        public void Load(CarbonDirectory path)
        {
            if (!path.IsNull && path.Exists)
            {
                if (this.LoadFromPath(path))
                {
                    return;
                }
            }

            Diagnostic.Warning("Could not load data from {0}, using defaults!", path);
            this.LoadFromDefaults();
        }
Exemple #8
0
        protected override bool RegisterCommandLineArguments()
        {
            ICommandLineSwitchDefinition definition = this.Arguments.Define("s", "source", x => this.sourceDirectory = new CarbonDirectory(x));
            definition.RequireArgument = true;
            definition.Required = true;
            definition.Description = "The source directory to compile";

            definition = this.Arguments.Define("t", "target", x => this.targetDirectory = new CarbonDirectory(x));
            definition.RequireArgument = true;
            definition.Required = true;
            definition.Description = "The target directory";

            return true;
        }
Exemple #9
0
        protected override bool RegisterCommandLineArguments()
        {
            ICommandLineSwitchDefinition definition = this.Arguments.Define("v", "version", x => this.version = x);
            definition.RequireArgument = true;
            definition.Required = true;
            definition.Description = "The version of the current Instance";

            definition = this.Arguments.Define("d", "directory", x => this.instanceDirectory = new CarbonDirectory(x));
            definition.RequireArgument = true;
            definition.Description = "The Root directory of the instance (if not current)";

            definition = this.Arguments.Define("m", "mode", x => Enum.TryParse(x, out this.mode));
            definition.RequireArgument = true;
            definition.Description = "mode, default is ClientInstance";

            return true;
        }
Exemple #10
0
        protected override bool RegisterCommandLineArguments()
        {
            ICommandLineSwitchDefinition definition = this.Arguments.Define("d", "dataPath", x => this.dataPath = new CarbonDirectory(x));
            definition.Description = "The path where the data is located";

            definition = this.Arguments.Define("s", "simulationFile", x => this.simulationFiles.Add(new CarbonFile(x)));
            definition.RequireArgument = true;
            definition.AllowMultiple = true;
            definition.Description = "The simulation to run";

            definition = this.Arguments.Define("r", "randomValues", x => this.randomValues = true);
            definition.Description = "Uses a seeded random instead of fixed giving different results every run";

            definition = this.Arguments.Define("t", "saveTable", x => this.saveAsTable = true);
            definition.Description = "Save as table in text format instead of Json report";

            return true;
        }
Exemple #11
0
        protected override bool RegisterCommandLineArguments()
        {
            ICommandLineSwitchDefinition definition = this.Arguments.Define("s", "sourcePath", x => this.sourcePath = new CarbonDirectory(x));
            definition.RequireArgument = true;
            definition.Required = true;
            definition.Description = "The path where the data is located";

            definition = this.Arguments.Define("t", "targetPath", x => this.targetPath = new CarbonDirectory(x));
            definition.RequireArgument = true;
            definition.Required = true;

            definition = this.Arguments.Define("server", x => this.isServerMode = true);
            definition.Description = "Sync as server mode, default is false";

            definition = this.Arguments.Define("force", x => this.forceSync = true);
            definition.Description = "Force the sync even if no indicator is present";

            return true;
        }
Exemple #12
0
        protected override bool RegisterCommandLineArguments()
        {
            ICommandLineSwitchDefinition definition = this.Arguments.Define("d", "directory", x => this.projectDirectory = new CarbonDirectory(x));
            definition.RequireArgument = true;
            definition.Required = true;
            definition.Description = "The directory to run on";

            definition = this.Arguments.Define("c", "configFile", x => this.configFile = new CarbonFile(x));
            definition.RequireArgument = true;
            definition.Description = "Specify a custom MetaFileUtility config";

            definition = this.Arguments.Define("m", "mode", x => CarbonCore.Utils.Edge.EnumExtensions.TryParseInvariant(x, out this.mode));
            definition.RequireArgument = true;
            definition.Description = "Show info about the folder and the environment";

            definition = this.Arguments.Define("p4", x => this.enableP4Check = true);
            definition.Description = "Enable check of meta files against p4";

            return true;
        }
Exemple #13
0
        protected override bool RegisterCommandLineArguments()
        {
            // -I Partials -I Overrides -o ..\..\..\..\Source -p ..\..\..\..\SharpMC.jtlproj
            ICommandLineSwitchDefinition definition = this.Arguments.Define("p", "projectFile", x => this.projectFileName = new CarbonFile(x));
            definition.RequireArgument = true;
            definition.Required = true;
            definition.Description = "The project file to compile";

            definition = this.Arguments.Define("o", "output", x => this.targetDirectory = new CarbonDirectory(x));
            definition.RequireArgument = true;
            definition.Required = true;
            definition.Description = "Target directory for the compilation";

            definition = this.Arguments.Define("I", "include", x => this.includes.Add(new CarbonDirectory(x)));
            definition.RequireArgument = true;
            definition.AllowMultiple = true;
            definition.Description = "Include directories for files to be included in the project file";

            definition = this.Arguments.Define("s", "skipProjectUpdate", x => this.skipProjectUpdate = true);
            definition.Description = "Skip project file re-generation";
            definition.RequireArgument = false;

            return true;
        }
Exemple #14
0
        // -------------------------------------------------------------------
        // Private
        // -------------------------------------------------------------------
        private bool InitializeDirectoryModManager()
        {
            if (this.instanceDirectory == null)
            {
                this.instanceDirectory = RuntimeInfo.WorkingDirectory;
            }

            this.modManager.Initialize(this.instanceDirectory);
            if (this.modManager.Mods.Count <= 0)
            {
                Diagnostic.Warning("No valid mods detected, aborting update check");
                return false;
            }

            return true;
        }
Exemple #15
0
 // -------------------------------------------------------------------
 // Constructor
 // -------------------------------------------------------------------
 public DirectoryFileProvider(CarbonDirectory root)
 {
     this.Root        = root;
     this.openStreams = new List <FileStream>();
 }
Exemple #16
0
        // -------------------------------------------------------------------
        // Protected
        // -------------------------------------------------------------------
        protected override void StartFinished()
        {
            if (this.simulationFiles.Count <= 0)
            {
                this.Arguments.PrintArgumentUse();
                return;
            }

            foreach (CarbonFile file in this.simulationFiles)
            {
                var simulation = JsonExtensions.LoadFromFile<Simulation>(file, false);
                simulation.File = file;
                this.simulations.Add(simulation);
            }

            if (this.dataPath.IsNull)
            {
                this.dataPath = RuntimeInfo.Path.ToDirectory(DefaultDataDirectory);
            }

            if (this.simulations.Count <= 0)
            {
                Simulation defaultSimulation = Defaults.GetDefaultSimulation();
                defaultSimulation.File = RuntimeInfo.Path.ToFile(DefaultSimulationFile + ExtensionSimulation);
                this.simulations.Add(defaultSimulation);
                JsonExtensions.SaveToFile(defaultSimulation.File, defaultSimulation, false, Formatting.Indented);
            }

            this.data.Load(this.dataPath);

            foreach (Simulation simulation in this.simulations)
            {
                SimulationStats results = this.Simulate(simulation);
                if (results == null)
                {
                    continue;
                }

                if (this.saveAsTable)
                {
                    CarbonFile resultFile = simulation.File.ChangeExtension(string.Concat(simulation.File.Extension, ExtensionResult, ExtensionResultTable));
                    using (FileStream stream = resultFile.OpenCreate())
                    {
                        using (var writer = new StreamWriter(stream))
                        {
                            writer.Write(results.ExportAsText());
                        }
                    }

                    resultFile = simulation.File.ChangeExtension(string.Concat(simulation.File.Extension, ExtensionResult, ".Sets", ExtensionResultTable));
                    using (FileStream stream = resultFile.OpenCreate())
                    {
                        using (var writer = new StreamWriter(stream))
                        {
                            writer.Write(results.ExportSetsAsTable());
                        }
                    }
                }
                else
                {
                    CarbonFile resultFile = simulation.File.ChangeExtension(simulation.File.Extension + ExtensionResult);
                    JsonExtensions.SaveToFile(resultFile, results, false, Formatting.Indented);
                }
            }

            this.data.Save(this.dataPath);
        }
Exemple #17
0
        // -------------------------------------------------------------------
        // Private
        // -------------------------------------------------------------------
        private void DoTranslate()
        {
            CarbonDirectory sourceDirectory = this.config.Current.SourceDirectory;
            if (this.config.Current.SourceDirectory.IsRelative)
            {
                sourceDirectory = this.config.Current.ProjectRoot.ToDirectory(sourceDirectory);
            }

            CarbonFileResult[] sources = sourceDirectory.GetFiles(this.config.Current.Filter, SearchOption.AllDirectories);
            System.Diagnostics.Trace.TraceInformation("Found {0} files to translate", sources.Length);

            IDictionary<CarbonFileResult, CarbonFile> files = new Dictionary<CarbonFileResult, CarbonFile>();
            for (int i = 0; i < sources.Length; i++)
            {
                CarbonFileResult source = sources[i];

            #if DEBUG
                /*if (!source.Contains(@"\BaseMetadataSectionSerializer."))
                {
                    continue;
                }*/
                /*if (!source.Contains(@"\Render.") && !source.Contains(@"\RenderEnderman.") && !source.Contains(@"\RendererLivingEntity.") && !source.Contains(@"\RenderLiving."))
                {
                    continue;
                }*/
            #endif

                bool ignore = false;
                foreach (string ignorePattern in MCData.IgnoreList)
                {
                    if (source.Relative.Contains(ignorePattern))
                    {
                        ignore = true;
                        break;
                    }
                }

                if (ignore)
                {
                    continue;
                }

                CarbonFile targetFile = new CarbonFile(source.Relative.FileName).ChangeExtension(CarbonCore.Utils.Constants.ExtensionCSharp);
                var subDirectory = new CarbonDirectory(string.Empty);
                foreach (string pattern in MCData.StructureMapping.Keys)
                {
                    if (source.Relative.StartsWith(pattern))
                    {
                        subDirectory = new CarbonDirectory(MCData.StructureMapping[pattern]);
                        break;
                    }
                }

                targetFile = subDirectory.ToFile(targetFile);
                files.Add(source, targetFile);
            }

            var translation = this.factory.Resolve<ITranslation>();
            translation.Translate(files);

            System.Diagnostics.Trace.TraceInformation(" Report: ");
            System.Diagnostics.Trace.TraceInformation("   Tokens: {0}", translation.TokenCount);
            System.Diagnostics.Trace.TraceInformation("   after Translation: {0}", translation.LinesTranslated);
        }
Exemple #18
0
        // -------------------------------------------------------------------
        // Private
        // -------------------------------------------------------------------
        private void DoCompileProject()
        {
            var project = JsonExtensions.LoadFromFile<TempProject>(this.projectFileName, false);
            if (!string.IsNullOrEmpty(project.Name))
            {
                this.compilerState.BaseNameSpace = project.Name;
            }

            // Set a default target directory if we have none
            if (this.targetDirectory == null || this.targetDirectory.IsNull)
            {
                this.targetDirectory = new CarbonDirectory(this.projectFileName.DirectoryName);
                if (this.targetDirectory == null || this.targetDirectory.IsNull)
                {
                    this.targetDirectory = RuntimeInfo.WorkingDirectory;
                }
            }

            if (this.targetDirectory.IsRelative)
            {
                CarbonDirectory root = RuntimeInfo.WorkingDirectory;
                if (!this.projectFileName.IsRelative)
                {
                    root = this.projectFileName.GetDirectory();
                }

                this.targetDirectory = this.targetDirectory.ToAbsolute<CarbonDirectory>(root);
            }

            // Check if we have a template to generate a project file and are not skipping
            //  if not we will only compile sources
            IProjectFile projectFile = null;
            if (!string.IsNullOrEmpty(project.TemplateFile) && !this.skipProjectUpdate)
            {
                projectFile = new ProjectFile(this.targetDirectory.ToFile(project.TemplateFile));
            }

            // Create jobs for each class in each file
            foreach (TempProjectFileEntry entry in project.Files)
            {
                CompilationJob job = this.CreateJob(project, entry);
                this.jobs.Add(job, 0);
            }

            using (new ProfileRegion("Checking Dependencies"))
            {
                this.RebuildDependencyInfo();
            }

            this.CompileJobs();

            // Update the project file
            if (projectFile != null)
            {
                this.ProcessIncludes();

                CarbonFile targetProjectFile = this.targetDirectory.ToFile(this.projectFileName.FileNameWithoutExtension + ".csproj");
                projectFile.Save(targetProjectFile);
            }
        }
Exemple #19
0
        private static void WriteContentToTarget(CompileContext context)
        {
            StringBuilder contentTocBuilder = new StringBuilder();
            contentTocBuilder.AppendLine("## Interface: 60200");
            contentTocBuilder.AppendLine("## Title: Built");
            contentTocBuilder.AppendLine("## Notes: Built");
            contentTocBuilder.AppendLine("## Author: AddonCompiler");
            contentTocBuilder.AppendLine("## Version: 6.0.001");

            int filesCopied = 0;
            int resourcesCopied = 0;
            foreach (CompileContent content in context.FullContentList)
            {
                CarbonFile targetRelativeFile = new CarbonDirectory(content.Addon.Name).ToFile(content.RelativeFile);
                CarbonFile targetAbsoluteFile = context.Target.ToFile(targetRelativeFile);

                if (content.AbsoluteFile.Extension == Constants.ExtensionXml)
                {
                    if (!WriteXmlContentToTarget(content.AbsoluteFile, targetAbsoluteFile))
                    {
                        continue;
                    }

                    filesCopied++;
                }
                else
                {
                    if (!WriteScriptContentToTarget(content, targetAbsoluteFile))
                    {
                        continue;
                    }

                    filesCopied++;
                }

                // Register the content in the TOC
                contentTocBuilder.AppendLine(targetRelativeFile.GetPath());
            }

            foreach (AddonEntry addon in context.EntriesOrderedByPriority)
            {
                foreach (CarbonFile resource in addon.Resources)
                {
                    CarbonFile targetAbsoluteResourceFile = context.Target.ToDirectory(addon.Name).ToFile(resource);
                    CarbonFile sourceAbsoluteResourceFile = addon.RootDirectory.ToFile(resource);
                    sourceAbsoluteResourceFile.CopyTo(targetAbsoluteResourceFile, true);
                    resourcesCopied++;
                }
            }

            CarbonFile builtTocFile = context.Target.ToFile("Built.toc");
            builtTocFile.WriteAsString(contentTocBuilder.ToString());

            Diagnostic.Info("Finished Compile with {0} content files and {1} resources", filesCopied, resourcesCopied);
        }
Exemple #20
0
 public void Initialize(CarbonDirectory root)
 {
     this.root = root;
     this.Refresh();
 }
Exemple #21
0
 public void Reset()
 {
     this.root = null;
     this.Mods.Clear();
 }
Exemple #22
0
        private bool InitializeInstanceModManager()
        {
            if (this.instanceDirectory == null)
            {
                this.instanceDirectory = RuntimeInfo.WorkingDirectory;
            }

            if (this.instanceDirectory == null || !this.instanceDirectory.Exists)
            {
                Diagnostic.Error("Invalid Directory, no Minecraft Instance detected");
                return false;
            }

            CarbonDirectory modDirectory = this.instanceDirectory.ToDirectory(Constants.ModsDirectory);
            if (!modDirectory.Exists)
            {
                Diagnostic.Warning("No mods directory found, aborting update check");
                return false;
            }

            this.modManager.Initialize(modDirectory);
            if (this.modManager.Mods.Count <= 0)
            {
                Diagnostic.Warning("No valid mods detected, aborting update check");
                return false;
            }

            return true;
        }
Exemple #23
0
        protected override void StartFinished()
        {
            if (this.projectDirectory == null)
            {
                this.Arguments.PrintArgumentUse();
                return;
            }

            if (!this.projectDirectory.Exists)
            {
                Diagnostic.Error("Directory does not exist: {0}", this.projectDirectory);
                return;
            }

            this.config.Load(RuntimeInfo.Path.ToFile(this.configFile));

            this.assetDirectory = this.projectDirectory.ToDirectory(Constants.DirectoryAssets);

            switch (this.mode)
            {
                case MetaUtilityMode.Config:
                    {
                        this.config.Save(this.configFile);
                        Diagnostic.Info("Config Generated as {0}", this.configFile);
                        break;
                    }

                case MetaUtilityMode.Info:
                    {
                        this.PrintInfo();
                        break;
                    }

                case MetaUtilityMode.Check:
                    {
                        this.CheckMetaFiles();
                        break;
                    }

                default:
                case MetaUtilityMode.Help:
                    {
                        this.Arguments.PrintArgumentUse();
                        break;
                    }
            }
        }
Exemple #24
0
        private bool LoadFromPath(CarbonDirectory path)
        {
            this.ClearData();

            this.Generic = JsonExtensions.LoadFromFile<D3Generic>(path.ToFile(FileGeneric), false);

            CarbonFileResult[] files = path.GetFiles("*" + ExtensionClass);
            foreach (CarbonFileResult file in files)
            {
                try
                {
                    var @class = JsonExtensions.LoadFromFile<D3Class>(file.Absolute, false);
                    this.classes.Add(@class);
                }
                catch (Exception e)
                {
                    Diagnostic.Error("Could not load class definition from {0}: {1}", file, e);
                    return false;
                }
            }

            return true;
        }
Exemple #25
0
        private static AddonContent ReadXMLContent(CarbonFile file, CarbonDirectory rootDirectory)
        {
            CarbonFile absoluteFile = rootDirectory.ToFile(file);
            if (!absoluteFile.Exists)
            {
                Diagnostic.Warning("Could not find content file {0}", absoluteFile);
                return null;
            }

            try
            {
                var result = new AddonContent(file, rootDirectory);

                XmlDocument document = AddonXmlUtils.ReadAddonXml(absoluteFile);

                XmlNode root = document.DocumentElement;
                foreach (XmlNode node in root.ChildNodes)
                {
                    if (node.Name.Equals(Constants.XmlNodeScript, StringComparison.OrdinalIgnoreCase))
                    {
                        string nestedContent = node.Attributes[Constants.XmlScriptFileAttribute].Value;
                        CarbonDirectory nestedRoot = file.GetDirectory() == null
                                                             ? rootDirectory
                                                             : rootDirectory.ToDirectory(file.GetDirectory());
                        result.SubContent.Add(new AddonContent(new CarbonFile(nestedContent), nestedRoot));
                        continue;
                    }

                    if (node.Name.Equals(Constants.XmlNodeInclude, StringComparison.OrdinalIgnoreCase))
                    {
                        string nestedContent = node.Attributes[Constants.XmlIncludeFileAttribute].Value;
                        CarbonFile nestedContentFile = new CarbonFile(nestedContent.Trim());
                        if (nestedContentFile.Extension == Constants.ExtensionLua)
                        {
                            CarbonDirectory nestedRoot = file.GetDirectory() == null
                                                             ? rootDirectory
                                                             : rootDirectory.ToDirectory(file.GetDirectory());
                            result.SubContent.Add(new AddonContent(nestedContentFile, nestedRoot));
                            continue;
                        }

                        AddonContent nestedEntry = ReadXMLContent(
                            new CarbonFile(nestedContent),
                            absoluteFile.GetDirectory());
                        if (nestedEntry != null)
                        {
                            result.SubContent.Add(nestedEntry);
                        }
                    }
                }

                return result;
            }
            catch (Exception e)
            {
                Diagnostic.Error("Could not read content XML {0}\n{1}", file, e);
                return null;
            }
        }