Skip to content

Commit

Permalink
bug fix: make a duplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
Anime4000 committed Dec 25, 2017
1 parent a89e756 commit d4794ab
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 59 deletions.
5 changes: 3 additions & 2 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Version 7.7 (Prism Ark)
-----------------------
[new] Enable/Disable verbose log
[fixed] Version detection always return true
[fixed] Block save blank project
[fixed] Broken version detection that always return true.
[fixed] Prevent save a blank project.
[fixed] Make a duplicate file if exist. example: File Name (1).mkv

Version 7.6 (Soul Heart)
------------------------
Expand Down
68 changes: 48 additions & 20 deletions ifme/Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,44 +307,72 @@ internal static bool IsValidPath(string FilePath)
try
{
Path.GetFileName(FilePath);

Path.GetPathRoot(FilePath);
Path.Combine(FilePath);
return Path.IsPathRooted(FilePath);
}
catch (Exception)
catch (Exception ex)
{
ConsoleEx.Write(LogLevel.Error, $"Given path is wrong: {ex.Message}\n");

return false;
}
}

internal static string NewFilePath(string SaveDir, string FilePath, string Ext)
internal static string NewFilePath(string SaveFolder, string FilePath, string FileExt)
{
// base
var filename = Path.GetFileNameWithoutExtension(FilePath);
var name = Path.GetFileNameWithoutExtension(FilePath);
var ext = FileExt.Contains(".") ? FileExt : "." + FileExt;
var prefix = string.Empty;
var postfix = string.Empty;

var time = $"{DateTime.Now:yyyyMMdd_HHmmss}";

// prefix
if (Properties.Settings.Default.FileNamePrefixType == 1)
prefix = $"[{DateTime.Now:yyyyMMdd_HHmmss}] ";
else if (Properties.Settings.Default.FileNamePrefixType == 2)
prefix = Properties.Settings.Default.FileNamePrefix;
switch (Properties.Settings.Default.FileNamePrefixType)
{
case 1:
prefix = $"[{time}] ";
break;
case 2:
prefix = Properties.Settings.Default.FileNamePrefix;
break;
default:
break;
}

// postfix
switch (Properties.Settings.Default.FileNamePostfixType)
{
case 1:
postfix = Properties.Settings.Default.FileNamePostfix;
break;
default:
break;
}

// Check path is valid and not UNC
if (IsValidPath(SaveFolder))
{
var count = 0;
var filename = string.Empty;

// postfix
if (Properties.Settings.Default.FileNamePostfixType == 1)
postfix = Properties.Settings.Default.FileNamePostfix;
do
{
if (count == 0)
filename = $"{prefix}{name}{postfix}{ext}";
else
filename = $"{prefix}{name}{postfix} ({count}){ext}";

// use save folder
filename = Path.Combine(SaveDir, $"{prefix}{filename}{postfix}{Ext}");
count++;

// check SaveDir is valid
if (!IsValidPath(filename))
filename = Path.Combine(Path.GetDirectoryName(FilePath), $"{prefix}{filename}{postfix}{Ext}");
} while (File.Exists(Path.Combine(SaveFolder, filename)));

// if exist, make a duplicate
if (File.Exists(filename))
filename = Path.Combine(Path.GetDirectoryName(filename), $"{prefix}{filename}{postfix} NEW{Ext}");
return Path.Combine(SaveFolder, filename);
}

return filename;
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos), $"{prefix}{name}{postfix} [{time}]{ext}");
}
}
}
40 changes: 40 additions & 0 deletions ifme/Version.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Linq;
using System.Reflection;
using System.Diagnostics;

namespace ifme
{
public class Version
{
public static string ThisApp { get; } = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;

public static bool IsLatest(string Target)
{
if (!Target.Contains('.'))
return false;

var check = Target.Split('.');
var source = ThisApp.Split('.');

if (check.Length < 1)
return false;

if (source.Length < 1)
return false;

if (source.Length == check.Length)
{
int.TryParse(source[0], out int s1);
int.TryParse(source[1], out int s2);

int.TryParse(check[0], out int c1);
int.TryParse(check[1], out int c2);

if (s1 >= c1 && s2 >= c2)
return true;
}

return false;
}
}
}
1 change: 1 addition & 0 deletions ifme/frmAbout.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions ifme/frmAbout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ private void frmAbout_Load(object sender, EventArgs e)
InitializeUX();
}

private void lblDonatePP_Click(object sender, EventArgs e)
private void frmAbout_Shown(object sender, EventArgs e)
{
// Lock size
MinimumSize = new Size(Width, Height);
MaximumSize = new Size(Width, Height);
}

private void lblDonatePP_Click(object sender, EventArgs e)
{
Process.Start("https://paypal.me/anime4000/10");
lblDonatePP.ForeColor = Color.Purple;
Expand All @@ -38,5 +45,5 @@ private void lblDonateETH_Click(object sender, EventArgs e)
Clipboard.SetText("0xAdd9ba89B601e7CB5B3602643337B9db8c90EFe0");
lblDonateETH.ForeColor = Color.Purple;
}
}
}
}
2 changes: 1 addition & 1 deletion ifme/frmMain.Method.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private void CheckVersion()
if (string.IsNullOrEmpty(data[0]))
return;

