Skip to content

Commit

Permalink
update code for usb2snes 6
Browse files Browse the repository at this point in the history
Check romrunning automaticly
  • Loading branch information
Skarsnik committed Dec 23, 2017
1 parent 97bef15 commit 74aeaff
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 34 deletions.
17 changes: 10 additions & 7 deletions deploy.bat
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
@ECHO ON
set projectPath=C:\Users\Skarsnik\Documents\GitHub\Savestate2snes
set projectPath=D:\Project\Savestate2snes
set compilePath=D:\Project\compile\savestate2snes
set deployPath=D:\Project\deploy\savestate2snes
set originalBinDir=%compilePath%
::set vscdll=D:\Visual Studio\VC\redist\x64\Microsoft.VC140.CRT\msvcp140.dll
set vscdll=D:\Visual Studio\VC\Redist\MSVC\14.12.25810\x64\Microsoft.VC141.CRT\msvcp140.dll

rmdir /Q /S %deployPath%
mkdir %deployPath%
:: Compile

:: D:\Visual Studio\VC\vcvarsall.bat amd64
d:
::"D:\Visual Studio\VC\Auxiliary\Build\vcvarsall.bat" amd64

mkdir %compilePath%
cd %compilePath%
cd
qmake %projectPath%\savestate2snes.pro -spec win32-g++ "CONFIG+=release"
mingw32-make
set QMAKE_MSC_VER=1910
qmake %projectPath%\savestate2snes.pro -spec win32-msvc "CONFIG+=release"
nmake

xcopy /y %originalBinDir%\release\savestate2snes.exe %deployPath%

Expand All @@ -30,4 +31,6 @@ xcopy /e %projectPath%\Patches %deployPath%\Patches /r
rmdir /Q /S %deployPath%\imageformats
del %deployPath%\opengl32sw.dll
del %deployPath%\libEGL.dll
del %deployPath%\libGLESV2.dll
del %deployPath%\libGLESV2.dll

xcopy /y "%vscdll%" %deployPath%
2 changes: 1 addition & 1 deletion firsttimedialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;I have the USB2snes firmware version 5 or highter&lt;br/&gt;I have the USB2snes client version 5.1 or highter&lt;br/&gt; You can found it at &lt;a href=&quot;https://github.com/RedGuyyyy/sd2snes/releases&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;USB2snes last release&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;I have the USB2snes firmware version 6 or highter&lt;br/&gt;I have the USB2snes client version 6 or highter&lt;br/&gt; You can found it at &lt;a href=&quot;https://github.com/RedGuyyyy/sd2snes/releases&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;USB2snes last release&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
Expand Down
4 changes: 2 additions & 2 deletions shortcuteditdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ ShortcutEditDialog::~ShortcutEditDialog()
delete ui;
}

ShortcutEditDialog::saveShortcut()
quint16 ShortcutEditDialog::saveShortcut()
{
return m_saveShortcut;
}

ShortcutEditDialog::loadShortcut()
quint16 ShortcutEditDialog::loadShortcut()
{
return m_loadShortcut;
}
Expand Down
4 changes: 2 additions & 2 deletions shortcuteditdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class ShortcutEditDialog : public QDialog
explicit ShortcutEditDialog(QWidget *parent = 0);
ShortcutEditDialog(QWidget *parent, quint16 save, quint16 load);
~ShortcutEditDialog();
saveShortcut();
loadShortcut();
quint16 saveShortcut();
quint16 loadShortcut();


private slots:
Expand Down
33 changes: 28 additions & 5 deletions usb2snes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void USB2snes::usePort(QString port)
m_port = port;
}

QString USB2snes::getPort()
QString USB2snes::port()
{
return m_port;
}
Expand All @@ -72,6 +72,11 @@ void USB2snes::connect()
m_webSocket.open(QUrl(USB2SNESURL));
}

void USB2snes::setAppName(QString name)
{
sendRequest("Name", QStringList() << name);
}

