Esempio n. 1
0
        public async Task <bool> DoCommandLineAsync(string[] args)
        {
            string[] templateFiles        = (from string arg in args where File.Exists(arg) select arg).ToArray();
            string[] invalidTemplateFiles = (from string arg in args where !File.Exists(arg) select arg).ToArray();

            foreach (string filePath in invalidTemplateFiles)
            {
                WriteToDebugLog($"Template file {filePath} doesn't exist.", LogMessageErrorLevel.Warning);
            }

            if (templateFiles.Length == 0)
            {
                WriteToDebugLog("No valid mission template files given as parameters.", LogMessageErrorLevel.Error);
                WriteToDebugLog("");
                WriteToDebugLog("Command-line format is BriefingRoomCommandLine.exe <MissionTemplate.brt> [<MissionTemplate2.brt> <MissionTemplate3.brt>...]");
                return(false);
            }

            foreach (string t in templateFiles)
            {
                if (Path.GetExtension(t).ToLowerInvariant() == ".cbrt") // Template file is a campaign template
                {
                    DCSCampaign campaign = await BriefingRoomGenerator.GenerateCampaignAsync(t);

                    if (campaign == null)
                    {
                        Console.WriteLine($"Failed to generate a campaign from template {Path.GetFileName(t)}");
                        continue;
                    }

                    string campaignDirectory;
                    if (templateFiles.Length == 1) // Single template file provided, use  campaign name as campaign path.
                    {
                        campaignDirectory = Path.Combine(Application.StartupPath, RemoveInvalidPathCharacters(campaign.Name));
                    }
                    else // Multiple template files provided, use the template name as campaign name so we know from which template campaign was generated.
                    {
                        campaignDirectory = Path.Combine(Application.StartupPath, Path.GetFileNameWithoutExtension(t));
                    }
                    campaignDirectory = GetUnusedFileName(campaignDirectory);

                    campaign.ExportToDirectory(Application.StartupPath);
                    WriteToDebugLog($"Campaign {Path.GetFileName(campaignDirectory)} exported to directory from template {Path.GetFileName(t)}");
                }
                else // Template file is a mission template
                {
                    DCSMission mission = await BriefingRoomGenerator.GenerateMissionAsync(t);

                    if (mission == null)
                    {
                        Console.WriteLine($"Failed to generate a mission from template {Path.GetFileName(t)}");
                        continue;
                    }

                    string mizFileName;
                    if (templateFiles.Length == 1) // Single template file provided, use "theater + mission name" as file name.
                    {
                        mizFileName = Path.Combine(Application.StartupPath, $"{mission.TheaterID} - {RemoveInvalidPathCharacters(mission.Briefing.Name)}.miz");
                    }
                    else // Multiple template files provided, use the template name as file name so we know from which template mission was generated.
                    {
                        mizFileName = Path.Combine(Application.StartupPath, Path.GetFileNameWithoutExtension(t) + ".miz");
                    }
                    mizFileName = GetUnusedFileName(mizFileName);

                    if (!mission.SaveToMizFile(mizFileName))
                    {
                        WriteToDebugLog($"Failed to export .miz file from template {Path.GetFileName(t)}", LogMessageErrorLevel.Warning);
                        continue;
                    }
                    else
                    {
                        WriteToDebugLog($"Mission {Path.GetFileName(mizFileName)} exported to .miz file from template {Path.GetFileName(t)}");
                    }
                }
            }

            return(true);
        }