Skip to content

Commit d2f397e

Browse files
committed
EpisodeBox: Initial work on music.ini handling
While converting and renaming music, it's important to also apply tweaks at the custom music.ini files.
1 parent 3f51e73 commit d2f397e

2 files changed

Lines changed: 180 additions & 91 deletions

File tree

_common/qt-modules/episode_box/episode_box.cpp

Lines changed: 124 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -92,35 +92,7 @@ void EpisodeBox_level::buildEntriesCache()
9292
}
9393
}
9494

95-
EpisodeBox_level::EpisodeBox_level()
96-
{
97-
ftype = F_NONE;
98-
ftypeVer = 0;
99-
m_wasOverwritten = false;
100-
}
101-
102-
EpisodeBox_level::EpisodeBox_level(const EpisodeBox_level &e)
103-
{
104-
this->operator=(e);
105-
}
106-
107-
EpisodeBox_level::~EpisodeBox_level()
108-
{}
109-
110-
EpisodeBox_level &EpisodeBox_level::operator=(const EpisodeBox_level &e)
111-
{
112-
d = e.d;
113-
ftype = e.ftype;
114-
ftypeVer = e.ftypeVer;
115-
fPath = e.fPath;
116-
dataPath = e.dataPath;
117-
music_entries = e.music_entries;
118-
level_entries = e.level_entries;
119-
m_wasOverwritten = e.m_wasOverwritten;
120-
return *this;
121-
}
122-
123-
bool EpisodeBox_level::open(QString filePath)
95+
bool EpisodeBox_level::open(const QString &filePath)
12496
{
12597
fPath = filePath;
12698

@@ -154,7 +126,7 @@ bool EpisodeBox_level::open(QString filePath)
154126
return d.meta.ReadFileValid;
155127
}
156128

157-
QString EpisodeBox_level::findFileAliasCaseInsensitive(QString file)
129+
QString EpisodeBox_level::findFileAliasCaseInsensitive(const QString &file)
158130
{
159131
QDir fullPath(d.meta.path);
160132
for(MusicField &mus : music_entries)
@@ -172,7 +144,7 @@ QString EpisodeBox_level::findFileAliasCaseInsensitive(QString file)
172144
return QString();
173145
}
174146

175-
bool EpisodeBox_level::renameFile(QString oldFile, QString newFile)
147+
bool EpisodeBox_level::renameFile(const QString &oldFile, const QString &newFile)
176148
{
177149
bool modified = false;
178150

@@ -220,7 +192,7 @@ bool EpisodeBox_level::renameFile(QString oldFile, QString newFile)
220192
return modified;
221193
}
222194

223-
bool EpisodeBox_level::renameMusic(QString oldMus, QString newMus, bool isBulk)
195+
bool EpisodeBox_level::renameMusic(const QString &oldMus, const QString &newMus, bool isBulk)
224196
{
225197
bool modified = false;
226198
QDir fullPath(d.meta.path);
@@ -243,7 +215,7 @@ bool EpisodeBox_level::renameMusic(QString oldMus, QString newMus, bool isBulk)
243215
return modified;
244216
}
245217

246-
bool EpisodeBox_level::renameLevel(QString oldLvl, QString newLvl, bool isBulk)
218+
bool EpisodeBox_level::renameLevel(const QString &oldLvl, const QString &newLvl, bool isBulk)
247219
{
248220
bool modified = false;
249221
QDir fullPath(d.meta.path);
@@ -291,6 +263,8 @@ void EpisodeBox_level::save()
291263
}
292264

293265

266+
267+
294268
void EpisodeBox_world::buildEntriesCache()
295269
{
296270
music_entries.clear();
@@ -341,35 +315,8 @@ void EpisodeBox_world::buildEntriesCache()
341315
}
342316
}
343317

344-
EpisodeBox_world::EpisodeBox_world()
345-
{
346-
ftype = F_NONE;
347-
ftypeVer = 0;
348-
m_wasOverwritten = false;
349-
}
350-
351-
EpisodeBox_world::EpisodeBox_world(const EpisodeBox_world &w)
352-
{
353-
this->operator=(w);
354-
}
355-
356-
EpisodeBox_world::~EpisodeBox_world()
357-
{}
358-
359-
EpisodeBox_world &EpisodeBox_world::operator=(const EpisodeBox_world &w)
360-
{
361-
d = w.d;
362-
fPath = w.fPath;
363-
dataPath = w.dataPath;
364-
ftype = w.ftype;
365-
ftypeVer = w.ftypeVer;
366-
music_entries = w.music_entries;
367-
level_entries = w.level_entries;
368-
m_wasOverwritten = w.m_wasOverwritten;
369-
return *this;
370-
}
371318

372-
bool EpisodeBox_world::open(QString filePath)
319+
bool EpisodeBox_world::open(const QString &filePath)
373320
{
374321
fPath = filePath;
375322
FileFormats::OpenWorldFile(filePath, d);
@@ -412,7 +359,7 @@ QString EpisodeBox_world::findFileAliasCaseInsensitive(QString file)
412359
return QString();
413360
}
414361

