Esempio n. 1
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(jsonFilePath) == true)
            {
                buttonSaveAs_Click(null, null);
            }

            JsonCharacter.GetInstance().SaveJsonFile(KeywordPathManager.GetOriginalPath(jsonFilePath), true);
            AppConfiguration.SetAppConfig("Json_file_path", KeywordPathManager.GetKeywordPath(jsonFilePath));
        }
Esempio n. 2
0
        public static bool LoadJsonFile(string filePath, out JsonCharacter jsonCharacter)
        {
            if (File.Exists(filePath) == false)
            {
                jsonCharacter = new JsonCharacter();
                return(false);
            }

            //파일을 읽어서 Json string 생성
            string jsonString = System.IO.File.ReadAllText(filePath);

            try
            {
                //Json object로 생성
                Newtonsoft.Json.Linq.JObject jObject = Newtonsoft.Json.Linq.JObject.Parse(jsonString);
                //Json object를 JsonCharacter 객체로 형변환 후 Instance로 설정
                jsonCharacter = jObject.ToObject(typeof(JsonCharacter)) as JsonCharacter;
            }
            catch (Exception exception)
            {
                throw exception;
            }

            jsonCharacter.rootPath = KeywordPathManager.GetOriginalPath(jsonCharacter.rootPath);

            for (int i = 0; i < jsonCharacter.characterList.Count(); i++)
            {
                //부모-자식관계 설정
                jsonCharacter.characterList[i].SetParentJsonCharacter(jsonCharacter);

                string imageFilePath = $@"{jsonCharacter.rootPath}\{jsonCharacter.characterList[i].imageFileName}";
                if (File.Exists(imageFilePath))
                {
                    //File lock이 되므로 코드 변경함.
                    //jsonCharacter.characterList[i].image = Image.FromFile(imageFilePath);
                    using (FileStream fileStream = new FileStream(imageFilePath, FileMode.Open, FileAccess.Read))
                    {
                        Image loadImage = Image.FromStream(fileStream);
                        jsonCharacter.characterList[i].image = loadImage.Clone() as Image;
                        loadImage.Dispose();
                        fileStream.Close();
                    }
                }
                else
                {
                    jsonCharacter.characterList[i].image = Properties.Resources.DefaultImageBitmap.Clone() as Image;
                }
            }

            //창 닫기 전에 변경사항 확인용 원본 저장
            jsonCharacter.originalJsonString = jsonCharacter.ConvertJsonString();

            return(true);
        }