void USB2snes::onWebSocketConnected()
{
sDebug() << "Websocket connected";
Expand Down Expand Up @@ -107,6 +112,7 @@ QStringList USB2snes::getJsonResults(QString json)
void USB2snes::onWebSocketTextReceived(QString message)
{
sDebug() << "<<T" << message;
lastTextMessage = message;
switch (m_istate)
{
case DeviceListRequested:
Expand All @@ -130,7 +136,8 @@ void USB2snes::onWebSocketTextReceived(QString message)
QStringList results = getJsonResults(message);
if (!results.isEmpty())
{
m_firmwareVersion = results.at(0);
m_firmwareString = results.at(0);
m_firmwareVersion= QVersionNumber(m_firmwareString.right(1).toInt());
m_istate = ServerVersionRequested;
sendRequest("AppVersion");
}
Expand All @@ -141,13 +148,14 @@ void USB2snes::onWebSocketTextReceived(QString message)
QStringList results = getJsonResults(message);
if (!results.isEmpty())
{
m_serverVersion = results.at(0);
m_serverVersion = QVersionNumber::fromString(results.at(0));
m_istate = IReady;
changeState(Ready);
}
break;
}
}
emit textMessageReceived();
}

void USB2snes::onWebSocketBinaryReceived(QByteArray message)
Expand Down Expand Up @@ -254,17 +262,32 @@ USB2snes::State USB2snes::state()
return m_state;
}

QString USB2snes::firmwareVersion()
QStringList USB2snes::infos()
{
sendRequest("Info");
QEventLoop loop;
QObject::connect(this, SIGNAL(textMessageReceived()), &loop, SLOT(quit()));
loop.exec();
return getJsonResults(lastTextMessage);
}

QString USB2snes::firmwareString()
{
return m_firmwareString;
}

QVersionNumber USB2snes::firmwareVersion()
{
return m_firmwareVersion;
}


QStringList USB2snes::deviceList()
{
return m_deviceList;
}

QString USB2snes::serverVersion()
QVersionNumber USB2snes::serverVersion()
{
return m_serverVersion;
}
16 changes: 11 additions & 5 deletions usb2snes.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,25 @@ class USB2snes : public QObject
USB2snes();
QPair<QString, QString> autoFind();
void usePort(QString port);
QString getPort();
QString port();
QString getRomName();
void connect();
void setAppName(QString name);
QByteArray getAddress(unsigned int addr, unsigned int size, Space space = SNES);
void setAddress(unsigned int addr, QByteArray data, Space space = SNES);
State state();
QString firmwareVersion();
QStringList infos();
QString firmwareString();
QVersionNumber firmwareVersion();
QStringList deviceList();
QString serverVersion();
QVersionNumber serverVersion();
bool patchROM(QString patch);

signals:
void stateChanged();
void disconnected();
void binaryMessageReceived();
void textMessageReceived();
void romStarted();
void menuStarted();

Expand All @@ -93,11 +97,13 @@ private slots:
QString m_port;
State m_state;
sd2snesState m_sd2snesState;
QString m_firmwareVersion;
QString m_serverVersion;
QVersionNumber m_firmwareVersion;
QString m_firmwareString;
QVersionNumber m_serverVersion;
InternalState m_istate;
QStringList m_deviceList;
QByteArray lastBinaryMessage;
QString lastTextMessage;
unsigned int requestedBinaryReadSize;

QTimer timer;
Expand Down
58 changes: 48 additions & 10 deletions usb2snesstatut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "usb2snesstatut.h"
#include "ui_usb2snesstatut.h"

#include <QMessageBox>
#include <QToolTip>

Q_LOGGING_CATEGORY(log_usb2snesstatus, "USB2SNES Status")
Expand All @@ -39,7 +40,11 @@ USB2SnesStatut::USB2SnesStatut(QWidget *parent) :
connectedOnce = false;
readyOnce = false;
connect(&timer, SIGNAL(timeout()), this, SLOT(onTimerTick()));
timer.start(1000);
//timer.start(1000);
menuRunning = false;
romRunning = false;
ui->romPatchedLabel->hide();
ui->pushButton->hide();
}

