Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
senjyouhara committed Apr 28, 2023
1 parent ebb330a commit f8ffd40
Show file tree
Hide file tree
Showing 28 changed files with 87 additions and 168 deletions.
Binary file modified .vs/ProjectEvaluation/senjyouhara.main.metadata.v5.2
Binary file not shown.
Binary file modified .vs/ProjectEvaluation/senjyouhara.main.projects.v5.2
Binary file not shown.
Binary file modified .vs/Senjyouhara.Main/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .vs/Senjyouhara.Main/v17/.futdcache.v2
Binary file not shown.
4 changes: 2 additions & 2 deletions Senjyouhara.Main/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ protected override void Configure()
container.Singleton<IWindowManager, WindowManager>();
container.Singleton<IEventAggregator, EventAggregator>();

container.PerRequest<TestViewModel>();
container.PerRequest<ShellViewModel>();
container.PerRequest<StartLoadingViewModel>();
container.PerRequest<MainViewModel>();
Expand All @@ -42,7 +41,8 @@ protected override async void OnStartup(object sender, StartupEventArgs e)
#if (DEBUG)
await DisplayRootViewForAsync<ShellViewModel>();
#else
await DisplayRootViewForAsync<StartLoadingViewModel>();
await DisplayRootViewForAsync<ShellViewModel>();
//await DisplayRootViewForAsync<StartLoadingViewModel>();
#endif
}

Expand Down
21 changes: 21 additions & 0 deletions Senjyouhara.Main/Comparer/FileNameComparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Senjyouhara.Main.Comparer
{

public class FileComparer : IComparer<string>
{
//引入API文件:Shlwapi.dlL
[DllImport("shlwapi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int StrCmpLogicalW(String x, String y);
public int Compare(string str_1_ForCompare, string str_2_ForCompare)
{
return StrCmpLogicalW(str_1_ForCompare, str_2_ForCompare);
}
}
}
2 changes: 1 addition & 1 deletion Senjyouhara.Main/Config/UpdateConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class UpdateDataEntity
}

// 是否开启自动更新
public static bool IsEnableUpdate = true;
public static bool IsEnableUpdate = false;
// 是否强制更新,如果为否则可以用户取消更新
public static bool IsForceUpdate = false;
// 下载更新文件路径
Expand Down
8 changes: 8 additions & 0 deletions Senjyouhara.Main/Senjyouhara.Main.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<UseWPF>true</UseWPF>
<LangVersion>10.0</LangVersion>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<AssemblyName>BatchRename</AssemblyName>
<ApplicationIcon>icon.ico</ApplicationIcon>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand All @@ -27,9 +29,14 @@
</PropertyGroup>

<ItemGroup>
<None Remove="icon.png" />
<None Remove="Resources\loading.png" />
</ItemGroup>

<ItemGroup>
<Content Include="icon.ico" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Caliburn.Micro" Version="4.0.212" />
<PackageReference Include="HandyControl" Version="3.4.0" />
Expand All @@ -43,6 +50,7 @@
<Reference Include="System.ComponentModel.DataAnnotations" />
</ItemGroup>
<ItemGroup>
<Resource Include="icon.png" />
<Resource Include="Resources\loading.png">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Resource>
Expand Down
14 changes: 7 additions & 7 deletions Senjyouhara.Main/ViewModels/GenerateRuleViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public class FormData : IDataErrorInfo

public bool IsValid()
{
var list = AppendNumberList.Where(v => v.IsValid()).ToList();
var list = AppendNumberList.Where(v => v.IsValid() == false).ToList();

var result = Validator.TryValidateObject(
this, new ValidationContext(this, null, null), new List<ValidationResult>(), true);

Expand All @@ -122,10 +122,10 @@ public bool IsValid()
return result;
}

//if (list.Count > 0)
//{
// return false;
//}
if (list.Count > 0)
{
return false;
}

return true;
}
Expand Down Expand Up @@ -249,7 +249,7 @@ public void OnOk()

public void OnCancel()
{
_eventAggregator.PublishOnUIThreadAsync(null);
_eventAggregator.PublishOnUIThreadAsync("cancel");
TryCloseAsync();
CloseCommand?.Execute();
}
Expand Down
128 changes: 37 additions & 91 deletions Senjyouhara.Main/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Senjyouhara.Common.Exceptions;
using Senjyouhara.Common.Log;
using Senjyouhara.Common.Utils;
using Senjyouhara.Main.Comparer;
using Senjyouhara.Main.Config;
using Senjyouhara.Main.models;
using Senjyouhara.Main.Views;
Expand Down Expand Up @@ -64,15 +65,16 @@ class Dewater
}

[AddINotifyPropertyChangedInterface]
public class MainViewModel : Screen, IHandle<FormData>
public class MainViewModel : Screen, IHandle<FormData>, IHandle<string>
{
public bool IsSubMergeVideo { get; set; } = true;
public string Tips { get; set; }
public ObservableCollection<FileNameItem> FileNameItems { get; set; } = new ObservableCollection<FileNameItem>();

private GenerateRuleViewModel generateRuleViewModel;
private FormData formData;
public string FileSortPattern { get; set; } = "(\\s[0-9]+\\.[0-9]+\\s|\\s[0-9]+\\s)|(\\[[0-9]+\\.[0-9]+\\]|\\[[0-9]+\\])";
public string FileSortPattern { get; set; } = "(\\s[0-9]+\\.[0-9]+\\s|\\s[0-9]+\\s)|(\\[[0-9]+\\.[0-9]+\\]|\\[[0-9]+\\])|(^[0-9]+$|[0-9]+\\.[0-9]+$)";
public string SubFileSortPattern { get; set; } = "(\\s[0-9]+\\.[0-9]+\\s|\\s[0-9]+\\s)|(\\[[0-9]+\\.[0-9]+\\]|\\[[0-9]+\\])|(^[0-9]+$|[0-9]+\\.[0-9]+$)";

[OnChangedMethod(nameof(FileNameItemsHandle))]
public string Rename { get; set; } = string.Empty;
Expand All @@ -91,7 +93,6 @@ private void FileNameItemsHandle()

if (otherList.Count > 0)
{

var otherCount = string.IsNullOrWhiteSpace(formData?.FirstNumber) ? 1 : (int.Parse(formData?.FirstNumber));
otherCount *= 10;

Expand Down Expand Up @@ -140,16 +141,16 @@ private void FileNameItemsHandle()
Count *= 10;
for (int i = 0; i < subList.Count; i++)
{
var prevItemNumber = "";
var prevlist = i > 0 ? PatternUtil.GetPatternResult(@$"{FileSortPattern}", subList[i - 1].FileName) : new List<string>();
var prevItemNumber = string.Empty;
var prevlist = i > 0 ? PatternUtil.GetPatternResult(@$"{SubFileSortPattern}", subList[i - 1].FileName) : new List<string>();
if (prevlist.Count > 0)
{
prevItemNumber = prevlist[0];
}

var itemNumber = "";
var itemNumber = string.Empty;
var item = subList[i];
var list = PatternUtil.GetPatternResult(@$"{FileSortPattern}", item.FileName);
var list = PatternUtil.GetPatternResult(@$"{SubFileSortPattern}", item.FileName);
if (list.Count > 0)
{
itemNumber = list[0];
Expand All @@ -166,6 +167,7 @@ private void FileNameItemsHandle()
{
if (name.IndexOf("#") != -1)
{
// 根据文件数量获取前面填充0数量
var count = subList.Count.ToString();
var tmp = count.Substring(0, count.Length - (i + 1).ToString().Length);
var DigitsNumber = string.IsNullOrWhiteSpace(formData?.DigitsNumber) ? tmp.Length : int.Parse(formData?.DigitsNumber);
Expand All @@ -180,7 +182,6 @@ private void FileNameItemsHandle()
name = name.Replace("#", $"{index.PadLeft(DigitsNumber, '0')}{(string.IsNullOrWhiteSpace(select.DecimalNumber) ? string.Empty : '.' + select.DecimalNumber)}");
}
}

}
} else
{
Expand All @@ -206,21 +207,9 @@ public MainViewModel(IEventAggregator eventAggregator, IWindowManager windowMana
//Test();
//Test2();
generateRuleViewModel = new(_eventAggregator);

//Application.Current.Dispatcher.BeginInvoke((() => {
// var grid = new Grid();
// var text = new TextBlock();
// text.Text = "asdhsakdhkasdsad";
// grid.Children.Add(text) ;
// MessageBoxHelper.Ask("叼毛开发者抛出了一个异常,请问您要跳转百度帮开发者解决一下这个问题吗?", "系统提示", callback =>
// {
// if (callback == MessageBoxResult.OK)
// {
// }
// });
//}));

//AddUpdateModal();
formData= new FormData();
formData.AppendNumberList.Add(new AppendNumber { DecimalNumber = "", SerialNumber = "" });
AddUpdateModal();

}

Expand Down Expand Up @@ -351,7 +340,7 @@ private void Test()

public void SelectFileHandle()
{
Tips = "";
Tips = string.Empty;
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = "c:\\desktop"; //初始的文件夹
openFileDialog.Filter = "所有文件(*.*)|*.*";//在对话框中显示的文件类型
Expand All @@ -367,7 +356,7 @@ public void SelectFileHandle()

public void ClearListHandle()
{
Tips = "";
Tips = string.Empty;
FileNameItems.Clear();
}

Expand All @@ -389,9 +378,9 @@ private void AddFilesHandle(List<string> files)
OriginFileName = v.Name.LastIndexOf(".") >= 0 ? v.Name.Substring(0, v.Name.LastIndexOf(".")) : v.Name,
FileName = v.Name.LastIndexOf(".") >= 0 ? v.Name.Substring(0, v.Name.LastIndexOf(".")) : v.Name,
FilePath = v.FullName,
PreviewFileName = "",
SubtitleFileName = "",
SuffixName = v.Name.LastIndexOf(".") >= 0 ? v.Name.Substring(v.Name.LastIndexOf(".") + 1) : ""
PreviewFileName = string.Empty,
SubtitleFileName = string.Empty,
SuffixName = v.Name.LastIndexOf(".") >= 0 ? v.Name.Substring(v.Name.LastIndexOf(".") + 1) : string.Empty
});
});