415-
bool EpisodeBox_world::renameFile(QString oldFile, QString newFile)
362+
bool EpisodeBox_world::renameFile(const QString &oldFile, const QString &newFile)
416363
{
417364
bool modified = false;
418365
if(oldFile == fPath)
@@ -421,9 +368,12 @@ bool EpisodeBox_world::renameFile(QString oldFile, QString newFile)
421368
fPath = newFile;
422369
QString newDataPath = newFile;
423370
int dotPos = newFile.lastIndexOf(".");
371+
424372
if(dotPos > 0)
425373
newDataPath.remove(dotPos, newDataPath.size() - dotPos);
374+
426375
QDir dDir(dataPath);
376+
427377
if(dDir.exists())
428378
{
429379
if(dataPath != newDataPath)
@@ -444,20 +394,24 @@ bool EpisodeBox_world::renameFile(QString oldFile, QString newFile)
444394
}
445395
}
446396
}
397+
447398
modified |= renameMusic(oldFile, newFile, true);
448399
modified |= renameLevel(oldFile, newFile, true);
400+
449401
if(modified)
450402
{
451403
save();
452404
m_wasOverwritten = true;
453405
}
406+
454407
return modified;
455408
}
456409

457-
bool EpisodeBox_world::renameMusic(QString oldMus, QString newMus, bool isBulk)
410+
bool EpisodeBox_world::renameMusic(const QString &oldMus, const QString &newMus, bool isBulk)
458411
{
459412
bool modified = false;
460413
QDir fullPath(d.meta.path);
414+
461415
for(MusicField &mus : music_entries)
462416
{
463417
if(mus.absolutePath.compare(oldMus, Qt::CaseInsensitive) == 0)
@@ -466,15 +420,17 @@ bool EpisodeBox_world::renameMusic(QString oldMus, QString newMus, bool isBulk)
466420
modified = true;
467421
}
468422
}
423+
469424
if(!isBulk && modified)
470425
{
471426
save();
472427
m_wasOverwritten = true;
473428
}
429+
474430
return modified;
475431
}
476432

477-
bool EpisodeBox_world::renameLevel(QString oldLvl, QString newLvl, bool isBulk)
433+
bool EpisodeBox_world::renameLevel(const QString &oldLvl, const QString &newLvl, bool isBulk)
478434
{
479435
bool modified = false;
480436
QDir fullPath(d.meta.path);
@@ -516,6 +472,110 @@ void EpisodeBox_world::save()
516472
}
517473

518474

475+
476+
QString Episode_music_ini::fieldToFile(const QString &field)
477+
{
478+
QStringList f = field.split('=');
479+
480+
if(f.size() < 2)
481+
return field;
482+
483+
QString file = f[1].trimmed();
484+
485+
if(file.front() == '"')
486+
file.remove(0, 1);
487+
488+
if(file.back() == '"')
489+
file.remove(file.size() - 1, 1);
490+
491+
return file;
492+
}
493+
494+
void Episode_music_ini::updateField(QString &field, const QString &newFile)
495+
{
496+
// FIXME: Implement this!
497+
}
498+
499+
void Episode_music_ini::buildEntriesCache()
500+
{
501+
// FIXME: Implement this!
502+
}
503+
504+
bool Episode_music_ini::open(const QString &filePath)
505+
{
506+
QFile in(filePath);
507+
QFileInfo info(filePath);
508+
509+
if(!in.open(QIODevice::ReadOnly|QIODevice::Text))
510+
return false;
511+
512+
QTextStream tIn(&in);
513+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
514+
tIn.setEncoding(QStringConverter::Utf8);
515+
#else
516+
tIn.setCodec("UTF-8");
517+
#endif
518+
519+
file_lines.clear();
520+
QString line;
521+
522+
while(!tIn.atEnd())
523+
{
524+
line = tIn.readLine();
525+
file_lines.push_back(line.trimmed());
526+
}
527+
528+
in.close();
529+
530+
fPath = filePath;
531+
dataPath = info.absoluteDir().absolutePath();
532+
533+
return true;
534+
}
535+
536+
QString Episode_music_ini::findFileAliasCaseInsensitive(const QString &file)
537+
{
538+
QDir fullPath(dataPath);
539+
540+
for(MusicField &mus : music_entries)
541+
{
542+
if(mus.absolutePath.compare(file, Qt::CaseInsensitive) == 0)
543+
return fieldToFile(*(mus.field));
544+
}
545+
546+
return QString();
547+
}
548+
549+
bool Episode_music_ini::renameMusic(const QString &oldMus, const QString &newMus, bool isBulk)
550+
{
551+
// FIXME: Implement this!
552+
return false;
553+
}
554+
555+
void Episode_music_ini::save()
556+
{
557+
QFile out(fPath);
558+
559+
if(out.open(QIODevice::WriteOnly|QIODevice::Text))
560+
{
561+
QTextStream tOut(&out);
562+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
563+
tOut.setEncoding(QStringConverter::Utf8);
564+
#else
565+
tOut.setCodec("UTF-8");
566+
#endif
567+
568+
foreach(const QString &line, file_lines)
569+
tOut << line << "\n";
570+
571+
tOut.flush();
572+
out.close();
573+
}
574+
}
575+
576+
577+
578+
519579
EpisodeBox::EpisodeBox() {}
520580

521581
EpisodeBox::~EpisodeBox() {}

0 commit comments

Comments
 (0)