mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
(linux) Manage one directory per user for save games and config.
This commit is contained in:
parent
668b203486
commit
b02d4c1c2f
@ -115,7 +115,7 @@ find . -name "*.exe" | xargs rm -f
|
||||
rm -rf AI
|
||||
rm -f AUTHORS ChangeLog license.txt Microsoft.VC90.CRT.manifest
|
||||
rm -rf MP3
|
||||
#rm -rf Games # TODO
|
||||
rm -rf Games
|
||||
|
||||
mv sprites Sprites
|
||||
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include "CConfigHandler.h"
|
||||
#include "../lib/Connection.h"
|
||||
#include "../lib/VCMI_Lib.h"
|
||||
#include "../lib/VCMIDirs.h"
|
||||
#include <cstdlib>
|
||||
#include "../lib/NetPacks.h"
|
||||
|
||||
@ -66,6 +67,7 @@ SDL_Surface *screen = NULL, //main screen surface
|
||||
*screenBuf = screen; //points to screen (if only advmapint is present) or screen2 (else) - should be used when updating controls which are not regularly redrawed
|
||||
|
||||
SystemOptions GDefaultOptions;
|
||||
VCMIDirs GVCMIDirs;
|
||||
std::queue<SDL_Event*> events;
|
||||
boost::mutex eventsM;
|
||||
|
||||
@ -106,7 +108,7 @@ void init()
|
||||
|
||||
{
|
||||
//read system options
|
||||
CLoadFile settings(DATA_DIR "/config/sysopts.bin");
|
||||
CLoadFile settings(GVCMIDirs.UserPath + "/config/sysopts.bin");
|
||||
if(settings.sfile)
|
||||
{
|
||||
settings >> GDefaultOptions;
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "../lib/CondSh.h"
|
||||
#include "../lib/NetPacks.h"
|
||||
#include "../lib/map.h"
|
||||
#include "../lib/VCMIDirs.h"
|
||||
#include "../mapHandler.h"
|
||||
#include "../timeHandler.h"
|
||||
#include <boost/lexical_cast.hpp>
|
||||
@ -1563,7 +1564,7 @@ void SystemOptions::setMapScrollingSpeed( int newSpeed )
|
||||
|
||||
void SystemOptions::settingsChanged()
|
||||
{
|
||||
CSaveFile settings(DATA_DIR "/config/sysopts.bin");
|
||||
CSaveFile settings(GVCMIDirs.UserPath + "/config/sysopts.bin");
|
||||
|
||||
if(settings.sfile)
|
||||
settings << *this;
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <boost/bind.hpp>
|
||||
#include <cstdlib>
|
||||
#include "../lib/Connection.h"
|
||||
#include "../lib/VCMIDirs.h"
|
||||
#include "../hch/CMusicHandler.h"
|
||||
#include "../hch/CVideoHandler.h"
|
||||
#include "AdventureMapButton.h"
|
||||
@ -370,7 +371,7 @@ void CSelectionScreen::startGame()
|
||||
if(!(sel && sel->txt && sel->txt->text.size()))
|
||||
return;
|
||||
|
||||
selectedName = "Games/" + sel->txt->text + ".vlgm1";
|
||||
selectedName = GVCMIDirs.UserPath + "/Games/" + sel->txt->text + ".vlgm1";
|
||||
LOCPLINT->cb->save(sel->txt->text);
|
||||
GH.popIntTotally(this);
|
||||
}
|
||||
@ -505,7 +506,7 @@ SelectionTab::SelectionTab(EState Type, const boost::function<void(CMapInfo *)>
|
||||
|
||||
case loadGame:
|
||||
case saveGame:
|
||||
getFiles(toParse, USER_DIR "/Games", "vlgm1");
|
||||
getFiles(toParse, GVCMIDirs.UserPath + "/Games", "vlgm1");
|
||||
parseGames(toParse);
|
||||
if(type == loadGame)
|
||||
{
|
||||
|
@ -371,7 +371,7 @@ void CClient::newGame( CConnection *con, StartInfo *si )
|
||||
|
||||
void CClient::runServer(const char * portc)
|
||||
{
|
||||
static std::string comm = std::string(SERVER_NAME) + " " + portc + " > server_log.txt"; //needs to be static, if not - will be probably destroyed before new thread reads it
|
||||
static std::string comm = std::string(BIN_DIR "/" SERVER_NAME " ") + portc + " > server_log.txt"; //needs to be static, if not - will be probably destroyed before new thread reads it
|
||||
boost::thread servthr(boost::bind(system,comm.c_str())); //runs server executable; //TODO: will it work on non-windows platforms?
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "../hch/CObjectHandler.h"
|
||||
#include "../lib/VCMI_Lib.h"
|
||||
#include "../lib/map.h"
|
||||
#include "../lib/VCMIDirs.h"
|
||||
#include "../hch/CSpellHandler.h"
|
||||
#include "../hch/CSoundBase.h"
|
||||
#include "../mapHandler.h"
|
||||
@ -541,7 +542,7 @@ void YourTurn::applyCl( CClient *cl )
|
||||
|
||||
void SaveGame::applyCl(CClient *cl)
|
||||
{
|
||||
CSaveFile save(DATA_DIR "/Games/" + fname + ".vcgm1");
|
||||
CSaveFile save(GVCMIDirs.UserPath + "/Games/" + fname + ".vcgm1");
|
||||
save << *cl;
|
||||
}
|
||||
|
||||
|
13
global.h
13
global.h
@ -28,13 +28,14 @@ extern std::string NAME_AFFIX; //client / server
|
||||
|
||||
/*
|
||||
* DATA_DIR contains the game data (Data/, MP3/, ...).
|
||||
* USER_DIR is where to save games (Games/).
|
||||
* BIN_DIR is where the vcmiclient/vcmiserver binaries reside (linux only)
|
||||
* LIB_DIR is where the AI libraries reside (linux only)
|
||||
* USER_DIR is where to save games (Games/) and the config.
|
||||
* BIN_DIR is where the vcmiclient/vcmiserver binaries reside
|
||||
* LIB_DIR is where the AI libraries reside (linux only)
|
||||
*/
|
||||
#ifdef _WIN32
|
||||
#define DATA_DIR "."
|
||||
#define USER_DIR "."
|
||||
#define USER_DIR "."
|
||||
#define BIN_DIR "."
|
||||
#define SERVER_NAME "VCMI_server.exe"
|
||||
#else
|
||||
#ifndef DATA_DIR
|
||||
@ -46,8 +47,7 @@ extern std::string NAME_AFFIX; //client / server
|
||||
#ifndef LIB_DIR
|
||||
#error LIB_DIR undefined.
|
||||
#endif
|
||||
#define USER_DIR DATA_DIR // TODO: should be $HOME/.vcmi
|
||||
#define SERVER_NAME BIN_DIR "/vcmiserver"
|
||||
#define SERVER_NAME "vcmiserver"
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -341,5 +341,4 @@ extern DLL_EXPORT CLogger<5> tlog5; //gray - minor log info
|
||||
throw; \
|
||||
}
|
||||
|
||||
|
||||
#endif // __GLOBAL_H__
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "../lib/NetPacks.h"
|
||||
#include "../lib/VCMI_Lib.h"
|
||||
#include "../lib/map.h"
|
||||
#include "../lib/VCMIDirs.h"
|
||||
#include "CGameHandler.h"
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time_types.hpp> //no i/o just types
|
||||
@ -1848,14 +1849,14 @@ void CGameHandler::save( const std::string &fname )
|
||||
|
||||
{
|
||||
tlog0 << "Serializing game info...\n";
|
||||
CSaveFile save(std::string(DATA_DIR "/Games/") + fname + ".vlgm1");
|
||||
CSaveFile save(GVCMIDirs.UserPath + "/Games/" + fname + ".vlgm1");
|
||||
char hlp[8] = "VCMISVG";
|
||||
save << hlp << static_cast<CMapHeader&>(*gs->map) << gs->scenarioOps->difficulty << *VLC << gs;
|
||||
}
|
||||
|
||||
{
|
||||
tlog0 << "Serializing server info...\n";
|
||||
CSaveFile save(std::string(DATA_DIR "/Games/") + fname + ".vsgm1");
|
||||
CSaveFile save(GVCMIDirs.UserPath + "/Games/" + fname + ".vsgm1");
|
||||
save << *this;
|
||||
}
|
||||
tlog0 << "Game has been succesfully saved!\n";
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "../hch/CLodHandler.h"
|
||||
#include "../lib/Interprocess.h"
|
||||
#include "../lib/VCMI_Lib.h"
|
||||
#include "../lib/VCMIDirs.h"
|
||||
#include "CGameHandler.h"
|
||||
std::string NAME_AFFIX = "server";
|
||||
std::string NAME = NAME_VER + std::string(" (") + NAME_AFFIX + ')'; //application name
|
||||
@ -33,6 +34,7 @@ using namespace boost::asio::ip;
|
||||
namespace intpr = boost::interprocess;
|
||||
bool end2 = false;
|
||||
int port = 3030;
|
||||
VCMIDirs GVCMIDirs;
|
||||
|
||||
/*
|
||||
* CVCMIServer.cpp, part of VCMI engine
|
||||
|
Loading…
Reference in New Issue
Block a user