private void ShowPlantFolderContents() { List <string> signBareNames = new List <string>(); lstPlantFiles.Items.Clear(); foreach (string filePath in Directory.GetFiles(_PlantFolder, "*.sgndat")) { string signFileName = Path.GetFileName(filePath); signBareNames.Add(Path.GetFileNameWithoutExtension(signFileName)); lstPlantFiles.Items.Add(signFileName); } lstImageFiles.Items.Clear(); foreach (string filePath in Directory.GetFiles(_PlantFolder, "*.jpg")) { string imageFileName = Path.GetFileName(filePath); string outputNameWithoutType; ImageNameParser.ParseFileName(imageFileName, out outputNameWithoutType, ref _LastGrower); if (signBareNames.Contains(outputNameWithoutType)) { imageFileName = _ImageUsedPrefix + imageFileName; } lstImageFiles.Items.Add(imageFileName); } _PlantHasChanged = false; _PlantIsNew = false; }
private void lstImageFiles_DoubleClick(object sender, EventArgs e) { if (DeclineToDiscardChanges()) { return; } Clear(); string imageFile = (string)lstImageFiles.SelectedItem; if (imageFile.StartsWith(_ImageUsedPrefix)) { imageFile = imageFile.Substring(_ImageUsedPrefix.Length); MessageBox.Show("NOTE: There is already a *.SGNDAT file with the same name as this image!"); } string outputNameWithoutType; List <string> nameWords; string encodedImageName; ImageNameParser.ExtractPlantFileAttributes(_PlantFolder, imageFile, chkRemoveExtraWord.Checked, cboExtraFactFile, out outputNameWithoutType, out nameWords, out encodedImageName, ref _LastGrower); txtEncodedImageName.Text = encodedImageName; txtPlantFileName.Text = outputNameWithoutType + ".sgndat"; txtVarietyName.Text = string.Join(" ", nameWords); GenerateContents(); _PlantIsNew = true; }
private void LoadImageFileList() { lvwImageFiles.Items.Clear(); foreach (string imageFile in _ImageFiles) { string lastGrower = string.Empty; ImageInfo imageInfo = new ImageInfo(); string[] subItems = new string[6]; subItems[0] = imageFile; subItems[1] = string.Empty; subItems[2] = string.Empty; subItems[3] = string.Empty; subItems[4] = string.Empty; subItems[5] = string.Empty; int factFileIndex = cboExtraFactFile.SelectedIndex; ImageNameParser.ExtractPlantFileAttributes(_PlantFolder, imageFile, false, cboExtraFactFile, out imageInfo.OutputNameWithoutType, out imageInfo.NameWords, out imageInfo.EncodedImageName, ref lastGrower); cboExtraFactFile.SelectedIndex = factFileIndex; imageInfo.PlantFile = imageInfo.OutputNameWithoutType + ".sgndat"; imageInfo.PlantPath = Path.Combine(_PlantFolder, imageInfo.PlantFile); subItems[5] = string.Join(" ", imageInfo.NameWords); if (File.Exists(imageInfo.PlantPath)) { imageInfo.PlantPathExists = true; subItems[1] = imageInfo.PlantFile; XmlDocument plantDoc = new XmlDocument(); plantDoc.Load(imageInfo.PlantPath); XmlElement varietyElm = plantDoc.DocumentElement.SelectSingleNode("data[@id='variety']") as XmlElement; if (varietyElm != null) { subItems[3] = varietyElm.InnerText; } foreach (XmlElement includeElm in plantDoc.DocumentElement.SelectNodes("include")) { string includeFile = includeElm.InnerText; if (includeFile.ToLower() != "facts.sgninc") { subItems[2] = includeFile; } } int varietyTips = 0; foreach (XmlElement dataElm in plantDoc.DocumentElement.SelectNodes("data")) { if (dataElm.GetAttribute("id").StartsWith("varietytip")) { varietyTips++; } } subItems[4] = varietyTips.ToString(); } ListViewItem item = new ListViewItem(subItems); item.Tag = imageInfo; lvwImageFiles.Items.Add(item); } }
private void btnCreatePlantFiles_Click(object sender, EventArgs e) { if (MessageBox.Show("Are you sure you want to create plant files for all the checked images?", "Continue", MessageBoxButtons.OKCancel) != DialogResult.OK) { return; } foreach (ListViewItem item in lvwImageFiles.CheckedItems) { ImageInfo imageInfo = (ImageInfo)item.Tag; if (imageInfo.PlantPathExists) { if (MessageBox.Show("Plant file \"" + imageInfo.PlantFile + "\" already exists. Do you want to create a new one?", "Continue", MessageBoxButtons.YesNo) != DialogResult.Yes) { continue; } } List <string> nameWords = new List <string>(imageInfo.NameWords); if (chkRemoveExtraWord.Checked) { int factFileIndex = cboExtraFactFile.SelectedIndex; string matchingExtraFactWord = ImageNameParser.ChooseMatchingExtraFact(nameWords, cboExtraFactFile); cboExtraFactFile.SelectedIndex = factFileIndex; if (matchingExtraFactWord != null) { nameWords.Remove(matchingExtraFactWord); } } StringBuilder content = new StringBuilder(); content.AppendLine("<container>"); content.AppendLine(" <data id=\"variety\">" + string.Join(" ", nameWords) + "</data>"); content.AppendLine(" <data id=\"pic\">" + imageInfo.EncodedImageName + "</data>"); content.AppendLine(" <include>Facts.sgninc</include>"); content.AppendLine("</container>"); using (TextWriter writer = new StreamWriter(imageInfo.PlantPath)) { writer.Write(content.ToString()); } } LoadImageFileList(); }
private void InsureSpecializedFactsExist() { List <string> colors = new List <string> { "red", "blue", "green", "yellow", "gold", "pink", "orange", "cardinal", "white", "violet", "purple", "cream", "blush", "scarlet", "tangerine", "crystal", "mix", "rose", "coral", "lemon", "silver", "apricot", "cranberry", "lilac", "salmon", "sapphire", "flame", "fire", "lavender", "black", "wine", "cherry", "fuchsia", "burgundy", "vanilla" }; bool fileCreated = false; Dictionary <string, WordUsage> words = new Dictionary <string, WordUsage>(); string signFolderName = GetSignFolderName(); foreach (string dirFile in Directory.GetFiles(_PlantFolder, "*.jpg")) { string bareName = Path.GetFileNameWithoutExtension(dirFile); foreach (string wordText in ImageNameParser.GetCapitalizedWords(bareName)) { if (wordText.Length > 2 && wordText != signFolderName) { if (!colors.Contains(wordText.ToLower())) { WordUsage usage; if (words.TryGetValue(wordText, out usage)) { usage.UseCount++; } else { words[wordText] = new WordUsage(wordText); } } } } } foreach (WordUsage usage in words.Values) { if (usage.UseCount > 1) { string factPath = Path.Combine(_PlantFolder, usage.Text + ".sgninc"); if (!File.Exists(factPath)) { if (MessageBox.Show("Create extra fact file for \"" + usage.Text + "\"?", "Create", MessageBoxButtons.YesNo) == DialogResult.Yes) { using (TextWriter writer = new StreamWriter(factPath)) { writer.WriteLine("<container>"); if (MessageBox.Show("Show \"" + usage.Text + "\" as separate subtitle line?", "Subtitle", MessageBoxButtons.YesNo) == DialogResult.Yes) { writer.WriteLine(" <data id=\"subtitle\">" + usage.Text + "</data>"); } writer.WriteLine("</container>"); } fileCreated = true; } } } } if (fileCreated) { ShowExtraFactFiles(); } }
private string GetSignFolderName() { return(ImageNameParser.GetPlantFolderName(_PlantFolder)); }