refactor: 新建 getAppFileName() 函数并使用
This commit is contained in:
parent
533c3e2d49
commit
51e723fc4e
|
@ -17,5 +17,17 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QtWidgets/QApplication>
|
||||
|
||||
#include "config.h"
|
||||
#include "misc.h"
|
||||
|
||||
QString getAppFileName()
|
||||
{
|
||||
QString filename;
|
||||
filename = QCoreApplication::applicationFilePath().mid(QCoreApplication::applicationDirPath().size() + 1);
|
||||
filename = filename.mid(0, filename.size() - QString(".exe").size());
|
||||
|
||||
return filename;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include <cstdlib>
|
||||
#include <chrono>
|
||||
|
||||
#include <QString>
|
||||
|
||||
using TimePoint = std::chrono::milliseconds::rep; // A value in milliseconds
|
||||
|
||||
static_assert(sizeof(TimePoint) == sizeof(int64_t), "TimePoint should be 64 bits");
|
||||
|
@ -47,4 +49,6 @@ inline uint64_t rand56()
|
|||
return rand64() << 8;
|
||||
}
|
||||
|
||||
extern QString getAppFileName();
|
||||
|
||||
#endif /* MISC_H */
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <QDesktopWidget>
|
||||
|
||||
#include "gamewindow.h"
|
||||
#include "misc.h"
|
||||
|
||||
QString APP_FILENAME_DEFAULT = "MillGame";
|
||||
|
||||
|
@ -31,10 +32,7 @@ int main(int argc, char *argv[])
|
|||
MillGameWindow w;
|
||||
w.show();
|
||||
|
||||
QString appFileName;
|
||||
appFileName = QCoreApplication::applicationFilePath().mid(QCoreApplication::applicationDirPath().size() + 1);
|
||||
appFileName = appFileName.mid(0, appFileName.size() - QString(".exe").size());
|
||||
w.setWindowTitle(appFileName + " (" + QString::number(QCoreApplication::applicationPid()) + ")");
|
||||
w.setWindowTitle(getAppFileName() + " (" + QString::number(QCoreApplication::applicationPid()) + ")");
|
||||
|
||||
#ifndef _DEBUG
|
||||
w.move((QApplication::desktop()->width() - w.width()) / 4, (QApplication::desktop()->height() - w.height()) / 2);
|
||||
|
|
|
@ -28,9 +28,9 @@
|
|||
#include <QtCore>
|
||||
#include <random>
|
||||
|
||||
#include "misc.h"
|
||||
#include "test.h"
|
||||
|
||||
extern QString appFileName;
|
||||
extern QString APP_FILENAME_DEFAULT;
|
||||
|
||||
Test::Test(QWidget *parent, QString k)
|
||||
|
@ -49,9 +49,7 @@ Test::Test(QWidget *parent, QString k)
|
|||
|
||||
keyCombo->setEditable(true);
|
||||
#ifdef TEST_MODE
|
||||
QString appFileName;
|
||||
appFileName = QCoreApplication::applicationFilePath().mid(QCoreApplication::applicationDirPath().size() + 1);
|
||||
appFileName = appFileName.mid(0, appFileName.size() - QString(".exe").size());
|
||||
QString appFileName = getAppFileName();
|
||||
if (appFileName != APP_FILENAME_DEFAULT) {
|
||||
keyCombo->addItem(QString(appFileName));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue