-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
74 lines (59 loc) · 2.57 KB
/
Program.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// See https://aka.ms/new-console-template for more information
namespace BSSFR
{
class SongInfo
{
public string? Author { get; set; }
public string? SongName { get; set; }
public string? Mapper { get; set; }
}
class Renamer
{
static void Main(string[] args)
{
string currentDir = Directory.GetCurrentDirectory();
var songDirs = Directory.EnumerateDirectories(currentDir);
foreach (string songDir in songDirs)
{
//Console.WriteLine(songDir);
SongInfo songInfo = Renamer.DatToSongInfo(songDir + "/info.dat");
string newDir = currentDir + @"\" + @songInfo.Author + " - " + @songInfo.SongName + " - " + @songInfo.Mapper + " Mapper";
//Console.WriteLine(songDir);
Console.WriteLine(newDir);
if (songDir != newDir) { Directory.Move(songDir, newDir); }
}
Console.WriteLine("press a key to quit.....");
Console.ReadKey();
}
static string RemoveInvalidChars (string stringtoformat )
{
char[] forbiddenChars = { '\\', '/', ':', '*', '?', '"', '<', '>', '|' };
foreach (char c in forbiddenChars)
{
stringtoformat = stringtoformat.Replace(c.ToString(), "");
}
return stringtoformat;
}
internal static SongInfo DatToSongInfo(string path)
{
char[] charsToTrim = { '{', '}'};
string text = System.IO.File.ReadAllText(path).Trim(charsToTrim);
string splitter = "\",";
string[] lines = text.Split(splitter);
SongInfo songInfo = new SongInfo();
string mapper = lines[4].Split(':')[1].Trim().Remove(0, 1).Trim();
if (mapper.Length == 0) { mapper = "Unknown Mapper"; }
songInfo.Mapper = RemoveInvalidChars(mapper);
//Console.WriteLine(author);
string songName = lines[1].Split(':')[1].Trim().Remove(0, 1).Trim();
//Console.WriteLine(lines[3]);
songInfo.SongName = RemoveInvalidChars(songName);
//Console.WriteLine(songName);
string author = lines[3].Split(':')[1].Trim().Remove(0, 1).Trim();
if (author.Length == 0) { author = "Unknown Author"; }
songInfo.Author = RemoveInvalidChars(author);
//Console.WriteLine(mapper);
return songInfo;
}
}
}