static void sendToRawMaterial(string path, bool copy = false)
        {
            // "delete" it by sending it to raw material
            var material = Configs.Current.Get(ConfigKey.FilepathSortMusicKeepAsMaterialDir);

            if (string.IsNullOrEmpty(material) || !Directory.Exists(material))
            {
                material = InputBoxForm.GetStrInput(
                    "Choose a directory where deleted music will be sent as raw material:",
                    Configs.Current.Get(ConfigKey.FilepathSortMusicKeepAsMaterialDir),
                    mustBeDirectory: true);

                if (string.IsNullOrEmpty(material) || !Directory.Exists(material))
                {
                    throw new CoordinatePicturesException("Directory not found.");
                }
                else
                {
                    Configs.Current.Set(ConfigKey.FilepathSortMusicKeepAsMaterialDir, material);
                }
            }

            var dest = Path.Combine(material, Path.GetFileName(path) + Utils.GetRandomDigits());

            if (copy)
            {
                SimpleLog.Current.WriteLog("Send to raw-material. File.Copy " + path + " to " + dest);
                File.Copy(path, dest);
            }
            else
            {
                SimpleLog.Current.WriteLog("Send to raw-material. File.Move " + path + " to " + dest);
                File.Move(path, dest);
            }
        }
        public void AutoAcceptSmallFiles(FormGallery form, int capJpg = 0, int capWebp = 0)
        {
            var list = form.GetFilelist().GetList();

            // first, check for duplicate names
            foreach (var path in list)
            {
                var similar = FindSimilarFilenames.FindSimilarNames(
                    path, GetFileTypes(), list, out bool nameHasSuffix, out string pathWithoutSuffix);
                if (similar.Count != 0)
                {
                    Utils.MessageErr("the file " + path + " has similar name(s) "
                                     + string.Join(Utils.NL, similar));
                    return;
                }
            }

            // then, accept the small files
            if (capJpg == 0)
            {
                var optCapWebp = InputBoxForm.GetInteger("Accept webp files less than this many Kb:", 50);
                if (!optCapWebp.HasValue)
                {
                    return;
                }

                var optCapJpg = InputBoxForm.GetInteger("Accept jpg files less than this many Kb:", 100);
                if (!optCapJpg.HasValue)
                {
                    return;
                }

                capWebp = 1024 * optCapWebp.Value;
                capJpg  = 1024 * optCapJpg.Value;
            }

            int countAccepted      = 0;
            var sizeIsGoodCategory = GetDefaultCategories().Split(new char[] { '/' })[2];

            foreach (var path in list)
            {
                var fileLength = new FileInfo(path).Length;
                if (fileLength > 0 &&
                    ((ModeUtils.IsWebp(path) &&
                      fileLength < capWebp) ||
                     (ModeUtils.IsJpg(path) &&
                      fileLength < capJpg)))
                {
                    countAccepted++;
                    var newPath = FilenameUtils.AddCategoryToFilename(path, sizeIsGoodCategory);
                    form.WrapMoveFile(path, newPath);
                }
            }

            Utils.MessageBox("Accepted for " + countAccepted + " images.", true);
        }
Beispiel #3
0
        static void OnSetConfigsDir(string info, object sender, ConfigKey key)
        {
            var message         = (sender as ToolStripItem).Text + Utils.NL + info;
            var chosenDirectory = InputBoxForm.GetStrInput(message,
                                                           Configs.Current.Get(key), mustBeDirectory: true);

            if (!string.IsNullOrEmpty(chosenDirectory))
            {
                Configs.Current.Set(key, chosenDirectory);
            }
        }
Beispiel #4
0
        // ask user for string input.
        public static string GetStrInput(string mesage, string currentSuggestion = null,
                                         InputBoxHistory historyKey = InputBoxHistory.None, string[] more = null,
                                         bool useClipboard          = true, bool mustBeDirectory = false, bool taller = false)
        {
            using (InputBoxForm form = new InputBoxForm(historyKey))
            {
                form._label.Text        = mesage;
                form._btnBrowse.Visible = mustBeDirectory;
                form._btnBrowse.Click  += (o, e) => form.OnBrowseClick();
                if (taller)
                {
                    form._comboBox.Top  += form.Height - 40;
                    form._btnOK.Top     += form.Height - 40;
                    form._btnCancel.Top += form.Height - 40;
                    form._label.Height  += form.Height - 40;
                    form.Height         *= 2;
                }

                // fill combo box with suggested input.
                form._comboBox.Items.Clear();
                var suggestions = GetInputSuggestions(currentSuggestion, historyKey, form._mru,
                                                      useClipboard, mustBeDirectory, more).ToArray();

                foreach (var s in suggestions)
                {
                    form._comboBox.Items.Add(s);
                }

                form._comboBox.Text = suggestions.Length > 0 ? suggestions[0] : "";
                form.ShowDialog();
                if (form.DialogResult != DialogResult.OK)
                {
                    return(null);
                }

                if (mustBeDirectory && !Directory.Exists(form._comboBox.Text))
                {
                    Utils.MessageBox("Directory does not exist");
                    return(null);
                }

                // save to history
                form._mru.AddToHistory(form._comboBox.Text);
                return(form._comboBox.Text);
            }
        }
        private void MnuEditLocal_Click(object sender, EventArgs e)
        {
            // current limitations:
            // 1) can't be undone
            // 2) doesn't edit underlying file yet, until you assign a category
            if (this.listBox.SelectedItems.Count != 1)
            {
                MessageBox.Show("You should first select exactly one.");
                return;
            }

            var index = this.listBox.SelectedIndices[0];
            var next  = InputBoxForm.GetStrInput("edit:", this.listBox.Items[index].ToString());

            if (!string.IsNullOrEmpty(next))
            {
                this.listBox.Items.RemoveAt(index);
                this.listBox.Items.Insert(index, next);
            }
        }
Beispiel #6
0
 static string AskUserForDirectory(InputBoxHistory mruKey)
 {
     return(InputBoxForm.GetStrInput(
                "Enter directory:", null, mruKey, mustBeDirectory: true));
 }