Skip to content

Commit

Permalink
Merge pull request #7 from qwqcode/dev
Browse files Browse the repository at this point in the history
Version 0.3.0.0
  • Loading branch information
qwqcode authored Mar 23, 2020
2 parents 39b031f + 64e2673 commit 3b158d8
Show file tree
Hide file tree
Showing 29 changed files with 2,171 additions and 465 deletions.
Binary file modified README.md
Binary file not shown.
252 changes: 199 additions & 53 deletions SubRenamer/Action.cs

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions SubRenamer/AppSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using SubRenamer.Lib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace SubRenamer
{
public class AppSettings
{
public static bool RawSubtitleBuckup
{
get { return GetBoolVal(defaultVal: true); }
set { WriteBoolVal(value); }
}

public static bool ListItemRemovePrompt
{
get { return GetBoolVal(defaultVal: true); }
set { WriteBoolVal(value); }
}

public static bool ListShowFileFullName
{
get { return GetBoolVal(defaultVal: false); }
set { WriteBoolVal(value); }
}

#region Utils
public static IniFile IniFile = new IniFile();

private static bool GetBoolVal(bool defaultVal = false, [CallerMemberName]string key = null)
{
if (string.IsNullOrWhiteSpace(key)) return defaultVal;
string defaultValStr = defaultVal ? "1" : "0";
return IniFile.Read(key, defaultValStr).Equals("1");
}

private static void WriteBoolVal(bool val, [CallerMemberName]string key = null)
{
if (string.IsNullOrWhiteSpace(key)) return;
IniFile.Write(key, val ? "1" : "0");
}
#endregion
}
}
5 changes: 5 additions & 0 deletions SubRenamer/Global.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SubRenamer
{
public class Global
{
#region 常量
public static readonly string LOG_FILENAME = Path.Combine(Application.StartupPath, $"{Program.GetAppName()}.log");
public static readonly List<string> VideoExts = new List<string> { ".mkv", ".mp4", "flv", ".avi", ".mov", ".rmvb", ".wmv", ".mpg", ".avs" };
public static readonly List<string> SubExts = new List<string> { ".srt", ".ass", ".ssa", ".sub", ".idx" };
#endregion

/// <summary>
Expand Down
55 changes: 55 additions & 0 deletions SubRenamer/Lib/IniFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace SubRenamer.Lib
{
public class IniFile
{
string Path;
public static string APP_NAME = Assembly.GetExecutingAssembly().GetName().Name;

[DllImport("kernel32", CharSet = CharSet.Ansi)]
static extern long WritePrivateProfileString(string Section, string Key, string Value, string FilePath);

[DllImport("kernel32", CharSet = CharSet.Ansi)]
static extern int GetPrivateProfileString(string Section, string Key, string Default, StringBuilder RetVal, int Size, string FilePath);

public IniFile(string IniPath = null)
{
Path = new FileInfo(IniPath ?? APP_NAME + ".ini").FullName.ToString();
}

public string Read(string Key, string DefaultVal = "", string Section = null)
{
var RetVal = new StringBuilder(255);
GetPrivateProfileString(Section ?? APP_NAME, Key, DefaultVal, RetVal, 255, Path);
return RetVal.ToString();
}

public void Write(string Key, string Value, string Section = null)
{
WritePrivateProfileString(Section ?? APP_NAME, Key, Value, Path);
}

public void DeleteKey(string Key, string Section = null)
{
Write(Key, null, Section ?? APP_NAME);
}

public void DeleteSection(string Section = null)
{
Write(null, null, Section ?? APP_NAME);
}

public bool KeyExists(string Key, string Section = null)
{
return Read(Key, Section).Length > 0;
}
}
}
14 changes: 14 additions & 0 deletions SubRenamer/Lib/Ui.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SubRenamer.Lib
{
public static class Ui
{

}
}
30 changes: 27 additions & 3 deletions SubRenamer/Utils.cs → SubRenamer/Lib/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
using System;
using Microsoft.WindowsAPICodePack.Dialogs;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static SubRenamer.Global;

namespace SubRenamer
namespace SubRenamer.Lib
{
public static class Utils
class Utils
{
/// <summary>
/// 输入对话框
Expand Down Expand Up @@ -37,5 +40,26 @@ public static string InputDialog(string text, string caption)

return prompt.ShowDialog() == DialogResult.OK ? textBox.Text : "";
}

public static void OpenFile(AppFileType FileType, Action<string, AppFileType> opened)
{
using (var fbd = new CommonOpenFileDialog())
{
if (FileType == AppFileType.Video)
fbd.Filters.Add(new CommonFileDialogFilter("视频文件", string.Join(";", VideoExts.ToList())));
else if (FileType == AppFileType.Sub)
fbd.Filters.Add(new CommonFileDialogFilter("字幕文件", string.Join(";", SubExts.ToList())));

fbd.Filters.Add(new CommonFileDialogFilter("视频或字幕文件", string.Join(";", VideoExts.Concat(SubExts).ToList())));
fbd.Filters.Add(new CommonFileDialogFilter("任何类型", "*.*"));
var result = fbd.ShowDialog();

if (result == CommonFileDialogResult.Ok && !string.IsNullOrWhiteSpace(fbd.FileName))
{
var fileName = Path.GetFileName(fbd.FileName.Trim());
opened(fileName, FileType);
}
}
}
}
}
42 changes: 40 additions & 2 deletions SubRenamer/MainForm.Designer.cs

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

Loading

0 comments on commit 3b158d8

Please sign in to comment.