[SCM] Wormux PKG branch, trunk-ups, updated. 0352c121d7d62492ec12e1d47d64c955e30b8e5c
gentildemon
gentildemon at 30ef787d-52ff-0310-b286-e08351bb7647
Wed Aug 27 18:49:04 UTC 2008
The following commit has been merged in the trunk-ups branch:
commit 5083e0c4622020bf87d4a66ada4ec3e621d5c49c
Author: gentildemon <gentildemon at 30ef787d-52ff-0310-b286-e08351bb7647>
Date: Tue Aug 26 10:58:38 2008 +0000
task #5918 - Implements command-line option --reset-config that removes the personal config file (~/.config/wormux/config.xml)
Kurosu, could you check it works under Windows ? I'm not sure unlink() is working under Win32.
git-svn-id: svn+ssh://svn.gna.org/svn/wormux/trunk@4897 30ef787d-52ff-0310-b286-e08351bb7647
diff --git a/src/game/config.cpp b/src/game/config.cpp
index 5636dab..bac5908 100644
--- a/src/game/config.cpp
+++ b/src/game/config.cpp
@@ -245,21 +245,40 @@ Config::Config():
resource_manager.AddDataPath(dir + PATH_SEPARATOR);
}
-bool Config::MkdirChatLogDir()
+bool Config::MkdirChatLogDir() const
{
return CreateFolder(chat_log_dir);
}
-bool Config::MkdirPersonalConfigDir()
+bool Config::MkdirPersonalConfigDir() const
{
return CreateFolder(personal_config_dir);
}
-bool Config::MkdirPersonalDataDir()
+bool Config::MkdirPersonalDataDir() const
{
return CreateFolder(personal_data_dir);
}
+bool Config::RemovePersonalConfigFile() const
+{
+ std::string personal_config_file = personal_config_dir + FILENAME;
+
+ int r = unlink(personal_config_file.c_str());
+ if (r) {
+ if (errno == -ENOENT) {
+ r = 0;
+ } else {
+ perror((Format("Fail to remove personal config file %s", personal_config_file.c_str())).c_str());
+ }
+ }
+
+ if (r)
+ return false;
+
+ return true;
+}
+
void Config::SetLanguage(const std::string language)
{
default_language = language;
@@ -649,8 +668,10 @@ uint Config::GetMaxVolume()
const std::string& Config::GetTtfFilename()
{
- if (fonts.find(default_language) == fonts.end()) return ttf_filename;
- else return fonts[default_language];
+ if (fonts.find(default_language) == fonts.end())
+ return ttf_filename;
+ else
+ return fonts[default_language];
}
void Config::SetNetworkLocalTeams()
diff --git a/src/game/config.h b/src/game/config.h
index fa79e16..44d8ca4 100644
--- a/src/game/config.h
+++ b/src/game/config.h
@@ -154,9 +154,11 @@ public:
const std::list<ConfigTeam>& AccessNetworkTeamsList() const { return network_local_teams; };
// return true if the directory is created
- bool MkdirPersonalConfigDir();
- bool MkdirPersonalDataDir();
- bool MkdirChatLogDir();
+ bool MkdirPersonalConfigDir() const;
+ bool MkdirPersonalDataDir() const;
+ bool MkdirChatLogDir() const;
+
+ bool RemovePersonalConfigFile() const;
protected:
bool SaveXml(bool save_current_teams);
@@ -231,8 +233,6 @@ private:
void LoadDefaultValue();
void LoadXml(const xmlNode* xml);
-
-
/* this is mutable in order to be able to load config on fly when calling
* GetObjectConfig() witch is not supposed to modify the object itself */
mutable std::map<std::string, ObjectConfig *> config_set;
diff --git a/src/main.cpp b/src/main.cpp
index 0402fc0..301cd10 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -310,6 +310,26 @@ void DisplayWelcomeMessage()
#endif
}
+void PrintUsage(const char* cmd_name)
+{
+ printf("usage: \n");
+ printf("%s -h|--help : show this help\n", cmd_name);
+ printf("%s -v|--version : show the version\n", cmd_name);
+ printf("%s -r|--reset-config : reset the configuration to default\n", cmd_name);
+ printf("%s -y|--skin-viewer [team] : start the skin viewer (for development only)\n", cmd_name);
+ printf("%s [-p|--play] [-g|--game-mode <game_mode>]"
+ " [-i|--internet] [-s|--server] [-c|--client [ip]]\n"
+ " [-l [ip/hostname of index server]]\n"
+#ifdef DEBUG
+ " [-d|--debug <debug_masks>|all]\n"
+#endif
+ , cmd_name);
+#ifdef DEBUG
+ printf("\nWith :\n");
+ printf(" <debug_masks> ::= { action | action_handler | action_handler.menu | ai | ai.move | body | body_anim | body.state | bonus | box | camera.follow | camera.shake | camera.tracking | character | character.collision | character.energy | damage | downloader | explosion | game | game.endofturn | game_mode | game.statechange | ghost | grapple.break | grapple.hook | grapple.node | ground_generator.element | index_server | jukebox | jukebox.cache | jukebox.play | lst_objects | map | map.collision | map.load | map.random | menu | mine | mouse | network | network.crc | network.crc_bad | network.traffic | network.turn_master | physical | physical.mem | physic.compute | physic.fall | physic.move | physic.overlapping | physic.pendulum | physic.physic | physic.position | physic.state | physic.sync | random | random.get | singleton | socket | sprite | team | test_rectangle | weapon | weapon.change | weapon.handposition | weapon.projectile | weapon.shoot | widget.border | wind | xml | xml.tree }\n");
+#endif
+}
+
void ParseArgs(int argc, char * argv[])
{
int c;
@@ -326,6 +346,7 @@ void ParseArgs(int argc, char * argv[])
{"skin-viewer",optional_argument, NULL, 'y'},
{"game-mode", required_argument, NULL, 'g'},
{"debug", required_argument, NULL, 'd'},
+ {"reset-config", no_argument, NULL, 'r'},
{NULL, no_argument, NULL, 0 }
};
@@ -335,22 +356,12 @@ void ParseArgs(int argc, char * argv[])
switch (c)
{
case 'h':
- printf("usage: %s [-h|--help] [-v|--version] [-p|--play]"
- " [-i|--internet] [-s|--server] [-c|--client [ip]]\n"
- " [-g|--game-mode <game_mode>] [-y|--skin-viewer [team]]"
-#ifdef DEBUG
- " [-d|--debug <debug_masks>|all]\n"
-#endif
- " [-l [ip/hostname]]\n", argv[0]);
-#ifdef DEBUG
- printf("\nWith :\n");
- printf(" <debug_masks> ::= { action | action_handler | action_handler.menu | ai | ai.move | body | body_anim | body.state | bonus | box | camera.follow | camera.shake | camera.tracking | character | character.collision | character.energy | damage | downloader | explosion | game | game.endofturn | game_mode | game.statechange | ghost | grapple.break | grapple.hook | grapple.node | ground_generator.element | index_server | jukebox | jukebox.cache | jukebox.play | lst_objects | map | map.collision | map.load | map.random | menu | mine | mouse | network | network.crc | network.crc_bad | network.traffic | network.turn_master | physical | physical.mem | physic.compute | physic.fall | physic.move | physic.overlapping | physic.pendulum | physic.physic | physic.position | physic.state | physic.sync | random | random.get | singleton | socket | sprite | team | test_rectangle | weapon | weapon.change | weapon.handposition | weapon.projectile | weapon.shoot | widget.border | wind | xml | xml.tree }\n");
-#endif
- exit(0);
+ PrintUsage(argv[0]);
+ exit(EXIT_SUCCESS);
break;
case 'v':
DisplayWelcomeMessage();
- exit(0);
+ exit(EXIT_SUCCESS);
break;
case 'p':
choice = MainMenu::PLAY;
@@ -397,6 +408,19 @@ void ParseArgs(int argc, char * argv[])
printf("Game-mode: %s\n", optarg);
Config::GetInstance()->SetGameMode(optarg);
break;
+ case 'r':
+ {
+ bool r;
+ r = Config::GetInstance()->RemovePersonalConfigFile();
+ if (!r)
+ exit(EXIT_FAILURE);
+ exit(EXIT_SUCCESS);
+ }
+ break;
+ default:
+ fprintf(stderr, "Unknow option %c", c);
+ PrintUsage(argv[0]);
+ exit(EXIT_FAILURE);
}
}
}
--
Wormux PKG
More information about the Pkg-games-commits
mailing list