Skip to content

Commit

Permalink
use ~/.config/flobby and ~/.cache/flobby
Browse files Browse the repository at this point in the history
~./config/ and ~/.cache/ can be overridden by XDG_CONFIG_HOME and XDG_CACHE_HOME.
  • Loading branch information
cleanrock committed Apr 17, 2013
1 parent 6b3322d commit da9544f
Show file tree
Hide file tree
Showing 29 changed files with 191 additions and 102 deletions.
23 changes: 9 additions & 14 deletions README
Expand Up @@ -15,17 +15,12 @@ $ cmake .
$ make -j4
$ src/flobby

Files and directories:
~/.fltk/cleanrock/flobby.prefs
flobby settings, delete this file to reset all settings to default
~/.spring/flobby/cache/
map cache files (images and map info)
~/.spring/flobby/log/
logs of all chats, logging to files can be disabled in flobby
~/.spring/flobby_script.txt
spring script file, written on spring launch
~/.spring/flobby_process_pr-downloader.log
pr-downloader output
/tmp/flobby.log
flobby debug log, path can be changed in flobby

Directories and files:
~/.config/flobby/ # can be changed with XDG_CONFIG_HOME
flobby.prefs # flobby settings, delete this file to reset all settings to default
~/.cache/flobby/ # can be changed with XDG_CACHE_HOME
flobby_script.txt # spring script file, written on spring launch
flobby_process_pr-downloader.log # pr-downloader output
map/ # map cache files
log/ # logs of all chats, logging to files can be disabled in flobby
/tmp/flobby.log # flobby debug log, path can be changed in flobby
4 changes: 2 additions & 2 deletions TODO
@@ -1,12 +1,12 @@
~/.config/flobby/
friend list
map window showing big map image, 512x512
commands in all chat windows
single player game
implement game hosting

