Beispiel #1
0
 public static void LoadConfig(string path)
 {
     try
     {
         if (!File.Exists(Path.Combine(path, "Config.xml")))
         {
             ConfigManager cm = new ConfigManager()
             {
                 PDF = new List <string>()
                 {
                     "DefaultPDF.xml", "AlternatePDF.xml"
                 }
             };
             cm.Save(Path.Combine(path, "Config.xml"));
         }
         ConfigManager loaded = Program.Context.LoadConfig(path);
         PDFExporter = PlayerExtensions.Load(ImportExtensions.Fullpath(path, loaded.PDF[0]));
         Program.Context.LoadAbilityScores(ImportExtensions.Fullpath(path, loaded.AbilityScores));
     }
     catch (Exception e)
     {
         System.Windows.Forms.MessageBox.Show(e.Message + "\n" + e.InnerException + "\n" + e.StackTrace, "Error while Loading Configuration");
         Program.Exit();
     }
 }
 static void Main()
 {
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     if (Properties.Settings.Default.DCI != null && Properties.Settings.Default.DCI != "")
     {
         Context.Player.DCI = Properties.Settings.Default.DCI;
     }
     if (Properties.Settings.Default.PlayerName != null && Properties.Settings.Default.PlayerName != "")
     {
         Context.Player.PlayerName = Properties.Settings.Default.PlayerName;
     }
     ConfigManager.LogEvents += (sender, text, e) => Console.WriteLine((text != null ? text + ": " : "") + e?.StackTrace);
     string[] args = Environment.GetCommandLineArgs();
     Errorlog = new ErrorLog();
     Config.LoadConfig(Application.StartupPath);
     HTMLExtensions.LoadTransform += (t, o) => { if (o is DisplayPossession)
                                                 {
                                                     t.Load(HTMLExtensions.Transform_Possession.FullName);
                                                 }
     };
     ConfigManager.LicenseProvider = new LicenseProvider();
     if (SourceManager.Init(Context, Application.StartupPath, true))
     {
         if (args.Count() > 1)
         {
             string file = args[1];
             if (File.Exists(file) && ".pdf".Equals(Path.GetExtension(file), StringComparison.InvariantCultureIgnoreCase))
             {
                 markFields(file);
                 Application.Exit();
                 return;
             }
         }
         if (Properties.Settings.Default.EnabledSourcebooks != null && Properties.Settings.Default.EnabledSourcebooks.Count != 0)
         {
             Context.Player.ExcludedSources = SourceManager.Sources.Where(s => !Properties.Settings.Default.EnabledSourcebooks.Contains(s)).ToList();
             Context.ExcludedSources.UnionWith(Context.Player.ExcludedSources);
         }
         LoadData();
     }
     else
     {
         Exit();
         return;
     }
     Context.SourcesChangedEvent += Player_SourcesChangedEvent;
     MainWindow = new Form1();
     if (args.Count() > 1)
     {
         string file = args[1];
         if (File.Exists(file))
         {
             MainWindow.lastfile = file;
             using (FileStream fs = new FileStream(file, FileMode.Open))
             {
                 try
                 {
                     Context.Player = PlayerExtensions.Load(Context, fs);
                     MainWindow.UpdateLayout();
                 }
                 catch (Exception e)
                 {
                     System.Windows.Forms.MessageBox.Show(e.Message + "\n" + e.InnerException + "\n" + e.StackTrace, "Error while loading " + file);
                     Program.Exit();
                 }
             }
         }
     }
     if (args.Count() > 2 && args[2] == "register")
     {
         Register();
     }
     Application.Run(MainWindow);
 }
        public Export(string lastfile)
        {
            this.lastfile = lastfile;
            InitializeComponent();
            foreach (String s in Program.Context.Config.PDFExporters)
            {
                try
                {
                    PDF p = PlayerExtensions.Load(s);
                    if (p.Name != "" && p.Name != null && !CUSTOM.Equals(p.Name) && !SAVE.Equals(p.Name))
                    {
                        pdfs[p.Name] = p;
                    }
                    if (p.File != null && p.File != "" && (!charsheets.ContainsKey(p.SheetName ?? Path.GetFileName(p.File)) || charsheets[p.SheetName ?? Path.GetFileName(p.File)].SheetPreview == null))
                    {
                        charsheets[p.SheetName ?? Path.GetFileName(p.File)] = p;
                    }
                    if (p.SpellFile != null && p.SpellFile != "" && (!spellsheets.ContainsKey(p.SpellName ?? Path.GetFileName(p.SpellFile)) || spellsheets[p.SpellName ?? Path.GetFileName(p.SpellFile)].SpellPreview == null))
                    {
                        spellsheets[p.SpellName ?? Path.GetFileName(p.SpellFile)] = p;
                    }
                    if (p.LogFile != null && p.LogFile != "" && (!logsheets.ContainsKey(p.LogName ?? Path.GetFileName(p.LogFile)) || logsheets[p.LogName ?? Path.GetFileName(p.LogFile)].LogPreview == null))
                    {
                        logsheets[p.LogName ?? Path.GetFileName(p.LogFile)] = p;
                    }
                    if (p.SpellbookFile != null && p.SpellbookFile != "" && (!spellbooks.ContainsKey(p.SpellbookName ?? Path.GetFileName(p.SpellbookFile)) || spellbooks[p.SpellbookName ?? Path.GetFileName(p.SpellbookFile)].SpellbookPreview == null))
                    {
                        spellbooks[p.SpellbookName ?? Path.GetFileName(p.SpellbookFile)] = p;
                    }
                    if (p.ActionsFile != null && p.ActionsFile != "" && (!actionsheets.ContainsKey(p.ActionsName ?? Path.GetFileName(p.ActionsFile)) || actionsheets[p.ActionsName ?? Path.GetFileName(p.ActionsFile)].ActionsPreview == null))
                    {
                        actionsheets[p.ActionsName ?? Path.GetFileName(p.ActionsFile)] = p;
                    }
                    if (p.MonstersFile != null && p.MonstersFile != "" && (!monstersheets.ContainsKey(p.MonstersName ?? Path.GetFileName(p.MonstersFile)) || monstersheets[p.MonstersName ?? Path.GetFileName(p.MonstersFile)].MonstersPreview == null))
                    {
                        monstersheets[p.MonstersName ?? Path.GetFileName(p.MonstersFile)] = p;
                    }
                }
                catch (Exception e)
                {
                    ConfigManager.LogError(e);
                }
            }
            Preset.Items.Add(CUSTOM);
            foreach (string s in pdfs.Keys.OrderBy(s => s))
            {
                Preset.Items.Add(s);
            }
            Preset.Items.Add(SAVE);
            SpellBox.Items.Add(NONE);
            LogBox.Items.Add(NONE);
            SpellbookBox.Items.Add(NONE);
            ActionsBox.Items.Add(NONE);
            MonsterBox.Items.Add(NONE);
            SheetBox.Items.AddRange(charsheets.Keys.OrderBy(s => s).ToArray());
            SpellBox.Items.AddRange(spellsheets.Keys.OrderBy(s => s).ToArray());
            LogBox.Items.AddRange(logsheets.Keys.OrderBy(s => s).ToArray());
            SpellbookBox.Items.AddRange(spellbooks.Keys.OrderBy(s => s).ToArray());
            ActionsBox.Items.AddRange(actionsheets.Keys.OrderBy(s => s).ToArray());
            MonsterBox.Items.AddRange(monstersheets.Keys.OrderBy(s => s).ToArray());

            foreach (string s in PDFBase.APFormats)
            {
                ACPBox.Items.Add(PDF.APFormat(Program.Context, s, 14) + " + 4 AP = " + PDF.APFormat(Program.Context, s, 18));
            }
            string last = Properties.Settings.Default.LastPDFPreset;

            if (pdfs.ContainsKey(last) || CUSTOM.Equals(last))
            {
                Preset.SelectedItem = last;
            }
            else
            {
                button1.Enabled = false;
            }
            ResourcesBox.Checked               = Properties.Settings.Default.PDFUsedResources;
            PreserveBox.Checked                = Properties.Settings.Default.PDFPreserveForms;
            DuplexBox.Checked                  = Properties.Settings.Default.PDFDuplex;
            DuplexWhiteBox.Checked             = Properties.Settings.Default.PDFDuplexWhite;
            ACPBox.SelectedIndex               = Properties.Settings.Default.PDFACPFormat;
            SwapScoreModBox.Checked            = Properties.Settings.Default.PDFSwapScoreMod;
            IgnoreMagicItemsBox.Checked        = !Properties.Settings.Default.PDFLogMagicItems;
            MundaneItemBox.Checked             = Properties.Settings.Default.PDFSpellbookMundaneItems;
            BonusSpellsResources.SelectedIndex = Properties.Settings.Default.PDFBonusSpellResources;
            EquipmentKeywords.Checked          = Properties.Settings.Default.PDFEquipmentKeywords;
            EquipmentStats.Checked             = Properties.Settings.Default.PDFEquipmentStats;
            FeatureTitle.Checked               = Properties.Settings.Default.PDFFeatureTitlesOnly;

            BuildAttacks();
        }