/
AddDateProcessor.cs
41 lines (38 loc) · 1.48 KB
/
AddDateProcessor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Daramkun.DaramRenamer.Processors.Date
{
[Serializable]
public class AddDateProcessor : IProcessor
{
public string Name => "process_add_date";
public bool CannotMultithreadProcess => false;
[Localized ( "add_date_type", 0 )]
public DateType Type { get; set; } = DateType.CreationDate;
[Localized ( "add_date_format", 1 )]
public string Format { get; set; } = "yyMMdd";
[Localized ( "add_date_pos", 2 )]
public OnePointPosition Position { get; set; } = OnePointPosition.EndPoint;
public bool Process ( FileInfo file )
{
string fn = Path.GetFileNameWithoutExtension ( file.ChangedFilename );
string ext = Path.GetExtension ( file.ChangedFilename );
string date;
switch ( Type)
{
case DateType.CreationDate: date = File.GetCreationTime ( file.OriginalFullPath ).ToString ( Format ); break;
case DateType.ModifiedDate: date = File.GetLastWriteTime ( file.OriginalFullPath ).ToString ( Format ); break;
case DateType.AccessedDate: date = File.GetLastAccessTime ( file.OriginalFullPath ).ToString ( Format ); break;
case DateType.Now: date = DateTime.Now.ToString ( Format ); break;
default: return false;
}
file.ChangedFilename = Position == OnePointPosition.StartPoint ? $"{date}{fn}{ext}" :
( Position == OnePointPosition.EndPoint ? $"{fn}{date}{ext}" : $"{date}{fn}{date}{ext}" );
return true;
}
}
}