/// <summary>
        /// Exports behaviours from the export dialogue. Internal use only.
        /// </summary>
        /// <param name="pool">The pool of tree nodes whose behaviours you want to export.</param>
        /// <param name="folder">The folder the behaviours are exported to.</param>
        /// <param name="exportNoGroups">Defines if the groups are exported as well.</param>
        /// <param name="exporter">The exporter which is used.</param>
        private void ExportBehavior(TreeNodeCollection pool, string folder, bool exportNoGroups, ExporterInfo exporter)
        {
            Exporters.Exporter exp= null;
            bool firstRun= true;

            // export the behaviour for each tree node
            foreach(TreeNode tnode in pool)
            {
                // reset any previously loaded behaviour
                FileManagers.FileManager.ResetLoadedBehavior();

                NodeTag nodetag= (NodeTag) tnode.Tag;

                // if the tree node is selected and a behaviour
                if(nodetag.Type ==NodeTagType.Behavior && tnode.Checked)
                {
                    // get or load the behaviour we want to export
                    BehaviorNode node= GetBehavior(nodetag, tnode.Text);
                    if(node ==null)
                        node= LoadBehavior(nodetag.Filename);

                    // generate the new filename and the exporter
                    exp= exporter.Create(node, folder, exportNoGroups ? tnode.Text : tnode.FullPath);

                    // if we are exporting the first time run PreExport()
                    if(firstRun)
                    {
                        firstRun= false;

                        if(!exp.PreExport(false))
                            return;
                    }

                    // export behaviour
                    exp.Export();
                }

                // export the child tree nodes
                ExportBehavior(tnode.Nodes, folder, exportNoGroups, exporter);
            }

            // when we finishes exporting we call the PostExport() method
            if(exp !=null)
                exp.PostExport(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initialise the exporter.
        /// </summary>
        /// <param name="args">Command-line arguments.</param>
        static void Main(string[] args)
        {
            // display the application name and version
            Version version = Assembly.GetExecutingAssembly().GetName().Version;

            string title = "Brainiac Exporter";

            title += " " + version.Major + "." + version.Minor;

            if (version.Build != 0)
            {
                title += (char)(version.Build + 0x60);
            }

            if (version.Revision != 0)
            {
                title += string.Format(" ({0})", version.Revision);
            }

            LogMessage(title);
            LogMessage("\r\nUsage:\r\n  export -exporter exporterid -input files & folders -output output_dir [-nosubfolders] [-pause]");

            // assign our behaviour manager
            BehaviorManager.Instance = _behaviorManager;

            try
            {
                // load the plugins
                LoadPlugins("plugins");

                // evaluate all the arguments
                List <FileToExport> files  = new List <FileToExport>();
                string outputFolder        = string.Empty;
                bool   exportIntoOneFolder = false;
                string exporterid          = string.Empty;
                bool   pause = false;

                int i = 0;
                while (i < args.Length)
                {
                    if (args[i] == "-nosubfolders")
                    {
                        exportIntoOneFolder = true;
                        i++;
                    }
                    else if (args[i] == "-output")
                    {
                        if (i == args.Length - 1)
                        {
                            throw new Exception("-output cannot be the last argument");
                        }

                        outputFolder = args[i + 1];
                        i           += 2;
                    }
                    else if (args[i] == "-input")
                    {
                        if (i == args.Length - 1)
                        {
                            throw new Exception("-output cannot be the last argument");
                        }

                        // as long as we do not find another argument, keep adding files and folders
                        while (++i < args.Length)
                        {
                            if (args[i].StartsWith("-"))
                            {
                                break;
                            }

                            string obj = args[i];
                            if (Directory.Exists(obj))
                            {
                                // add the files from the given folder
                                IList <string> foundFiles, foundFolders;
                                FileManagers.FileManager.CollectBehaviors(_fileManagers, obj, out foundFiles, out foundFolders);
                                for (int f = 0; f < foundFiles.Count; ++f)
                                {
                                    files.Add(new FileToExport(obj, foundFiles[f]));
                                }
                            }
                            else if (File.Exists(obj))
                            {
                                // add the given file
                                files.Add(new FileToExport(obj));
                            }
                            else
                            {
                                throw new Exception(string.Format("Invalid file/folder found: {0}", obj));
                            }
                        }
                    }
                    else if (args[i] == "-exporter")
                    {
                        if (i == args.Length - 1)
                        {
                            throw new Exception("-exporter cannot be the last argument");
                        }

                        exporterid = args[i + 1];
                        i         += 2;
                    }
                    else if (args[i] == "-pause")
                    {
                        pause = true;
                        i++;
                    }
                    else
                    {
                        throw new Exception("Invalid argument found: " + args[i]);
                    }
                }

                // validate the read arguments
                if (files.Count < 1)
                {
                    throw new Exception("No files to export");
                }

                if (outputFolder == String.Empty)
                {
                    throw new Exception("No output folder set");
                }

                if (!Directory.Exists(outputFolder))
                {
                    throw new Exception("Output folder does not exist " + outputFolder);
                }

                if (exporterid == string.Empty)
                {
                    throw new Exception("No exporterinfo given");
                }

                // check if the stated exporter could be found in one of the plugins
                ExporterInfo exporterinfo = null;
                foreach (ExporterInfo ei in _exporters)
                {
                    if (ei.ID.Equals(exporterid, StringComparison.OrdinalIgnoreCase))
                    {
                        exporterinfo = ei;
                        break;
                    }
                }

                if (exporterinfo == null)
                {
                    throw new Exception(string.Format("No such exporterinfo: {0}", exporterid));
                }

                LogMessage("Exporting to: \"" + outputFolder + '"');

                // export the behaviours
                ExportBehaviors(exporterinfo, files, outputFolder, exportIntoOneFolder);

                // wait if the user asked for it
                if (pause)
                {
                    LogMessage("\r\nPress a key to continue");
                    Console.ReadKey();
                }
            }
            catch (Exception e) { LogError(e.Message); }
        }
Exemplo n.º 3
0
		/// <summary>
		/// Exports the found behaviour files.
		/// </summary>
		/// <param name="exporterinfo">The exporter info of the exporter we want to use.</param>
		/// <param name="files">The behaviour files.</param>
		/// <param name="outputFolder">The folder the behaviours will be exported into.</param>
		/// <param name="exportIntoOneFolder">Defines if we export all behaviours into the output folder directly or if we create any sub folders found.</param>
		private static void ExportBehaviors(ExporterInfo exporterinfo, List<FileToExport> files, string outputFolder, bool exportIntoOneFolder)
		{
			Exporter exporter= null;

			for(int i= 0; i <files.Count; ++i)
			{
				FileToExport file= files[i];

				LogMessage( string.Format("Exporting \"{0}\"...",file.File) );

				// reset previously loaded behavior
				FileManagers.FileManager.ResetLoadedBehavior();

				// load the behaviour file
				BehaviorNode behavior= _behaviorManager.LoadBehavior(file.File);
				if(behavior ==null)
					throw new Exception( string.Format("Could not load behavior {0}", file.File) );

				// check if the file we exported comes from a folder or a given file
				string relativefile;
				if(file.BaseFolder ==string.Empty || exportIntoOneFolder)
				{
					// simply use the filename as it is
					relativefile= Path.GetFileName(file.File);
				}
				else
				{
					// create a relative filename of the behaviour to the folder it comes from
					Uri root= new Uri( Path.GetFullPath(file.BaseFolder) +'\\');
					Uri thefile= new Uri( Path.GetFullPath(file.File) );

					Uri relative= root.MakeRelativeUri(thefile);

					relativefile= Uri.UnescapeDataString(relative.OriginalString).Replace('/', '\\');
				}

				// generate the export filename
				string targetfile= Path.GetFullPath(outputFolder +'\\'+ relativefile);

				// ensure that the export folder exists
				string finalOutputFolder= Path.GetDirectoryName(targetfile);
				Directory.CreateDirectory(finalOutputFolder);

				// remove the file extension
				//targetfile= targetfile.Substring(0, targetfile.Length - Path.GetExtension(targetfile).Length);
				relativefile= relativefile.Substring(0, relativefile.Length - Path.GetExtension(relativefile).Length);

				// export the behaviour
				bool firstRun= exporter ==null;
				exporter= exporterinfo.Create(behavior, outputFolder, relativefile);
                exporter.behaviorServer = "";

				// check if we must call pre export
				if(firstRun)
				{
					if(!exporter.PreExport(true))
						throw new Exception("Export process was aborted");
				}

				exporter.Export();
			}

			// call post export
			if(exporter !=null)
				exporter.PostExport(true);
		}
Exemplo n.º 4
0
        /// <summary>
        /// Exports the found behaviour files.
        /// </summary>
        /// <param name="exporterinfo">The exporter info of the exporter we want to use.</param>
        /// <param name="files">The behaviour files.</param>
        /// <param name="outputFolder">The folder the behaviours will be exported into.</param>
        /// <param name="exportIntoOneFolder">Defines if we export all behaviours into the output folder directly or if we create any sub folders found.</param>
        private static void ExportBehaviors(ExporterInfo exporterinfo, List <FileToExport> files, string outputFolder, bool exportIntoOneFolder)
        {
            Exporter exporter = null;

            for (int i = 0; i < files.Count; ++i)
            {
                FileToExport file = files[i];

                LogMessage(string.Format("Exporting \"{0}\"...", file.File));

                // reset previously loaded behavior
                FileManagers.FileManager.ResetLoadedBehavior();

                // load the behaviour file
                BehaviorNode behavior = _behaviorManager.LoadBehavior(file.File);
                if (behavior == null)
                {
                    throw new Exception(string.Format("Could not load behavior {0}", file.File));
                }

                // check if the file we exported comes from a folder or a given file
                string relativefile;
                if (file.BaseFolder == string.Empty || exportIntoOneFolder)
                {
                    // simply use the filename as it is
                    relativefile = Path.GetFileName(file.File);
                }
                else
                {
                    // create a relative filename of the behaviour to the folder it comes from
                    Uri root    = new Uri(Path.GetFullPath(file.BaseFolder) + '\\');
                    Uri thefile = new Uri(Path.GetFullPath(file.File));

                    Uri relative = root.MakeRelativeUri(thefile);

                    relativefile = Uri.UnescapeDataString(relative.OriginalString).Replace('/', '\\');
                }

                // generate the export filename
                string targetfile = Path.GetFullPath(outputFolder + '\\' + relativefile);

                // ensure that the export folder exists
                string finalOutputFolder = Path.GetDirectoryName(targetfile);
                Directory.CreateDirectory(finalOutputFolder);

                // remove the file extension
                //targetfile= targetfile.Substring(0, targetfile.Length - Path.GetExtension(targetfile).Length);
                relativefile = relativefile.Substring(0, relativefile.Length - Path.GetExtension(relativefile).Length);

                // export the behaviour
                bool firstRun = exporter == null;
                exporter = exporterinfo.Create(behavior, outputFolder, relativefile);

                // check if we must call pre export
                if (firstRun)
                {
                    if (!exporter.PreExport(true))
                    {
                        throw new Exception("Export process was aborted");
                    }
                }

                exporter.Export();
            }

            // call post export
            if (exporter != null)
            {
                exporter.PostExport(true);
            }
        }