Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions Client/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "../Puyolib/Game.h"
#include <QCryptographicHash>
#include <QDesktopServices>
#include <QDir>
#include <QKeyEvent>
#include <QMessageBox>
#include <QObject>
Expand Down Expand Up @@ -47,14 +48,46 @@ QString getCryptographicHash(QString str)
return QString(QCryptographicHash::hash(s.toUtf8(), QCryptographicHash::Md5).toHex());
}

QString verifyFolderExistence(QString fn)
{
// Create the folder if it doesn't already
if (!QDir(fn).exists())
{
QDir().mkpath(fn);
}
return fn;
}

QString getCacheLocation()
{
#if QT_VERSION >= 0x050000
//Qt 5
return verifyFolderExistence(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
#else
return verifyFolderExistence(QDesktopServices::storageLocation(QDesktopServices::CacheLocation));
#endif
}

QString getDataLocation()
{

#if QT_VERSION >= 0x050000
// Qt5: QStandardPaths::StandardLocation
return QStandardPaths::writableLocation(QStandardPaths::DataLocation);
return verifyFolderExistence(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
#else
// Qt4
return QDesktopServices::storageLocation(QDesktopServices::DataLocation);
return verifyFolderExistence(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
#endif
}

QString getSettingsLocation()
{
#if QT_VERSION >= 0x050000
// Qt5
return verifyFolderExistence(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation));
#else
// Qt4: revert to Data location
return verifyFolderExistence(QDesktopServices::storageLocation(QDesktopServices::DataLocation));
#endif
}

Expand Down
2 changes: 2 additions & 0 deletions Client/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ typedef QList<GameModePair> GameModeList;
typedef QListIterator<QPair<ppvs::Rules, QString>> GameModeListIterator;
GameModeList getModeList();
void readRulesetString(QString str, ppvs::RuleSetInfo* rs);
QString getCacheLocation();
QString getDataLocation();
QString getSettingsLocation();
QString createRulesetString(ppvs::RuleSetInfo* rs);

namespace ilib {
Expand Down
4 changes: 2 additions & 2 deletions Client/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#ifndef PREFIX
#if defined(Q_OS_WIN)
#define PREFIX "C:\\PuyoVS"
#define PREFIX "C:\\Program Files"
#elif defined(Q_OS_MAC) && defined(__aarch64__)
#define PREFIX "/opt/homebrew"
#else
Expand All @@ -12,7 +12,7 @@
#endif

#if defined(Q_OS_WIN)
static const char* defaultAssetPath = PREFIX;
static const char* defaultAssetPath = PREFIX "\\PuyoVS";
#else
static const char* defaultAssetPath = PREFIX "/share/puyovs";
#endif
4 changes: 2 additions & 2 deletions Client/playlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ CacheDB* CacheDB::instance = nullptr;

CacheDB::CacheDB()
{
QFile cache("User/Music/cache.db");
QFile cache(getCacheLocation()+"/ppvs_cache.db");
cache.open(QIODevice::ReadOnly);
QDataStream dataStream(&cache);

Expand Down Expand Up @@ -113,7 +113,7 @@ void CacheDB::removeHashCode(unsigned hash)

void CacheDB::write()
{
QFile cache("User/Music/cache.db");
QFile cache(getCacheLocation()+"/ppvs_cache.db");
cache.open(QIODevice::WriteOnly);
QDataStream dataStream(&cache);

Expand Down
22 changes: 10 additions & 12 deletions Client/pvsapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,32 @@ struct PVSApplication::Priv {
MusicPlayer normalPlayer, feverPlayer;

Priv()
: normalPlaylist("User/Music/Normal.m3u")
, feverPlaylist("User/Music/Fever.m3u")
: normalPlaylist(getDataLocation()+"/User/Music/Normal.m3u")
, feverPlaylist(getDataLocation()+"/User/Music/Fever.m3u")
, normalPlayer(normalPlaylist)
, feverPlayer(feverPlaylist)
{
normalPlaylist.discover("User/Music/Normal");
feverPlaylist.discover("User/Music/Fever");
normalPlaylist.discover(getDataLocation()+"/User/Music/Normal");
feverPlaylist.discover(getDataLocation()+"/User/Music/Fever");
}
};

PVSApplication::PVSApplication(int& argc, char** argv)
: QApplication(argc, argv)
, p(new Priv)
{
// We do not need to check the existence of the folder, that's done automatically
// Copy settings.json if necessary
if (!QDir(getDataLocation()).exists()) {
QDir().mkpath(getDataLocation());
}
if (QFile("Settings.json").exists() && !QFile(getDataLocation() + "/Settings.json").exists()) {
QFile("Settings.json").copy(getDataLocation() + "/Settings.json");
if (QFile("Settings.json").exists() && !QFile(getSettingsLocation() + "/Settings.json").exists()) {
QFile("Settings.json").copy(getSettingsLocation() + "/Settings.json");
}

p->settings = new Settings(this);

// Make sure these exist.
QDir().mkdir("User/Music");
QDir().mkdir("User/Music/Fever");
QDir().mkdir("User/Music/Normal");
QDir().mkdir(getDataLocation()+"/User/Music");
QDir().mkdir(getDataLocation()+"/User/Music/Fever");
QDir().mkdir(getDataLocation()+"/User/Music/Normal");

pvsApp = this;

Expand Down
1 change: 1 addition & 0 deletions Puyolib/Game.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Game.h"
#include "../PVS_ENet/PVS_Channel.h"
#include "../PVS_ENet/PVS_Client.h"
#include <algorithm>
#include <cstdio>
#include <ctime>
#include <fstream>
Expand Down