Skip to content

Commit

Permalink
More progress on useing std::filesystem::path in more places vs. std:…
Browse files Browse the repository at this point in the history
…:string

I think with this most of them are done now, and it builds.
  • Loading branch information
wwiv committed Jan 21, 2023
1 parent 41a2b48 commit 408d3c2
Show file tree
Hide file tree
Showing 30 changed files with 109 additions and 101 deletions.
2 changes: 1 addition & 1 deletion bbs/bbslist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ bool SaveToJSON(const std::filesystem::path& dir, const std::string& filename,
return true;
}

static bool ConvertLegacyList(const std::string& dir, const std::string& legacy_filename,
static bool ConvertLegacyList(const std::filesystem::path& dir, const std::string& legacy_filename,
std::vector<BbsListEntry>& entries) {

TextFile legacy_file(FilePath(dir, legacy_filename), "r");
Expand Down
2 changes: 1 addition & 1 deletion bbs/diredit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ void insert_dir(int n) {
files::directory_t r{};
r.name = "** NEW DIR **";
r.filename = "noname";
r.path = a()->config()->dloadsdir();
r.path = a()->config()->dloadsdir().string();
r.acs = "user.sl >= 10";
r.maxfiles = 500;
r.mask = 0;
Expand Down
10 changes: 6 additions & 4 deletions bbs/dropfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,12 @@ void CreateDoorSysDropFile() {
0); // kb dl/day max
file.Write(line);
const auto birthday_date = u.birthday_mmddyy();
const auto gfilesdir = a()->config()->gfilesdir();
const auto gfilesdir = a()->config()->gfilesdir().string();
const auto datadir = a()->config()->datadir().string();
const auto t = times();
line = fmt::sprintf("%s\n%s\n%s\n%s\n%s\n%s\n%c\n%c\n%c\n%u\n%u\n%s\n%-.5s\n%s\n",
birthday_date,
a()->config()->datadir(), gfilesdir,
datadir, gfilesdir,
a()->config()->sysop_name(), u.name(),
"00:01", // event time
'Y',
Expand Down Expand Up @@ -508,9 +509,10 @@ std::string create_chain_file() {
u.gender(), u.gold(), u.laston(),
u.screen_width(), u.screen_lines(), u.sl()));
const auto temporary_log_filename = instance_sysoplog_filename();
const auto gfilesdir = a()->config()->gfilesdir();
const auto gfilesdir = a()->config()->gfilesdir().string();
const auto datadir = a()->config()->datadir().string();
file.Write(fmt::sprintf("%d\n%d\n%d\n%u\n%8ld.00\n%s\n%s\n%s\n", cs(), so(), okansi(),
a()->sess().incom(), nsl(), gfilesdir, a()->config()->datadir(),
a()->sess().incom(), nsl(), gfilesdir, datadir,
temporary_log_filename));
if (a()->sess().using_modem()) {
file.WriteLine(a()->modem_speed_);
Expand Down
5 changes: 3 additions & 2 deletions bbs/extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
#include "sdk/config.h"
#include "sdk/filenames.h"

#include <filesystem>
#include <string>

using namespace wwiv::core;
using namespace wwiv::strings;

static std::optional<std::string> get_extract_dir() {
static std::optional<std::filesystem::path> get_extract_dir() {
bout.print_help_file(MEXTRACT_NOEXT);
do {
bout.outstr("|#5(Q=Quit) Which (D,G,T) ? ");
Expand All @@ -42,7 +43,7 @@ static std::optional<std::string> get_extract_dir() {
case 'D':
return a()->config()->datadir();
case 'T':
return a()->sess().dirs().temp_directory().string();
return a()->sess().dirs().temp_directory();
case '?':
bout.print_help_file(MEXTRACT_NOEXT);
break;
Expand Down
3 changes: 2 additions & 1 deletion bbs/msgscan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ static void HandleScanReadAutoReply(int& msgnum, const char* user_input,
}

if (user_input[0] == 'O' && (so() || lcs())) {
show_files("*.frm", a()->config()->gfilesdir().c_str());
const auto gfilesdir = a()->config()->gfilesdir().string();
show_files("*.frm", gfilesdir.c_str());
bout.outstr("|#2Which form letter: ");
auto fn = bin.input_filename("", 8);
if (fn.empty()) {
Expand Down
3 changes: 2 additions & 1 deletion bbs/readmail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,8 @@ void readmail(bool newmail_only) {
break;
case 'O': {
if (cs() && okmail && m.fromuser != 65535 && nn != 255) {
show_files("*.frm", a()->config()->gfilesdir().c_str());
const auto gfilesdir = a()->config()->gfilesdir().string();
show_files("*.frm", gfilesdir.c_str());
bout.outstr("|#2Which form letter: ");
auto user_input = bin.input(8, true);
if (user_input.empty()) {
Expand Down
2 changes: 1 addition & 1 deletion bbs/wfc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ std::tuple<wfc_events_t, int> WFC::doWFCEvents() {
case 'W': {
Clear();
write_inst(INST_LOC_TEDIT, 0, INST_FLAGS_NONE);
bout.print("|#1Edit {}<filename>: \r\n", a()->config()->gfilesdir());
bout.print("|#1Edit {}<filename>: \r\n", a()->config()->gfilesdir().string());
text_edit();
} break;
// Print Yesterday's Log
Expand Down
3 changes: 2 additions & 1 deletion bbs/xinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ bool Application::ReadConfig() {

if (!config_->versioned_config_dat()) {
const auto msg = fmt::format(
"Please run WWIVconfig to upgrade {} to the most recent version.", config_->config_filename());
"Please run WWIVconfig to upgrade {} to the most recent version.",
config_->config_filename().string());
std::cerr << msg << std::endl;
LOG(ERROR) << msg;
sleep_for(seconds(2));
Expand Down
17 changes: 7 additions & 10 deletions binkp/binkp_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
/* either express or implied. See the License for the specific */
/* language governing permissions and limitations under the License. */
/**************************************************************************/
#ifndef __INCLUDED_NETWORKB_BINKP_CONFIG_H__
#define __INCLUDED_NETWORKB_BINKP_CONFIG_H__
#ifndef INCLUDED_NETWORKB_BINKP_CONFIG_H
#define INCLUDED_NETWORKB_BINKP_CONFIG_H

#include "sdk/net/binkp.h"
#include "sdk/net/callout.h"
Expand All @@ -27,8 +27,7 @@
#include <memory>
#include <string>

namespace wwiv {
namespace net {
namespace wwiv::net {

class BinkConfig final {
public:
Expand All @@ -45,7 +44,7 @@ class BinkConfig final {
[[nodiscard]] std::string callout_fido_address() const { return callout_fido_node_; }
[[nodiscard]] std::string system_name() const { return system_name_; }
[[nodiscard]] std::string sysop_name() const { return sysop_name_; }
[[nodiscard]] std::string gfiles_directory() const { return gfiles_directory_; }
[[nodiscard]] std::filesystem::path gfiles_directory() const { return gfiles_directory_; }
[[nodiscard]] std::string callout_network_name() const { return callout_network_name_; }
/** Gets net.dir in absolute form for the network named network_name */
[[nodiscard]] std::filesystem::path network_dir(const std::string& network_name) const;
Expand Down Expand Up @@ -79,14 +78,13 @@ class BinkConfig final {

private:
const sdk::Config& config_;
std::string home_dir_;

int callout_wwivnet_node_{0};
std::string callout_fido_node_;
std::string system_name_;
std::string callout_network_name_ = "wwivnet";
std::string sysop_name_;
std::string gfiles_directory_;
std::filesystem::path gfiles_directory_;
const wwiv::sdk::Networks networks_;
std::map<const std::string, std::unique_ptr<wwiv::sdk::Callout>> callouts_;
std::unique_ptr<wwiv::sdk::Binkp> binkp_;
Expand All @@ -99,7 +97,6 @@ class BinkConfig final {
std::string session_identifier_;
};

} // namespace net
} // namespace wwiv
} // namespace

#endif // __INCLUDED_NETWORKB_BINKP_CONFIG_H__
#endif // INCLUDED_NETWORKB_BINKP_CONFIG_H
3 changes: 1 addition & 2 deletions binkp/net_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ using namespace wwiv::sdk;

namespace wwiv::net {

NetworkLog::NetworkLog(std::string gfiles_directory)
: gfiles_directory_(std::move(gfiles_directory)) {}
NetworkLog::NetworkLog(const std::filesystem::path& d) : gfiles_directory_(d) {}
NetworkLog::~NetworkLog() = default;

std::string NetworkLog::CreateLogLine(time_t time, NetworkSide side, int node,
Expand Down
5 changes: 3 additions & 2 deletions binkp/net_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "sdk/config.h"
#include <chrono>
#include <ctime>
#include <filesystem>
#include <string>

namespace wwiv::net {
Expand All @@ -38,7 +39,7 @@ enum class NetworkSide { FROM, TO };

class NetworkLog final {
public:
explicit NetworkLog(std::string gfiles_directory);
explicit NetworkLog(const std::filesystem::path& gfiles_directory);
~NetworkLog();

bool Log(time_t time, NetworkSide side, int node, unsigned int bytes_sent,
Expand All @@ -53,7 +54,7 @@ class NetworkLog final {
const std::string& network_name) const;

private:
std::string gfiles_directory_;
const std::filesystem::path gfiles_directory_;
};

} // namespace wwiv::net
Expand Down
11 changes: 6 additions & 5 deletions common/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ namespace wwiv::common {
class Dirs {
public:
explicit Dirs(const std::filesystem::path& bbsdir);
Dirs(const std::string& temp, const std::string& batch, const std::string& qwk,
std::string gfiles, const std::string& scratch)
Dirs(const std::filesystem::path& temp, const std::filesystem::path& batch,
const std::filesystem::path& qwk, const std::filesystem::path& gfiles,
const std::filesystem::path& scratch)
: temp_directory_(temp), batch_directory_(batch), qwk_directory_(qwk),
gfiles_directory_(std::move(gfiles)), scratch_directory_(scratch) {}
gfiles_directory_(gfiles), scratch_directory_(scratch) {}

[[nodiscard]] const std::filesystem::path& temp_directory() const noexcept { return temp_directory_; }
void temp_directory(const std::string& d) { temp_directory_ = d; }
Expand All @@ -69,7 +70,7 @@ class Dirs {
[[nodiscard]] const std::filesystem::path& qwk_directory() const noexcept { return qwk_directory_; }
void qwk_directory(const std::string& d) { qwk_directory_ = d; }

[[nodiscard]] const std::string& gfiles_directory() const noexcept { return gfiles_directory_; }
[[nodiscard]] const std::filesystem::path& gfiles_directory() const noexcept { return gfiles_directory_; }
void gfiles_directory(const std::string& d) { gfiles_directory_ = d; }

[[nodiscard]] std::filesystem::path current_menu_directory() const noexcept {
Expand All @@ -96,7 +97,7 @@ class Dirs {
std::filesystem::path batch_directory_;
std::filesystem::path qwk_directory_;
std::filesystem::path current_menu_directory_;
std::string gfiles_directory_;
std::filesystem::path gfiles_directory_;
std::filesystem::path scratch_directory_;
};

Expand Down
2 changes: 1 addition & 1 deletion core/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void Logger::Init(int argc, char** argv, LoggerConfig& c) {
cmdline.Parse();

const auto l = cmdline.arg("logdir");
auto logdir = cmdline.logdir();
auto logdir = std::filesystem::path(cmdline.logdir());
if (l.is_default() && c.logdir_fn_) {
if (const auto logdir_from_fn = c.logdir_fn_(cmdline.bbsdir()); !logdir_from_fn.empty()) {
logdir = logdir_from_fn;
Expand Down
3 changes: 2 additions & 1 deletion core/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "core/os.h"

#include <filesystem>
#include <functional>
#include <memory>
#include <sstream>
Expand Down Expand Up @@ -120,7 +121,7 @@ class Appender {
typedef std::unordered_map<LoggerLevel, std::unordered_set<std::shared_ptr<Appender>>>
log_to_map_t;
typedef std::function<std::string()> timestamp_fn;
typedef std::function<std::string(std::string)> logdir_fn;
typedef std::function<std::filesystem::path(std::filesystem::path)> logdir_fn;


class LoggerConfig {
Expand Down
16 changes: 8 additions & 8 deletions sdk/bbs_directories.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ namespace wwiv::sdk {

class BbsDirectories {
public:
[[nodiscard]] virtual std::string root_directory() const = 0;
[[nodiscard]] virtual std::string datadir() const = 0;
[[nodiscard]] virtual std::string msgsdir() const = 0;
[[nodiscard]] virtual std::string gfilesdir() const = 0;
[[nodiscard]] virtual std::string menudir() const = 0;
[[nodiscard]] virtual std::string dloadsdir() const = 0;
[[nodiscard]] virtual std::string scriptdir() const = 0;
[[nodiscard]] virtual std::string logdir() const = 0;
[[nodiscard]] virtual std::filesystem::path root_directory() const = 0;
[[nodiscard]] virtual std::filesystem::path datadir() const = 0;
[[nodiscard]] virtual std::filesystem::path msgsdir() const = 0;
[[nodiscard]] virtual std::filesystem::path gfilesdir() const = 0;
[[nodiscard]] virtual std::filesystem::path menudir() const = 0;
[[nodiscard]] virtual std::filesystem::path dloadsdir() const = 0;
[[nodiscard]] virtual std::filesystem::path scriptdir() const = 0;
[[nodiscard]] virtual std::filesystem::path logdir() const = 0;

/**
* Returns the scrarch directory for a given node.
Expand Down
3 changes: 2 additions & 1 deletion sdk/chains.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "core/wwivport.h"
#include "sdk/config.h"
#include <initializer_list>
#include <filesystem>
#include <set>
#include <string>
#include <vector>
Expand Down Expand Up @@ -129,7 +130,7 @@ class Chains final {
bool SaveToDat();

bool initialized_{false};
std::string datadir_;
std::filesystem::path datadir_;
std::vector<chain_t> chains_;
};

Expand Down
26 changes: 13 additions & 13 deletions sdk/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void Config::system_phone(const std::string& d) { config_.systemphone = d; }

void Config::system_password(const std::string& d) { config_.systempw = d; }

std::string Config::config_filename() const {
std::filesystem::path Config::config_filename() const {
return FilePath(root_directory(), CONFIG_JSON).string();
}

Expand All @@ -182,21 +182,21 @@ const config_t& Config::to_config_t() const {
return config_;
}

void Config::set_paths_for_test(const std::string& datadir, const std::string& msgsdir,
const std::string& gfilesdir, const std::string& menudir,
const std::string& dloadsdir, const std::string& scriptdir) {
void Config::set_paths_for_test(const std::filesystem::path& datadir, const std::filesystem::path& msgsdir,
const std::filesystem::path& gfilesdir, const std::filesystem::path& menudir,
const std::filesystem::path& dloadsdir, const std::filesystem::path& scriptdir) {
datadir_ = datadir;
config_.datadir = datadir;
config_.datadir = datadir.string();
msgsdir_ = msgsdir;
config_.msgsdir = msgsdir;
config_.msgsdir = msgsdir.string();
gfilesdir_ = gfilesdir;
config_.gfilesdir = gfilesdir;
config_.gfilesdir = gfilesdir.string();
menudir_ = menudir;
config_.menudir = menudir;
config_.menudir = menudir.string();
dloadsdir_ = dloadsdir;
config_.dloadsdir = dloadsdir;
config_.dloadsdir = dloadsdir.string();
script_dir_ = scriptdir;
config_.scriptdir = scriptdir;
config_.scriptdir = scriptdir.string();
}

static void set_script_flag(uint16_t& data, uint16_t flg, bool on) {
Expand Down Expand Up @@ -253,19 +253,19 @@ void Config::script_package_os_enabled(bool b) noexcept {
set_script_flag(config_.script_flags, script_flag_enable_os, b);
}

std::string Config::to_abs_path(const std::string& dir) const {
std::filesystem::path Config::to_abs_path(const std::string& dir) const {
return File::absolute(root_directory_, dir).string();
}

std::string LogDirFromConfig(const std::string& bbsdir) {
std::filesystem::path LogDirFromConfig(const std::filesystem::path& bbsdir) {
const Config config{bbsdir};
if (!config.IsInitialized()) {
return {};
}
return config.logdir();
}

std::unique_ptr<Config> load_any_config(const std::string& bbsdir) {
std::unique_ptr<Config> load_any_config(const std::filesystem::path& bbsdir) {
auto config = std::make_unique<Config>(bbsdir);
if (config->IsInitialized()) {
return config;
Expand Down
Loading

0 comments on commit 408d3c2

Please sign in to comment.