-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmlrenamer.cpp
91 lines (77 loc) · 2.44 KB
/
xmlrenamer.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
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 "xmlrenamer.h"
XmlRenamer::XmlRenamer() : Module("XmlRenamer")
{
}
void XmlRenamer::numToReal(QString dirPath)
{
QDir xmldir(dirPath);
QStringList filter("*.xml");
QFileInfoList dirlist = xmldir.entryInfoList(filter);
qint32 i, j;
for (i = 0; i < dirlist.size(); i++)
{
QFileInfo fileInfo = dirlist.at(i);
QFile xmlFile(fileInfo.filePath());
char buffer[100];
char *ptr = buffer;
xmlFile.open(QFile::ReadOnly);
xmlFile.read((char*)&buffer, 100);
xmlFile.close();
//locate 'name' property
for (j = 0; j < 94; j++)
{
if (qstrncmp((const char*)"name=", ptr, 5) == 0)
{
break;
}
ptr++;
}
if (j == 62) //that should be far enough
{
fatalExit("Couldn't find script name");
}
ptr += 6; //advance over: name="
//get name length
for (j = 0; j < 32; j++)
{
if (qstrncmp((const char*)"\"", ptr + j, 1) == 0)
{
break;
}
}
if (j == 32)
{
fatalExit("Name property seems too long");
}
ptr[j] = 0; //Null-terminate the string
QString xmlNewName = QString().sprintf("%s.xml", ptr);
printf("%s = %s\n", fileInfo.filePath().toAscii().data(), xmlNewName.toAscii().data());
if (xmldir.rename(fileInfo.filePath(), xmlNewName) != 1)
{
printf("Failed to rename %s\n", fileInfo.filePath().toAscii().data());
}
}
}
void XmlRenamer::realToNum(QString dirPath)
{
QDir xmldir(dirPath);
QStringList filter("*.xml");
QStringList dirlist = xmldir.entryList(filter, QDir::Files, QDir::Name);
qint32 i;
for (i = 0; i < dirlist.size(); i++)
{
QString xmlNewName = QString().sprintf("file_%04d.xml", i);
printf("%s = %s\n", xmlNewName.toAscii().data(), dirlist.at(i).toAscii().data());
if (xmldir.rename(dirlist.at(i), xmlNewName) != 1)
{
printf("Failed to rename %s\n", dirlist.at(i).toAscii().data());
}
}
}