if (string.Equals(Application.ProductVersion, data[0]))
if (Version.IsLatest(data[0]))
return; // simple version check

new frmCheckUpdate(data[1]).ShowDialog();
Expand Down
5 changes: 4 additions & 1 deletion ifme/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,10 @@ private void tsmiEncodingPresetSaveAs_Click(object sender, EventArgs e)

private void txtFolderOutput_TextChanged(object sender, EventArgs e)
{
Get.FolderSave = txtFolderOutput.Text;
if (Get.IsValidPath(txtFolderOutput.Text))
Get.FolderSave = txtFolderOutput.Text;
else
txtFolderOutput.Text = Get.FolderSave;
}

private void btnBrowseFolderOutput_Click(object sender, EventArgs e)
Expand Down
77 changes: 44 additions & 33 deletions ifme/frmOption.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Collections.Generic;

namespace ifme
Expand Down Expand Up @@ -30,7 +29,11 @@ private void cboLanguage_SelectedIndexChanged(object sender, EventArgs e)
{
var l = Language.List[id];

lblLanguageAuthor.Text = $"{l.AuthorName} ({l.AuthorEmail})\n{l.AuthorProfile}";
var name = l.AuthorName;
var email = (string.IsNullOrEmpty(l.AuthorEmail) ? "" : $"({l.AuthorEmail})");
var profile = l.AuthorProfile;

lblLanguageAuthor.Text = $"{name} {email}\n{profile}";
}
}
}
Expand Down Expand Up @@ -58,37 +61,45 @@ private void btnTempPath_Click(object sender, EventArgs e)

private void btnOk_Click(object sender, EventArgs e)
{
// Save all
// General
Properties.Settings.Default.Language = ((KeyValuePair<string, string>)cboLanguage.SelectedItem).Key;
Properties.Settings.Default.TempDir = txtTempPath.Text;
Properties.Settings.Default.FileNamePrefix = txtNamePrefix.Text;
Properties.Settings.Default.FileNamePostfix = txtNamePostfix.Text;

Properties.Settings.Default.Verbose = chkVerbose.Checked;

if (rdoNamePrefixCustom.Checked)
Properties.Settings.Default.FileNamePrefixType = 2;
else if (rdoNamePrefixDateTime.Checked)
Properties.Settings.Default.FileNamePrefixType = 1;
else
Properties.Settings.Default.FileNamePrefixType = 0;

if (rdoNamePostfixNone.Checked)
Properties.Settings.Default.FileNamePostfixType = 0;
else
Properties.Settings.Default.FileNamePostfixType = 1;

// Encoding
if (rdoFFmpeg32.Checked)
Properties.Settings.Default.FFmpegArch = 32;
else
Properties.Settings.Default.FFmpegArch = 64;

Properties.Settings.Default.FrameCountOffset = (int)nudFrameCountOffset.Value;

// Final
Properties.Settings.Default.Save();
try
{
// Save all
// General
Properties.Settings.Default.Language = ((KeyValuePair<string, string>)cboLanguage.SelectedItem).Key;
Properties.Settings.Default.TempDir = txtTempPath.Text;
Properties.Settings.Default.FileNamePrefix = txtNamePrefix.Text;
Properties.Settings.Default.FileNamePostfix = txtNamePostfix.Text;

Properties.Settings.Default.Verbose = chkVerbose.Checked;

if (rdoNamePrefixCustom.Checked)
Properties.Settings.Default.FileNamePrefixType = 2;
else if (rdoNamePrefixDateTime.Checked)
Properties.Settings.Default.FileNamePrefixType = 1;
else
Properties.Settings.Default.FileNamePrefixType = 0;

if (rdoNamePostfixNone.Checked)
Properties.Settings.Default.FileNamePostfixType = 0;
else
Properties.Settings.Default.FileNamePostfixType = 1;

// Encoding
if (rdoFFmpeg32.Checked)
Properties.Settings.Default.FFmpegArch = 32;
else
Properties.Settings.Default.FFmpegArch = 64;

Properties.Settings.Default.FrameCountOffset = (int)nudFrameCountOffset.Value;

// Final
Properties.Settings.Default.Save();
}
catch (Exception ex)
{
ConsoleEx.Write(LogLevel.Error, $"Configuration broken, resetting... [ {ex.Message} ]");
Properties.Settings.Default.Reset();
}
}
}
}
1 change: 1 addition & 0 deletions ifme/ifme.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
<Compile Include="ProcessManager.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Version.cs" />
<EmbeddedResource Include="frmAbout.resx">
<DependentUpon>frmAbout.cs</DependentUpon>
</EmbeddedResource>
Expand Down

0 comments on commit d4794ab

Please sign in to comment.