void generate(object sender, EventArgs e) { try { _string.Text = _suff.Generate(Convert.ToInt32(_value.Text)); _value.Text = _suff.ValueOf(_string.Text).ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); _string.Text = ""; } }
protected void saveButtonHandler(object sender, EventArgs e) { string path = _folderText.Text; if (path[path.Length - 1] != '\\') { path += '\\'; } string name = _nameBox.Text; if (_appendBtn.Checked) { name += _appendBox.Text + _wnd.ExportExtension; string[] fileList = Directory.GetFiles(path); for (int i = 0; i < fileList.Length; i++) { fileList[i] = Path.GetFileName(fileList[i]); } try { var suff = new Suffix(name); int[] exportList = suff.ListOfValues(fileList); int nextNum = 0; if (exportList != null) { nextNum = exportList[exportList.Length - 1] + 1; } name = suff.Generate(nextNum); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { name += _wnd.ExportExtension; } string fullPath = path + name; _wnd.Export(fullPath, (int)_scaleBox.Value); string abrvName; if (path.Length >= 10) { abrvName = path.Substring(0, 7) + "...\\" + name; } else { abrvName = fullPath; } _saveMsg.Text = "Saved " + abrvName; }
public void Generate(Suffix suff, string path, int count) { var img = new Bitmap(suff.Digits * 8 * Scale, 8 * Scale); using (var g = Graphics.FromImage(img)) { g.InterpolationMode = InterpolationMode.NearestNeighbor; g.PixelOffsetMode = PixelOffsetMode.Half; for (int i = 0; i < count; i++) { string name = suff.Generate(i); ProduceImage(g, suff, i); img.Save(path + name); } } }
void process(object sender, EventArgs e) { this.Output = ""; string path = _folderText.Text + "\\"; string[] fileList = Directory.GetFiles(path); string msg = fileList[0] + "\n"; int nFiles = 0; string plural = ""; for (int i = 0; i < fileList.Length; i++) { fileList[i] = Path.GetFileName(fileList[i]); } try { Suffix src = new Suffix(_srcField.Text); Suffix dst = new Suffix(_dstField.Text); if (!src.HasInsert || !dst.HasInsert) { throw new ArgumentException("Both suffix inputs must contain an insert (eg. {d2})"); } int[] values = src.ListOfValues(fileList); if (values == null) { throw new ArgumentException("No files matching \"" + _srcField.Text + "\" were found"); } nFiles = values.Length; plural = nFiles != 1 ? "s" : ""; Action <int> rename = (idx) => { string outName = dst.Generate(values[idx]); string srcFile = path + fileList[idx]; string dstFile = path + outName; if (!File.Exists(srcFile)) { return; } if (File.Exists(dstFile)) { if (outName.ToLower() != src.Generate(values[idx]).ToLower()) { throw new InvalidOperationException("i cant code :)"); } else { return; } } File.Move(srcFile, dstFile); }; for (int i = 0; i < nFiles; i++) { // This ensures that there aren't any rename conflicts, // where the destination file has the same name as the source file, // yet does not refer to the same number int idx = src.Base > dst.Base ? nFiles - i - 1 : i; rename(idx); } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } this.Output = "Successfully renamed " + nFiles + " file" + plural; }