private void PackSkinImages(string[] images, string imagesDir, string destination, string tempDir)
        {
            var project = new ContentProject(destination, tempDir);
            project.AddReference("Microsoft.Xna.Framework.Content.Pipeline.TextureImporter, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=MSIL");

            foreach (var file in images)
                project.AddItem(file, "TextureImporter", Path.GetFileName(file), Path.GetFileNameWithoutExtension(file), "TextureProcessor");

            if (!project.Build())
                logger.Error("Error while packing images. See log for details");
        }
        public void Pack(string sourcePath, string destinationPath)
        {
            var isFile = File.Exists(sourcePath);
            var unpackedFiles = isFile ? new[] { sourcePath } : Directory.GetFiles(sourcePath, "*.xnb.js", SearchOption.AllDirectories);
            var tempDir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "Gnomoria.ContentExtractor", Guid.NewGuid().ToString())).FullName;

            foreach (var file in unpackedFiles)
            {
                logger.Info("Creating intermediate file for {0}", Path.GetFileNameWithoutExtension(file));
                var doc = JsonConvert.DeserializeXmlNode(File.ReadAllText(file));
                var assetPath = (isFile ? Path.GetFileName(file) : file.Substring(sourcePath.Length)).Split('.')[0] + ".xml";
                Directory.CreateDirectory(Path.GetDirectoryName(Path.Combine(tempDir, assetPath)));
                doc.Save(Path.Combine(tempDir, assetPath));
            }

            logger.Info("Packing files");
            var filesToBePacked = Directory.GetFiles(tempDir, "*.xml", SearchOption.AllDirectories);
            var libPath = Path.Combine(tempDir, "gnomorialib.dll");
            var preppedLibrary = false;
            
            try
            {
                var startInfo = new ProcessStartInfo()
                {
                    FileName = "lib\\de4dot",
                    Arguments = "gnomorialib.dll -o {0} --keep-names ef".FormatWith(libPath),
                    RedirectStandardOutput = true,
                    CreateNoWindow = true,
                    UseShellExecute = false,
                    WorkingDirectory = "lib"
                };

                using (var process = new Process { StartInfo = startInfo })
                {
                    process.Start();
                    process.StandardOutput.ReadToEnd();

                    preppedLibrary = process.ExitCode == 0;
                }
            }
            catch (Exception e)
            {
                logger.Debug(e);
            }

            if (!preppedLibrary)
            {
                logger.Error("Couldn't prep library");
                Cleanup(tempDir);
                return;
            }

            var project = new ContentProject(destinationPath, tempDir);
            project.AddReference("gnomorialib", libPath);

            foreach (var file in filesToBePacked)
                project.AddItem(file, "XmlImporter", Path.GetFileName(file), Path.GetFileNameWithoutExtension(file));

            if (!project.Build())
                logger.Error("Error while packing data. See log for details");

            Cleanup(tempDir);
        }
예제 #3
0
        public bool Build(string fileName)
        {
            if (prepath != "" && File.Exists(prepath)) File.Move(prepath, prepath + "TEMP");

               string exepath = System.Windows.Forms.Application.StartupPath;
               _project = new ContentProject();

               string ext = Path.GetExtension(fileName).ToLower();
               _project.ProjectOptions.RootDirectory = Path.GetFullPath(fileName).Replace(Path.GetFileName(fileName), "");
               switch (ext)
               {
            case ".bmp":
            case ".jpg":
            case ".jpeg":
            case ".tga":
            case ".dds":

             _project.ProjectOptions.OutputDirectory = _project.ProjectOptions.RootDirectory;
             _project.ProjectOptions.IntermediateDirectory = _project.ProjectOptions.RootDirectory;

             break;
            case ".lua":

             _project.ProjectOptions.OutputDirectory = _project.ProjectOptions.RootDirectory;
             _project.ProjectOptions.IntermediateDirectory = _project.ProjectOptions.RootDirectory;

             break;
               }

               _project.InitContentFile(fileName);
               bool ret = _project.Build(false);
               if (ret == false) return false;

               if (prepath != "" && File.Exists(prepath + "TEMP")) File.Move(prepath + "TEMP", prepath);
               prepath = _project.ProjectOptions.OutputDirectory + "\\" +Path.GetFileNameWithoutExtension(fileName) + ".xnb";

               switch(ext)
               {
            case ".lua":
            string outlilfile = _project.ProjectOptions.OutputDirectory + Path.GetFileNameWithoutExtension(fileName) + ".lil";
            string outpdbfile = _project.ProjectOptions.OutputDirectory + Path.GetFileNameWithoutExtension(fileName) + ".pdb";
            string outxnbfile = _project.ProjectOptions.OutputDirectory + Path.GetFileNameWithoutExtension(fileName) + ".xnb";
            string contPipeli = _project.ProjectOptions.OutputDirectory + "ContentPipeline.xml";
            File.Delete(contPipeli);

            if (Path.GetDirectoryName(fileName) != (exepath + "\\scripts"))
            {
             File.Copy(fileName, exepath + "\\scripts\\" + Path.GetFileNameWithoutExtension(fileName) + ".lua");
             File.Delete(fileName);
            }

            string xnbfile = exepath + "\\Content\\scripts\\" + Path.GetFileNameWithoutExtension(fileName) + ".xnb";
            File.Delete(xnbfile);
            File.Move(outxnbfile, xnbfile);

            string lilfile = exepath + "\\Content\\" + Path.GetFileNameWithoutExtension(fileName) + ".lil";
            File.Delete(lilfile);
            File.Move(outlilfile, lilfile);

            string pdbfile = exepath + "\\Content\\" + Path.GetFileNameWithoutExtension(fileName) + ".pdb";
            File.Delete(pdbfile);
            File.Move(outpdbfile, pdbfile);

            break;

            case ".bmp":
            case ".jpg":
            case ".jpeg":
            case ".tga":
            case ".dds":
            //

            string outfile = _project.ProjectOptions.OutputDirectory + Path.GetFileNameWithoutExtension(fileName) + ".xnb";
            contPipeli = _project.ProjectOptions.OutputDirectory + "ContentPipeline.xml";
            File.Delete(contPipeli);

            string file = exepath + "\\Content\\textures\\" + Path.GetFileNameWithoutExtension(fileName) + ".xnb";
            File.Delete(file);
            File.Move(outfile, file);

            break;
               }

               return ret;
        }