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)); }
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)); }
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); }
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)}")); }
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)); }