Skip to content

Commit

Permalink
Improve magic2snes ui part
Browse files Browse the repository at this point in the history
  • Loading branch information
Skarsnik committed Sep 30, 2018
1 parent 27231a8 commit 8360eb6
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 9 deletions.
70 changes: 66 additions & 4 deletions appui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,49 @@ void AppUi::onMagic2SnesMenuTriggered(QAction *action)
}


static bool searchForQUsb2snesEntry(QString qmlFile)
{
QFile f(qmlFile);
if (f.open(QIODevice::Text | QIODevice::ReadOnly))
{
while (true)
{
QByteArray line = f.readLine();
if (line.isEmpty())
return false;
if (line.indexOf("USB2Snes") != -1)
return true;
}
}
return false;
}

static QString searchWindowTitle(QString qmlFile)
{
QFile f(qmlFile);
sDebug() << "Searching in " << qmlFile;
if (f.open(QIODevice::Text | QIODevice::ReadOnly))
{
while (true)
{
QByteArray line = f.readLine();
if (line.isEmpty())
break;
if (line.indexOf("windowTitle") != -1)
{
sDebug() << line;
QRegExp exp("windowTitle\\s*\\:\\s*\"(.+)\"");
if (exp.indexIn(line) != -1)
{
sDebug() << "Found : " << exp.cap(1);
return exp.cap(1);
}
}
}
}
return QString();
}

void AppUi::addMagic2SnesFolder(QString path)
{
sDebug() << "Adding magic2snes qml path " << path;
Expand All @@ -218,11 +261,30 @@ void AppUi::addMagic2SnesFolder(QString path)
magic2SnesMenu->addSeparator();
auto fil = exDir.entryInfoList(QStringList() << "*.qml");
foreach (QFileInfo efi, fil)
magic2SnesMenu->addAction(efi.fileName())->setData(efi.absoluteFilePath());
if (fi.baseName() == "examples")
magic2SnesMenu->addAction("SMAlttp tracker")->setData(path + "/smalttptracker/smalttpautotracker.qml");
{
QString wTitle = searchWindowTitle(efi.absoluteFilePath());
if (wTitle.isEmpty())
magic2SnesMenu->addAction(efi.fileName())->setData(efi.absoluteFilePath());
else
magic2SnesMenu->addAction(wTitle)->setData(efi.absoluteFilePath());
}
fil = exDir.entryInfoList(QDir::NoDotAndDotDot | QDir::Dirs);
foreach(QFileInfo efi, fil)
{
auto filI = QDir(efi.absoluteFilePath()).entryInfoList(QStringList() << "*.qml");
foreach (QFileInfo qmlFI, filI)
if (searchForQUsb2snesEntry(qmlFI.absoluteFilePath()))
{
QString wTitle = searchWindowTitle(qmlFI.absoluteFilePath());
if (wTitle.isEmpty())
magic2SnesMenu->addAction(qmlFI.fileName())->setData(qmlFI.absoluteFilePath());
else
magic2SnesMenu->addAction(wTitle)->setData(qmlFI.absoluteFilePath());
}
}
}


void AppUi::handleMagic2Snes(QString path)
{
magic2SnesMenu = menu->addMenu(QIcon(":/img/magic2snesicon.png"), "Magic2Snes");
Expand All @@ -232,7 +294,7 @@ void AppUi::handleMagic2Snes(QString path)
connect(magic2SnesMenu, SIGNAL(triggered(QAction*)), this, SLOT(onMagic2SnesMenuTriggered(QAction*)));
QFileInfo fi(path);
QString examplePath = fi.absoluteFilePath() + "/examples";
QString scriptPath = fi.absolutePath() + "/scripts";
QString scriptPath = fi.absoluteFilePath() + "/scripts";
if (QFile::exists(examplePath))
addMagic2SnesFolder(examplePath);
if (QFile::exists(scriptPath))
Expand Down
10 changes: 5 additions & 5 deletions deploy.bat
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

set deployPath=D:\Project\build-QUsb2snes-Desktop_Qt_5_11_0_MSVC2017_64bit-Release\qtc_Desktop_Qt_5_11_0_MSVC2017_64bit_Release\install-root
set projectPath=D:\Project\QUsb2snes
set usb2snes=D:\Romhacking\usb2snes_v7\usb2snes_v7
set magic2snes=D:\Project\deploy\Magic2Snes
set snesclassicmod=D:\Project\snesclassicstuff\serverstuff\hmod\serverstuff.hmod
set deployPath=F:\Project\build-QUsb2snes-Desktop_Qt_5_11_1_MSVC2017_64bit-Release\qtc_Desktop_Qt_5_11_1_MSVC2017_64bit_Release\install-root
set projectPath=F:\Project\QUsb2snes
set usb2snes=F:\Romhacking\usb2snes_v7\usb2snes_v7
set magic2snes=F:\Project\deploy\Magic2Snes
set snesclassicmod=F:\Project\snesclassicstuff\serverstuff\hmod\serverstuff.hmod

cd %deployPath%

Expand Down

0 comments on commit 8360eb6

Please sign in to comment.