void USB2SnesStatut::setUsb2snes(USB2snes *usnes)
Expand Down Expand Up @@ -91,7 +96,7 @@ void USB2SnesStatut::refreshShortcuts()
void USB2SnesStatut::onRomStarted()
{
sDebug() << "Rom started";
QString text = usb2snes->getRomName();
QString text = usb2snes->infos().at(2);
ui->romNameLabel->setText(text);
if (!isPatchedRom())
{
Expand Down Expand Up @@ -136,17 +141,20 @@ void USB2SnesStatut::buildStatusInfo()
statusString.append(tr("No sd2nes devices found."));
goto setStatusToolTips;
}
statusString = QString(tr("SD2SNES On : %1\n")).arg(usb2snes->deviceList().at(0));
statusString += QString(tr("Firmware version is %1 and USB2SNES app version : %2 : %3\n")).arg(usb2snes->firmwareVersion()).arg(usb2snes->serverVersion()).arg("OK");
if (menuRunning)
{
statusString = tr("SD2SNES is on menu, not a rom\n");
}
statusString += QString(tr("SD2SNES On : %1\n")).arg(usb2snes->deviceList().at(0));
statusString += QString(tr("Firmware version is %1 and USB2SNES app version : %2 : %3\n")).arg(usb2snes->firmwareString()).arg(usb2snes->serverVersion().toString()).arg(validVersion() ? "OK" : "NOK");
setStatusToolTips:
sDebug() << statusString;
ui->statusPushButton->setToolTip(statusString);
}

bool USB2SnesStatut::validVersion()
{
if (usb2snes->firmwareVersion().right(1).toInt() >= 5 &&
!usb2snes->serverVersion().isEmpty())
if (usb2snes->firmwareVersion() >= QVersionNumber(6) && usb2snes->serverVersion() >= QVersionNumber(6))
return true;
return false;
}
Expand All @@ -165,16 +173,45 @@ bool USB2SnesStatut::isPatchedRom()
void USB2SnesStatut::onTimerTick()
{
//emit readyForSaveState();
timer.stop();
QStringList infos = usb2snes->infos();
if (infos.at(2) != "/sd2snes/menu.bin" && romRunning == false)
{
romRunning = true;
menuRunning = false;
onRomStarted();
}
if (infos.at(2) == "/sd2snes/menu.bin" && menuRunning == false)
{
ui->romPatchedLabel->setText(tr("SD2SNES on Menu"));
romRunning = false;
menuRunning = true;
buildStatusInfo();
emit unReadyForSaveState();
}
}

void USB2SnesStatut::onUsb2snesStateChanged()
{
if (usb2snes->state() == USB2snes::Ready)
{
ui->statusPushButton->setIcon(QIcon(STATUS_PIX_ORANGE));;
timer.start(CHECK_ROMRUNNING_TICK);
readyOnce = true;
if (validVersion())
{
ui->statusPushButton->setIcon(QIcon(STATUS_PIX_ORANGE));
usb2snes->setAppName("Savestate2snes");
timer.start(CHECK_ROMRUNNING_TICK);
readyOnce = true;
ui->romPatchedLabel->show();
} else {
QMessageBox msgBox(this);
msgBox.setTextFormat(Qt::RichText);
msgBox.setText(QString(tr("Your usb2snes client version (%1) and/or "
"usb2snes firmware version (%2) are not enought to run Savestate2snes<br/>"
"You need at least version 6 for both.<br/> You can get it at <a href=\"https://github.com/RedGuyyyy/sd2snes/releases\"><span style=\" text-decoration: underline; color:#0000ff;\">USB2snes last release</span></a>"
)).arg(usb2snes->serverVersion().toString()).arg(usb2snes->firmwareVersion().toString()));
msgBox.setWindowTitle(tr("Version error"));
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
}
}
if (usb2snes->state() == USB2snes::Connected)
connectedOnce = true;
Expand All @@ -184,6 +221,7 @@ void USB2SnesStatut::onUsb2snesStateChanged()
void USB2SnesStatut::onUsb2snesDisconnected()
{
ui->statusPushButton->setIcon(QIcon(STATUS_PIX_RED));
timer.stop();
emit unReadyForSaveState();
}

Expand Down
4 changes: 3 additions & 1 deletion usb2snesstatut.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ private slots:
bool connectedOnce;
bool readyOnce;
bool isPatchedRom();
void romPatched();
bool romRunning;
bool menuRunning;
void romPatched();
};

#endif // USB2SNESSTATUT_H
2 changes: 1 addition & 1 deletion usb2snesstatut.ui
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<item>
<widget class="QLabel" name="romNameLabel">
<property name="text">
<string>Rom Name</string>
<string>None</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit 74aeaff

Please sign in to comment.