Пример #1
0
        private void copyMediaButton_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            List <string> repositoryDirectoryList = RepositoryClass.Instance.RepositoryDirectoryList;
            string        worldName = worldNameTextBox.Text.Trim();

            if (worldName != "")
            {
                if (repositoryDirectoryList.Count == 0)
                {
                    throw new Exception("Specified world name without a repository");
                }
                repositoryDirectoryList.Insert(0, Path.Combine(repositoryDirectoryList[repositoryDirectoryList.Count - 1], worldName));
                // We should probably warn them if we have more than one repository
            }
            List <string> log =
                RepositoryClass.Instance.InitializeRepository(repositoryDirectoryList);

            CheckLogAndMaybeExit(log);
            List <string> assetListFiles = new List <string>();

            logListBox.Items.Clear();
            logListBox.Items.Add("Starting copy to repository " + newTreeTextBox.Text + "...");
            List <string> allWorldAssetsLines = new List <string>(worldAssetLines);

            if (worldAssetsCheckedListBox.CheckedItems.Count > 0)
            {
                foreach (Object item in worldAssetsCheckedListBox.CheckedItems)
                {
                    allWorldAssetsLines.AddRange(RepositoryClass.ReadFileLines(((string)item).Trim()));
                }
            }
            foreach (Object obj in assetListCheckedListBox.CheckedItems)
            {
                assetListFiles.Add((string)obj);
            }
            copyMediaButton.Enabled             = false;
            createEmptyRepositoryButton.Enabled = false;
            cancelButton.Enabled = false;
            generateBackgroundWorker.RunWorkerAsync(new copyArgs(worldNameTextBox.Text, allWorldAssetsLines, assetListFiles,
                                                                 newTreeTextBox.Text,
                                                                 copyAssetDefinitionsCheckBox.Checked));
        }
Пример #2
0
        // Legal args are:
        // --source_repository             Optional.  If supplied, the arg is the
        //                                 the directory that holds the asset repository
        //                                 from which files will be copied.
        // --set_default_repository        Optional.  If supplied, the arg is the
        //                                 new default repository directory.  Sets the
        //                                 key and exits immediately.
        // --worldassets_file file         Optional, but nearly always
        //                                 supplied.  You can have as
        //                                 many of these as you want.
        // --assetlist_file file           Optional, but if not supplied,
        //                                 worldassets_file must be supplied
        //                                 and vice versa.  Can have more
        //                                 than 1 assetlist_file argument pair
        // --new_asset_repository          Required; the directory that
        //                                 holds the new asset repository
        // --dont_copy_asset_defs          Don't copy the the asset definition
        //                                 files themselves.
        // --world_name name               If present, used to find
        //                                 the optional subdirectory
        //                                 of the source media tree
        //                                 which contains world-specific files to
        //                                 substitute for files referenced by asset
        //                                 definitions
        static void ProcessArgs(string [] args)
        {
            List <string> sourceRepositories  = new List <string>();
            List <string> worldAssetsFiles    = new List <string>();
            List <string> addonFiles          = new List <string>();
            string        newAssetRepository  = "";
            bool          copyAssetDefs       = true;
            List <string> defaultRepositories = new List <string>();
            string        worldName           = "";

            Console.OpenStandardOutput();
            for (int i = 0; i < args.Length; ++i)
            {
                switch (args[i])
                {
                case "--source_repository":
                    sourceRepositories.Add(args[++i]);
                    break;

                case "--worldassets_file":
                    worldAssetsFiles.Add(args[++i]);
                    break;

                case "--assetlist_file":
                    addonFiles.Add(args[++i]);
                    break;

                case "--new_asset_repository":
                    newAssetRepository = args[++i];
                    break;

                case "--dont_copy_asset_defs":
                    copyAssetDefs = false;
                    break;

                case "--set_default_repository":
                    defaultRepositories.Add(args[++i]);
                    break;

                case "--world_name":
                    worldName = args[++i];
                    break;

                default:
                    Barf(string.Format("Unrecognized command-line argument '{0}'; exiting", args[i]));
                    return;
                }
            }
            if (defaultRepositories.Count == 0 && worldAssetsFiles.Count == 0 && addonFiles.Count == 0)
            {
                Barf("Neither the worldassets_file argument was supplied, nor any assetlist_file arguments; exiting");
                return;
            }
            if (defaultRepositories.Count == 0 && newAssetRepository == "")
            {
                Barf("The new_asset_repository command-line argument was not supplied; exiting");
                return;
            }
            foreach (string worldAssetsFile in worldAssetsFiles)
            {
                if (!File.Exists(worldAssetsFile))
                {
                    Barf(string.Format("The world asset file '{0}' does not exist!", worldAssetsFile));
                    return;
                }
            }

            try {
                if (defaultRepositories.Count > 0)
                {
                    RepositoryClass.Instance.SetRepositoryDirectoriesInRegistry(defaultRepositories);
                    Console.WriteLine(string.Format("Set default repository to '{0}'", RepositoryClass.Instance.RepositoryDirectoryList));
                    return;
                }
                else
                {
                    if (!Directory.Exists(newAssetRepository))
                    {
                        Directory.CreateDirectory(newAssetRepository);
                    }
                    List <string> directories = new List <string>();
                    if (sourceRepositories.Count > 0)
                    {
                        directories = sourceRepositories;
                    }
                    else
                    {
                        RepositoryClass.Instance.InitializeRepositoryPath();
                        directories.AddRange(RepositoryClass.Instance.RepositoryDirectoryList);
                        if (worldName != "")
                        {
                            directories.Insert(0, Path.Combine(directories[directories.Count - 1], worldName));
                        }
                    }
                    RepositoryClass.Instance.InitializeRepository(directories);
                    string summary = string.Format("world_name='{0}', source_repositories='{1}', new_asset_repository='{2}', dont_copy_asset_defs={3}",
                                                   worldName, sourceRepositories, newAssetRepository, !copyAssetDefs);
                    List <string> worldAssetLines = new List <string>();
                    foreach (string worldAssetsFile in worldAssetsFiles)
                    {
                        summary += string.Format(", worldassets_file='{0}'", worldAssetsFile);
                        List <string> lines = (worldAssetsFile == "" ? new List <string>() :
                                               RepositoryClass.ReadFileLines(worldAssetsFile.Trim()));
                        worldAssetLines.AddRange(lines);
                    }
                    foreach (string addonFile in addonFiles)
                    {
                        summary += string.Format(", assetlist_file='{0}'", addonFile);
                    }
                    Console.WriteLine("Command-line arguments: " + summary);
                    RepositoryClass.Instance.GenerateAndCopyMediaTree(worldAssetLines, addonFiles,
                                                                      newAssetRepository, copyAssetDefs);
                    List <string> log = RepositoryClass.Instance.ErrorLog;
                    foreach (string s in log)
                    {
                        Console.WriteLine(s);
                    }
                }
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }