Freeciv21
Develop your civilization from humble roots to a global empire
modinst.cpp
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 
14 #include <fc_config.h>
15 
16 #include <sys/stat.h>
17 
18 // utility
19 #include "fciconv.h"
20 #include "fcintl.h"
21 #include "log.h"
22 #include "rand.h"
23 #include "support.h"
24 
25 // common
26 #include "fc_interface.h"
27 
28 // modinst
29 #include "mpdb.h"
30 
31 #include "modinst.h"
32 
33 static char main_ii_filename[500];
34 static char scenario_ii_filename[500];
35 
40 {
41  char main_db_filename[500];
42  char scenario_db_filename[500];
43  struct stat buf;
44 
45  fc_snprintf(main_db_filename, sizeof(main_db_filename),
46  "%s/" DATASUBDIR "/" FCMP_CONTROLD "/mp.db",
47  qUtf8Printable(fcmp->inst_prefix));
48  fc_snprintf(scenario_db_filename, sizeof(scenario_db_filename),
49  "%s/scenarios/" FCMP_CONTROLD "/mp.db",
50  qUtf8Printable(fcmp->inst_prefix));
51 
53  "%s/" DATASUBDIR "/" FCMP_CONTROLD "/modpacks.db",
54  qUtf8Printable(fcmp->inst_prefix));
56  "%s/scenarios/" FCMP_CONTROLD "/modpacks.db",
57  qUtf8Printable(fcmp->inst_prefix));
58 
59  if (fc_stat(main_db_filename, &buf)) {
60  create_mpdb(main_db_filename, false);
62  } else {
63  open_mpdb(main_db_filename, false);
64  }
65 
66  if (fc_stat(scenario_db_filename, &buf)) {
67  create_mpdb(scenario_db_filename, true);
69  } else {
70  open_mpdb(scenario_db_filename, true);
71  }
72 }
73 
77 void fcmp_init()
78 {
79  init_nls();
81 
82  fc_srand(time(nullptr)); /* Needed at least for Windows version of
83  netfile_get_section_file() */
84 }
85 
90 {
91  /* log_init() was not done by fcmp_init(); we assume the caller called
92  * fcmp_parse_cmdline() (which sets up logging) in between */
93  log_close();
95  free_nls();
96 }
#define FCMP_CONTROLD
Definition: download.h:31
void free_libfreeciv()
Free misc resources allocated for libfreeciv.
void init_character_encodings(const char *my_internal_encoding, bool my_use_transliteration)
Must be called during the initialization phase of server and client to initialize the character encod...
Definition: fciconv.cpp:39
#define FC_DEFAULT_DATA_ENCODING
Definition: fciconv.h:69
void log_close()
Deinitialize logging module.
Definition: log.cpp:212
void fcmp_deinit()
Deinitialize modpack installer.
Definition: modinst.cpp:89
void load_install_info_lists(struct fcmp_params *fcmp)
Load all required install info lists.
Definition: modinst.cpp:39
static char main_ii_filename[500]
Definition: modinst.cpp:33
void fcmp_init()
Initialize modpack installer.
Definition: modinst.cpp:77
static char scenario_ii_filename[500]
Definition: modinst.cpp:34
struct fcmp_params fcmp
Definition: mpcli.cpp:35
void load_install_info_list(const char *filename)
Construct install info list from file.
Definition: mpdb.cpp:39
void create_mpdb(const char *filename, bool scenario_db)
Create modpack database.
Definition: mpdb.cpp:132
void open_mpdb(const char *filename, bool scenario_db)
Open existing database.
Definition: mpdb.cpp:177
void fc_srand(std::uint_fast32_t seed)
Initialize the generator; see comment at top of file.
Definition: rand.cpp:69
void free_nls()
Free memory allocated by Native Language Support.
Definition: shared.cpp:931
void init_nls()
Setup for Native Language Support, if configured to use it.
Definition: shared.cpp:871
QString inst_prefix
Definition: modinst.h:21
int fc_snprintf(char *str, size_t n, const char *format,...)
See also fc_utf8_snprintf_trunc(), fc_utf8_snprintf_rep().
Definition: support.cpp:537
int fc_stat(const char *filename, struct stat *buf)
Wrapper function for stat() with filename conversion to local encoding on Windows.
Definition: support.cpp:293