Esempio n. 3
0
        private void buttonSetSaveDirectoryPath_Click(object sender, EventArgs e)
        {
            folderBrowserDialog.SelectedPath = saveDirectoryPath;
            if (folderBrowserDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            saveDirectoryPath = folderBrowserDialog.SelectedPath;
            AppConfiguration.SetAppConfig("Save_directory_path", KeywordPathManager.GetKeywordPath(folderBrowserDialog.SelectedPath));
        }
Esempio n. 4
0
        public void SaveJsonFile(string filePath, bool overwrite = false)
        {
            if (overwrite == false)
            {
                rootPath = $@"{Path.GetDirectoryName(filePath)}\{Path.GetFileNameWithoutExtension(filePath)}";
                Directory.CreateDirectory(rootPath);
                filePath = $@"{rootPath}\{Path.GetFileName(filePath)}";
            }

            for (int i = 0; i < characterList.Count(); i++)
            {
                string imageFilePath = $@"{rootPath}\{characterList[i].imageFileName}";

                if (File.Exists(imageFilePath))
                {
                    File.Delete(imageFilePath);
                }

                if (characterList[i].image == null)
                {
                    continue;
                }

                try
                {
                    characterList[i].image.Save(imageFilePath, characterList[i].image.RawFormat);
                }
                catch
                {
                    Bitmap   bitmap = new Bitmap(characterList[i].image.Width, characterList[i].image.Height, characterList[i].image.PixelFormat);
                    Graphics g      = Graphics.FromImage(bitmap);
                    g.DrawImage(characterList[i].image, new Point(0, 0));
                    g.Dispose();
                    characterList[i].image.Dispose();
                    bitmap.Save(imageFilePath);
                    characterList[i].image = bitmap; // preserve clone
                }
            }

            //Json string으로 변경합니다.
            //창 닫기 전에 변경사항 확인용 원본 저장
            rootPath           = KeywordPathManager.GetKeywordPath(rootPath);
            originalJsonString = ConvertJsonString();

            //파일로 저장합니다.
            File.WriteAllText(filePath, originalJsonString);

            rootPath = KeywordPathManager.GetOriginalPath(rootPath);
        }
Esempio n. 5
0
        private void buttonSaveAs_Click(object sender, EventArgs e)
        {
            Directory.CreateDirectory(saveDirectoryPath);

            saveJsonFileDialog.InitialDirectory = saveDirectoryPath;
            saveJsonFileDialog.FileName         = string.Empty;
            if (DialogResult.OK != saveJsonFileDialog.ShowDialog())
            {
                return;
            }

            JsonCharacter.GetInstance().SaveJsonFile(saveJsonFileDialog.FileName);
            jsonFilePath = $@"{JsonCharacter.GetInstance().rootPath}\{Path.GetFileName(saveJsonFileDialog.FileName)}";
            AppConfiguration.SetAppConfig("Json_file_path", KeywordPathManager.GetKeywordPath($@"{JsonCharacter.GetInstance().rootPath}\{Path.GetFileName(saveJsonFileDialog.FileName)}"));
        }
Esempio n. 6
0
        private void Initialize()
        {
            dataGridViewMain.AutoGenerateColumns   = false;
            dataGridViewWinner.AutoGenerateColumns = false;
            pictureBoxSelectedImage.Image          = Properties.Resources.DefaultImage;

            string[] seedStringArray       = null;
            int      randomNumberSeedCount = 0;

            if (int.TryParse(AppConfiguration.GetAppConfig("Random_number_seed_count"), out randomNumberSeedCount))
            {
                seedStringArray = new string[randomNumberSeedCount];
                for (int i = 0; i < randomNumberSeedCount; i++)
                {
                    seedStringArray[i] = AppConfiguration.GetAppConfig($@"Seed_{(i+1).ToString("00")}");
                }
            }
            randomNumberGenerator = new RandomNumberGenerator(seedStringArray);

            saveDirectoryPath = AppConfiguration.GetAppConfig("Save_directory_path");
            saveDirectoryPath = KeywordPathManager.GetOriginalPath(saveDirectoryPath); //null, empty인 경우 바탕화면으로 설정됨.

            jsonFilePath = AppConfiguration.GetAppConfig("Json_file_path");
            if (string.IsNullOrEmpty(jsonFilePath) == false)
            {
                jsonFilePath = KeywordPathManager.GetOriginalPath(jsonFilePath);
                JsonCharacter jsonCharacter = new JsonCharacter();
                if (JsonCharacter.LoadJsonFile(jsonFilePath, out jsonCharacter) == false)
                {
                    MessageBox.Show($@"Json 파일 읽어오기 실패.{Environment.NewLine}{AppConfiguration.GetAppConfig("Json_file_path")}");
                    jsonFilePath = string.Empty;
                }
                else
                {
                    JsonCharacter.SetInstance(jsonCharacter);
                }
            }

            dataGridViewMain.DataSource = new BindingList <Character>(JsonCharacter.GetInstance().characterList);
        }
Esempio n. 7
0
        private void buttonLoad_Click(object sender, EventArgs e)
        {
            openJsonFileDialog.InitialDirectory = saveDirectoryPath;
            openJsonFileDialog.FileName         = string.Empty;
            if (DialogResult.OK != openJsonFileDialog.ShowDialog())
            {
                return;
            }

            jsonFilePath = openJsonFileDialog.FileName;
            JsonCharacter jsonCharacter = new JsonCharacter();

            if (JsonCharacter.LoadJsonFile(jsonFilePath, out jsonCharacter) == false)
            {
                MessageBox.Show($@"Json 파일 오류. {AppConfiguration.GetAppConfig("Json_file_path")}");
            }
            else
            {
                JsonCharacter.SetInstance(jsonCharacter);
            }

            dataGridViewMain.DataSource = new BindingList <Character>(JsonCharacter.GetInstance().characterList);
            AppConfiguration.SetAppConfig("Json_file_path", KeywordPathManager.GetKeywordPath(jsonFilePath));
        }