コード例 #1
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (!ValidateFields())
            {
                return;
            }
            string filename = string.Empty;

            try
            {
                if (txtGroup.Text.Length > 1)
                {
                    filename = '[' + txtGroup.Text + ']' + ' ';
                }
                filename += txtTitle.Text + FileNameFormat.ToFormat(txtStart.Text, txtSeason.Text, fileformat);

                string fullpath = Path.Combine(dirname, filename.Replace(' ', '_'));
                file.FileName = fullpath;
                if (txtEnd.Text.Length > 1)
                {
                    fullpath = file.FileName.Replace(file.EstimateEpisode(), file.EstimateEpisode() + "-" + txtEnd.Text);
                }

                fullpath = Path.ChangeExtension(fullpath, radType_Filler.Checked ? "filler" : "missing");

                if (File.Exists(fullpath))
                {
                    Error_Handle.TipError("Title Already Exists\n", toolTip, txtTitle);
                    return;
                }
                imgWorking.Visible = true;
                File.CreateText(fullpath);
                Close();
            }
            catch (Exception ex)
            {
                Error_Handle.TipError("Error Creating File : " + ex.Message, toolTip, txtTitle);
            }
        }
コード例 #2
0
        /// <summary>
        /// Renames a file with a prefix, title, episode, and suffix into a standard format.
        /// </summary>
        /// <param name="filename">The fullpath filename.</param>
        /// <param name="prefix">The prefix for the front.</param>
        /// <param name="title">The title.</param>
        /// <param name="episode">The episode.</param>
        /// <param name="suffix">The suffix for the end.</param>
        /// <param name="newfilename">Just the filename.</param>
        /// <param name="skipped">A skipped message.</param>
        /// <returns>The fullpath filename.</returns>
        public static string RenameFile(string filename,
                                        string prefix, string title, string season, string episode, string suffix, EPFORMAT format,
                                        out string newfilename, out bool skipped)
        {
            FileInfo file         = new FileInfo(filename);
            string   destfilename = string.Empty;

            skipped = false;
            int outIgnore;

            try
            {
                if (prefix.Trim().Length >= 1)
                {
                    destfilename = '[' + prefix + ']' + ' ';
                }
                destfilename += title;

                if (episode.Trim().Length < 1)
                {
                    skipped = true;
                }
                else if (!int.TryParse(episode, out outIgnore))
                {
                    skipped = true;
                }
                else if (season.Trim().Length >= 1 && !int.TryParse(season, out outIgnore))
                {
                    skipped = true;
                }
                else
                {
                    destfilename += FileNameFormat.ToFormat(episode, season, format);
                }

                if (suffix.Trim().Length >= 1)
                {
                    destfilename += " [" + suffix + "]";
                }
                destfilename = destfilename.Replace(' ', '_');
                FixExtension(file);
                file.Refresh();
                if (!skipped)
                {
                    file.MoveTo(file.FullName.Replace(file.Name, destfilename) + file.Extension);
                }
                file.Refresh();
            }
            catch (IOException)
            {
                skipped = true;
                BetterDialog.ShowDialog("Rename Error",
                                        string.Format("Cannot Rename File: {0}\nFile Already Exists As: {1}", file.Name, destfilename),
                                        "", "", "OK", null, BetterDialog.ImageStyle.Icon);
            }
            finally
            {
                newfilename = Path.GetFileName(file.Name);
            }
            return(file.FullName);
        }