Exemple #1
0
        private void Bt_Save_Click(object sender, EventArgs e)
        {
            try
            {
                LastSes lst = null;
                if (CLB_Skills.Items.Count < 1 && CLB_Skill_Trees.Items.Count < 1)
                {
                    lst = new LastSes()
                    {
                        Dir = TB_GameDir_Dir.Text, WSAuth = Tb_WsAuthor.Text, Skills = new CustomSkill[0], Skilltrees = new SkillTree[0]
                    };
                }
                else if (CLB_Skill_Trees.Items.Count < 1)
                {
                    lst = new LastSes()
                    {
                        Dir = TB_GameDir_Dir.Text, WSAuth = Tb_WsAuthor.Text, Skills = CLB_Hero_Skills.Items.OfType <CustomSkill>().ToArray(), Skilltrees = new SkillTree[0]
                    };
                }
                else if (CLB_Skills.Items.Count < 1)
                {
                    lst = new LastSes()
                    {
                        Dir = TB_GameDir_Dir.Text, WSAuth = Tb_WsAuthor.Text, Skills = new CustomSkill[0], Skilltrees = CLB_Skill_Trees.Items.OfType <SkillTree>().ToArray()
                    };
                }
                else
                {
                    lst = new LastSes()
                    {
                        Dir = TB_GameDir_Dir.Text, WSAuth = Tb_WsAuthor.Text, Skills = CLB_Hero_Skills.Items.OfType <CustomSkill>().ToArray(), Skilltrees = CLB_Skill_Trees.Items.OfType <SkillTree>().ToArray()
                    };
                }
                FileStream      fs = new FileStream("LastSession.dat", FileMode.Create);
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(fs, lst);
                fs.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show($"There was an error saving program data, current data input will be lost on restart \n Error Msg: {ex.Message}", "Error, Data could not be saved", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            var folderBrowserDialog1 = new FolderBrowserDialog();

            DialogResult result = folderBrowserDialog1.ShowDialog();

            if (result == DialogResult.OK)
            {
                string folderName = folderBrowserDialog1.SelectedPath + "\\";

                byte[] Large;
                byte[] Medium;
                byte[] Mood;
                byte[] Mod;

                try
                {
                    Large = ImageToByteArray(this.PicBox_GUILarge.Image);
                }
                catch (Exception)
                {
                    Large = new byte[0];
                }
                try
                {
                    Medium = ImageToByteArray(this.PicBox_GUIMedium.Image);
                }
                catch (Exception)
                {
                    Medium = new byte[0];
                }
                try
                {
                    Mood = ImageToByteArray(this.PicBox_GUIMood.Image);
                }
                catch (Exception)
                {
                    Mood = new byte[0];
                }
                try
                {
                    Mod = ImageToByteArray(this.PicBox_ModIcon.Image);
                }
                catch (Exception)
                {
                    Mod = new byte[0];
                }


                FileStructure.CreateFolders(folderName, this.Tb_WsTitle.Text);
                FileStructure.CreateFiles(folderName, this.Tb_WsTitle.Text, this.Tb_Name.Text, this.Tb_Description.Text, this.Tb_WsTitle.Text, this.Tb_WsDescription.Text, this.Tb_WsAuthor.Text, this.Tb_WsReleaseNotes.Text, this.Cb_Affinity.Text, this.Cb_Class.Text, this.Cb_Politics.Text, this.Cb_ShipDesign.Text, this.Cb_SkillTree1.Text, this.Cb_SkillTree2.Text, this.Cb_SkillTree3.Text, Large, Medium, Mood, Mod, CLB_Hero_Skills.Items.OfType <CustomHeroSkill>().ToList(), CLB_Skill_Trees.Items.OfType <SkillTree>().ToList());
                if (CLB_HeroDebug.Items.Count != 0)
                {
                    File.WriteAllText($"{folderName}{this.Tb_WsTitle.Text}\\Simulation\\FactionTraits.xml", Data.GetXMLFactionDebug(TB_GameDir_Dir.Text, ref CLB_HeroDebug));
                }
            }
        }