? link statically to pr-downloader lib
? freeimage instead of imagemagick
? load chat history
? quick find in StringTable, e.g. press C key to show first entry beginning with a C, ignore ^[.*] also maybe
? handle FORCEQUITBATTLE
? battle preview (lower left) do not show host in player list, count host as a player if not bot
? extractSentence shall accept ""
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Expand Up @@ -12,6 +12,7 @@ include_directories (

add_executable (flobby
main.cpp
FlobbyDirs.cpp
)

target_link_libraries (flobby
Expand Down
53 changes: 53 additions & 0 deletions src/FlobbyDirs.cpp
@@ -0,0 +1,53 @@
#include "FlobbyDirs.h"

#include <boost/filesystem.hpp>
#include <cstring>
#include <cstdlib>
#include <cassert>

static std::string configDir_;
static std::string cacheDir_;

void initDirs()
{
const char* home = ::getenv("HOME");
assert(home);

const char* configHome = ::getenv("XDG_CONFIG_HOME");
if (configHome && ::strlen(configHome) > 0)
{
configDir_ = configHome;
}
else
{
configDir_ = home;
configDir_ += "/.config";
}
configDir_ += "/flobby/";
boost::filesystem::create_directories(configDir_);

const char* cacheHome = ::getenv("XDG_CACHE_HOME");
if (cacheHome && ::strlen(cacheHome) > 0)
{
configDir_ = cacheHome;
}
else
{
cacheDir_ = home;
cacheDir_ += "/.cache";
}
cacheDir_ += "/flobby/";
boost::filesystem::create_directories(cacheDir_);
}

std::string const& configDir()
{
assert(!configDir_.empty());
return configDir_;
}

std::string const& cacheDir()
{
assert(!cacheDir_.empty());
return cacheDir_;
}
9 changes: 9 additions & 0 deletions src/FlobbyDirs.h
@@ -0,0 +1,9 @@
#pragma once

#include <string>

void initDirs();

// return values below ends with '/'
std::string const& configDir();
std::string const& cacheDir();
3 changes: 2 additions & 1 deletion src/controller/Controller.cpp
Expand Up @@ -3,6 +3,7 @@
#include "model/Model.h"
#include "IServerEvent.h"
#include "log/Log.h"
#include "FlobbyDirs.h"

#include <boost/bind.hpp>
#include <boost/filesystem.hpp>
Expand Down Expand Up @@ -61,7 +62,7 @@ void Controller::runProcess(std::string const & cmd, bool logToFile, unsigned in
// create log filename
std::string const first = cmd.substr(0, cmd.find(' '));
boost::filesystem::path const path(first);
std::string const log = "flobby_process_" + path.stem().string() + ".log";
std::string const log = cacheDir() + "flobby_process_" + path.stem().string() + ".log";
LOG(DEBUG) << "runProcess logFile: '" << log << "'";

// redirect stdout and stderr to log file
Expand Down
8 changes: 4 additions & 4 deletions src/gui/BattleList.cpp
Expand Up @@ -56,16 +56,16 @@ BattleList::BattleList(int x, int y, int w, int h, Model & model, Cache & cache)

// read prefs
char str[65];
prefs.get(PrefBattleFilterGame, str, "", 64);
prefs().get(PrefBattleFilterGame, str, "", 64);
filterGame_ = str;
prefs.get(PrefBattleFilterPlayers, filterPlayers_, 0);
prefs().get(PrefBattleFilterPlayers, filterPlayers_, 0);

}

BattleList::~BattleList()
{
prefs.set(PrefBattleFilterGame, filterGame_.c_str());
prefs.set(PrefBattleFilterPlayers, filterPlayers_);
prefs().set(PrefBattleFilterGame, filterGame_.c_str());
prefs().set(PrefBattleFilterPlayers, filterPlayers_);
}

void BattleList::loginResult(bool success, std::string const & info)
Expand Down
4 changes: 2 additions & 2 deletions src/gui/BattleRoom.cpp
Expand Up @@ -155,13 +155,13 @@ BattleRoom::BattleRoom(int x, int y, int w, int h, Model & model, Cache & cache,

BattleRoom::~BattleRoom()
{
prefs.set(PrefBattleRoomSplitV, battleChat_->y());
prefs().set(PrefBattleRoomSplitV, battleChat_->y());
}

void BattleRoom::initTiles()
{
int y;
prefs.get(PrefBattleRoomSplitV, y, 0);
prefs().get(PrefBattleRoomSplitV, y, 0);
if (y != 0)
{
position(0, battleChat_->y(), 0, y);
Expand Down
17 changes: 9 additions & 8 deletions src/gui/Cache.cpp
Expand Up @@ -2,6 +2,7 @@

#include "log/Log.h"
#include "model/Model.h"
#include "FlobbyDirs.h"

#include <Magick++.h>
#include <FL/Fl_Shared_Image.H>
Expand All @@ -20,25 +21,25 @@ Cache::~Cache()
{
}

std::string Cache::basePath()
std::string Cache::mapDir()
{
std::string basePath = model_.getWriteableDataDir() + "flobby/cache/";
std::string basePath = cacheDir() + "map/";
if (!boost::filesystem::is_directory(basePath.c_str()))
{
boost::filesystem::create_directories(basePath.c_str());
}
return basePath;
}

std::string Cache::getPath(std::string const& mapName, std::string const& type)
std::string Cache::mapPath(std::string const& mapName, std::string const& type)
{
std::string path;

unsigned int const chksum = model_.getMapChecksum(mapName);
if (chksum != 0)
{
std::ostringstream oss;
oss << basePath() << mapName << "_" << chksum << "_" << type << "_128.png";
oss << mapDir() << mapName << "_" << chksum << "_" << type << "_128.png";
path = oss.str();
}

Expand All @@ -47,17 +48,17 @@ std::string Cache::getPath(std::string const& mapName, std::string const& type)

std::string Cache::pathMapImage(std::string const& mapName)
{
return getPath(mapName, "minimap");
return mapPath(mapName, "minimap");
}

std::string Cache::pathMetalImage(std::string const& mapName)
{
return getPath(mapName, "metal");
return mapPath(mapName, "metal");
}

std::string Cache::pathHeightImage(std::string const& mapName)
{
return getPath(mapName, "height");
return mapPath(mapName, "height");
}

bool Cache::hasMapImage(std::string const & mapName)
Expand Down Expand Up @@ -228,7 +229,7 @@ MapInfo const & Cache::getMapInfo(std::string const & mapName)
else
{
std::ostringstream oss;
oss << basePath() << key << "_info.bin";
oss << mapDir() << key << "_info.bin";
std::string const path = oss.str();

std::ifstream ifs(path);
Expand Down
4 changes: 2 additions & 2 deletions src/gui/Cache.h
Expand Up @@ -28,11 +28,11 @@ class Cache
Model & model_;
std::map<std::string, MapInfo> mapInfos_;

std::string basePath();
std::string mapDir();
std::string pathMapImage(std::string const& mapName);
std::string pathMetalImage(std::string const& mapName);
std::string pathHeightImage(std::string const& mapName);
std::string getPath(std::string const& mapName, std::string const& type);
std::string mapPath(std::string const& mapName, std::string const& type); // returns empty string map do not exist

void createImageFile(uint8_t const * data, int w, int h, int d, std::string const & path, double r = 1 /* w/h */);
};
2 changes: 1 addition & 1 deletion src/gui/ChannelChatTab.cpp
Expand Up @@ -48,7 +48,7 @@ ChannelChatTab::ChannelChatTab(int x, int y, int w, int h, std::string const & c
// setup split
{
int x;
prefs.get(PrefServerMessagesSplitH, x, 0);
prefs().get(PrefServerMessagesSplitH, x, 0);
if (x != 0)
{
position(userList_->x(), 0, x, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/ChannelsWindow.cpp
Expand Up @@ -16,7 +16,7 @@ static char const * PrefWindowH = "WindowH";
ChannelsWindow::ChannelsWindow(Model & model):
Fl_Double_Window(100, 100, "Channels"),
model_(model),
prefs_(prefs, label()),
prefs_(prefs(), label()),
channelsRetrieved_(false)
{
channelList_ = new StringTable(0, 0, 100, 100, "ChannelList",
Expand Down
40 changes: 20 additions & 20 deletions src/gui/ChatSettingsDialog.cpp
Expand Up @@ -109,44 +109,44 @@ void ChatSettingsDialog::loadPrefs()

// channel chat
{
prefs.get(PrefShowJoinLeaveInChannels, val, 0);
prefs().get(PrefShowJoinLeaveInChannels, val, 0);
showJoinLeaveInChannels_->value(val);

prefs.get(PrefChannelChatBeep, val, 0);
prefs().get(PrefChannelChatBeep, val, 0);
channelChatBeep_->value(val);

char * text;
prefs.get(PrefChannelChatBeepExceptions, text, "");
prefs().get(PrefChannelChatBeepExceptions, text, "");
channelChatBeepExceptions_->value(text);
::free(text);
}

// private chat
{
prefs.get(PrefPrivateChatBeep, val, 1);
prefs().get(PrefPrivateChatBeep, val, 1);
privateChatBeep_->value(val);

char * text;
prefs.get(PrefPrivateChatBeepExceptions, text, "");
prefs().get(PrefPrivateChatBeepExceptions, text, "");
privateChatBeepExceptions_->value(text);
::free(text);
}

// chat text color
{
prefs.get(PrefTimeColor, val, FL_INACTIVE_COLOR);
prefs().get(PrefTimeColor, val, FL_INACTIVE_COLOR);
textColor_[TextDisplay2::STYLE_TIME]->color(val);

prefs.get(PrefLowInterestColor, val, FL_INACTIVE_COLOR);
prefs().get(PrefLowInterestColor, val, FL_INACTIVE_COLOR);
textColor_[TextDisplay2::STYLE_LOW]->color(val);

prefs.get(PrefNormalInterestColor, val, FL_FOREGROUND_COLOR);
prefs().get(PrefNormalInterestColor, val, FL_FOREGROUND_COLOR);
textColor_[TextDisplay2::STYLE_NORMAL]->color(val);

prefs.get(PrefHighInterestColor, val, FL_FOREGROUND_COLOR);
prefs().get(PrefHighInterestColor, val, FL_FOREGROUND_COLOR);
textColor_[TextDisplay2::STYLE_HIGH]->color(val);

prefs.get(PrefMyTextColor, val, FL_FOREGROUND_COLOR);
prefs().get(PrefMyTextColor, val, FL_FOREGROUND_COLOR);
textColor_[TextDisplay2::STYLE_MYTEXT]->color(val);
}

Expand All @@ -160,31 +160,31 @@ void ChatSettingsDialog::savePrefs()
// channel chat
{
int const showJoinLeave = showJoinLeaveInChannels_->value();
prefs.set(PrefShowJoinLeaveInChannels, showJoinLeave);
prefs().set(PrefShowJoinLeaveInChannels, showJoinLeave);

int const beep = channelChatBeep_->value();
prefs.set(PrefChannelChatBeep, beep);
prefs().set(PrefChannelChatBeep, beep);

std::string const beepExceptions(channelChatBeepExceptions_->value());
prefs.set(PrefChannelChatBeepExceptions, beepExceptions.c_str());
prefs().set(PrefChannelChatBeepExceptions, beepExceptions.c_str());
}

// private chat
{
int const beep = privateChatBeep_->value();
prefs.set(PrefPrivateChatBeep, beep);
prefs().set(PrefPrivateChatBeep, beep);

std::string const beepExceptions(privateChatBeepExceptions_->value());
prefs.set(PrefPrivateChatBeepExceptions, beepExceptions.c_str());
prefs().set(PrefPrivateChatBeepExceptions, beepExceptions.c_str());
}

// chat text color
{
prefs.set(PrefTimeColor, static_cast<int>(textColor_[TextDisplay2::STYLE_TIME]->color()) );
prefs.set(PrefLowInterestColor, static_cast<int>(textColor_[TextDisplay2::STYLE_LOW]->color()) );
prefs.set(PrefNormalInterestColor, static_cast<int>(textColor_[TextDisplay2::STYLE_NORMAL]->color()) );
prefs.set(PrefHighInterestColor, static_cast<int>(textColor_[TextDisplay2::STYLE_HIGH]->color()) );
prefs.set(PrefMyTextColor, static_cast<int>(textColor_[TextDisplay2::STYLE_MYTEXT]->color()) );
prefs().set(PrefTimeColor, static_cast<int>(textColor_[TextDisplay2::STYLE_TIME]->color()) );
prefs().set(PrefLowInterestColor, static_cast<int>(textColor_[TextDisplay2::STYLE_LOW]->color()) );
prefs().set(PrefNormalInterestColor, static_cast<int>(textColor_[TextDisplay2::STYLE_NORMAL]->color()) );
prefs().set(PrefHighInterestColor, static_cast<int>(textColor_[TextDisplay2::STYLE_HIGH]->color()) );
prefs().set(PrefMyTextColor, static_cast<int>(textColor_[TextDisplay2::STYLE_MYTEXT]->color()) );
}

setCurrentSettings();
Expand Down
4 changes: 2 additions & 2 deletions src/gui/FontSettingsDialog.cpp
Expand Up @@ -20,7 +20,7 @@ void FontSettingsDialog::setupFont()
int FontSettingsDialog::getFontSize()
{
int fontSize;
prefs.get(PrefFontSize, fontSize, 13);
prefs().get(PrefFontSize, fontSize, 13);
return fontSize;
}

Expand Down Expand Up @@ -70,7 +70,7 @@ void FontSettingsDialog::onApply()
return;
}

prefs.set(PrefFontSize, fontSize);
prefs().set(PrefFontSize, fontSize);

box_->label(0);
hide();
Expand Down

1 comment on commit da9544f

@cleanrock
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move settings:
$ cp ~/.fltk/cleanrock/flobby.prefs ~/.config/flobby/flobby.prefs

Move map cache files:
$ cp ~/.spring/flobby/cache/* ~/.cache/flobby/map/

Please sign in to comment.