Expand All @@ -407,59 +396,54 @@ private void AddFilesHandle(List<string> files)
{
var key = groupItem.Key;
var groupList = groupItem.ToList();
groupList.Sort(MySort);
//groupList.Sort(MySort);
groupList = groupList.OrderBy(f => f.FileName, new FileComparer()).ToList();
sortList = sortList.Concat(groupList).ToList();
}

Debug.WriteLine(group);


if (IsSubMergeVideo)
{

try
{

var subList = sortList.Where(v => SUB_FILE_SUBFIX_LIST.Where(s => s.Trim().ToLower().Equals(v.SuffixName)).FirstOrDefault() != null).ToList();
var otherList = sortList.Where(v => !subList.Contains(v)).ToList();

var subSortList = subList.OrderBy(f => f.FileName, new FileComparer()).ToList();
var newList = new List<FileNameItem>();
foreach (var item in otherList)
{
// 如果为视频文件
if (VIDEO_SUBFIX_LIST.Contains(item.SuffixName.ToLower()))
{
newList.Add(item);
var FilterSub = subList.Where(v =>
// 寻找视频文件对应的字幕
var FilterSub = subSortList.Where(v =>
{
var matchesA = PatternUtil.GetPatternResult(@$"{FileSortPattern}", item.FileName);
var matchesB = PatternUtil.GetPatternResult(@$"{FileSortPattern}", v.FileName);

var matchesB = PatternUtil.GetPatternResult(@$"{SubFileSortPattern}", v.FileName);
if (matchesA.Count < matchesB.Count)
{
(matchesA, matchesB) = (matchesB, matchesA);
}

for (int i = 0; i < matchesA.Count; i++)
{

var aValue = matchesA[i].Replace(" ", "").Replace("[", "").Replace("]", "");

var bValue = "";

var aValue = matchesA[i];
var bValue = string.Empty;
if (matchesB[i] != null)
{
bValue = matchesB[i];
}

bValue = bValue.Replace(" ", "").Replace("[", "").Replace("]", "");

Debug.WriteLine($"aValue : {aValue}, bValue : {bValue}");

if (string.IsNullOrEmpty(bValue))
{
break;
}
if (aValue.Equals(bValue)) return true;
}

return false;
}).ToList();
if (FilterSub.Count > 0)
Expand Down Expand Up @@ -519,7 +503,7 @@ public void RenameFileHandle()
item.FilePath = item.PreviewFilePath;
item.FileName = item.PreviewFileName;
item.OriginFileName = item.FileName;
item.SuffixName = item.FileName.LastIndexOf(".") >= 0 ? item.FileName.Substring(item.FileName.LastIndexOf(".") + 1) : "";
item.SuffixName = item.FileName.LastIndexOf(".") >= 0 ? item.FileName.Substring(item.FileName.LastIndexOf(".") + 1) : string.Empty;
item.PreviewFileName = "成功!";
});
Thread.Sleep(80);
Expand Down Expand Up @@ -547,46 +531,6 @@ public void RenameFileHandle()
});
}

private int MySort (FileNameItem a, FileNameItem b)
{
var matchesA = PatternUtil.GetPatternResult(@$"{FileSortPattern}", a.FileName);
var matchesB = PatternUtil.GetPatternResult(@$"{FileSortPattern}", b.FileName);


if (matchesA.Count < matchesB.Count)
{
(matchesA, matchesB) = (matchesB, matchesA);
}

for (int i = 0; i < matchesA.Count; i++)
{
var aValue = matchesA[i].Replace(" ", "").Replace("[", "").Replace("]", "");

var bValue = "";

if (!string.IsNullOrEmpty(matchesB[i]))
{
bValue = matchesB[i];
}
else
{
break;
}

bValue = bValue?.Replace(" ", "").Replace("[", "").Replace("]", "");
Log.Info($"aValue : {aValue}, bValue : {bValue}");
if (aValue == bValue) continue;

int aDouble = int.Parse((double.Parse(aValue) * 100).ToString());
int bDouble = int.Parse((double.Parse(bValue) * 100).ToString());
Log.Info($"aDouble : {aDouble}, bDouble : {bDouble}");

return aDouble - bDouble;
}

return -1;
}

public void OnListViewDrop(object sender, DragEventArgs e)
{

Expand Down Expand Up @@ -714,17 +658,19 @@ public Task HandleAsync(FormData message, CancellationToken cancellationToken)
{
return Task.Run(() =>
{
if(message == null)
{
formData = new FormData();
} else
{
formData = JSONUtil.ToData<FormData>(JSONUtil.ToJSON(message));
FileNameItemsHandle();
}
});

}

public Task HandleAsync(string message, CancellationToken cancellationToken)
{
return Task.Run(() =>
{

});
}
}

internal static class Utils
Expand Down
Loading

0 comments on commit f8ffd40

Please sign in to comment.