-
Notifications
You must be signed in to change notification settings - Fork 0
/
scfrenamer.cpp
63 lines (53 loc) · 1.84 KB
/
scfrenamer.cpp
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
/*
This file is a part of the
Amagami PS2 Translation Project
You may feel free to use this code if you want so.
We provide no guarantee that this code is working,
useful or anything else. Use it at your own risk.
*/
#include "scfrenamer.h"
ScfRenamer::ScfRenamer() : Module("ScfRenamer")
{
}
void ScfRenamer::numToReal(QString dirPath)
{
QDir scfdir(dirPath);
QStringList filter("*.scf");
QFileInfoList dirlist = scfdir.entryInfoList(filter);
qint32 i;
quint16 nameLen;
for (i = 0; i < dirlist.size(); i++)
{
QFileInfo fileInfo = dirlist.at(i);
QFile scfFile(fileInfo.filePath());
char temp[32]; //dammit Qt... i can't think
scfFile.open(QFile::ReadOnly);
scfFile.seek(6);
scfFile.read((char*)&nameLen, 2);
scfFile.read(temp, nameLen);
scfFile.close();
temp[nameLen] = 0; //Null-terminate the string
QString scfNewName = QString().sprintf("%s.scf", temp);
printf("%s = %s\n", fileInfo.filePath().toAscii().data(), scfNewName.toAscii().data());
if (scfdir.rename(fileInfo.filePath(), scfNewName) != 1)
{
printf("Failed to rename %s\n", fileInfo.filePath().toAscii().data());
}
}
}
void ScfRenamer::realToNum(QString dirPath)
{
QDir scfdir(dirPath);
QStringList filter("*.scf");
QStringList dirlist = scfdir.entryList(filter, QDir::Files, QDir::Name);
qint32 i;
for (i = 0; i < dirlist.size(); i++)
{
QString scfNewName = QString().sprintf("file_%04d.scf", i);
printf("%s = %s\n", scfNewName.toAscii().data(), dirlist.at(i).toAscii().data());
if (scfdir.rename(dirlist.at(i), scfNewName) != 1)
{
printf("Failed to rename %s\n", dirlist.at(i).toAscii().data());
}
}
}