Skip to content

Commit

Permalink
Added support for wwivconfig to upgrade menus
Browse files Browse the repository at this point in the history
* Also fixed an issue with the enter/exit scripts being
  added as an action multiple times.
* Upgraded the wwiv revision number to 3 to denote JSON menus.
  • Loading branch information
wwiv committed Nov 12, 2020
1 parent 7a7946f commit a0ef0d6
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 18 deletions.
28 changes: 16 additions & 12 deletions sdk/menus/menu.cpp
Expand Up @@ -105,7 +105,6 @@ bool Menu56::Load() {
const auto name = StrCat(menu_name_, ".mnu.json");
JsonFile f(FilePath(dir, name), "menu", menu, 1);
return f.Load();

}

bool Menu56::Save() {
Expand Down Expand Up @@ -143,6 +142,12 @@ std::optional<Menu56> Create56MenuFrom43(const Menu430& m4) {
h.acs = ae.get();
}
h.password = oh.szPassWord;
if (oh.szScript[0]) {
h.enter_actions.emplace_back(CreateActionFrom43Execute(oh.szScript));
}
if (oh.szExitScript[0]) {
h.exit_actions.emplace_back(CreateActionFrom43Execute(oh.szScript));
}

// Add the items now.
for (const auto& o : m4.recs) {
Expand All @@ -154,22 +159,21 @@ std::optional<Menu56> Create56MenuFrom43(const Menu430& m4) {
i.instance_message = o.szInstanceMessage;

{
// TODO(rushfan): Add support for co-sysop, sysop, restrict into ACS.
// TODO(rushfan): restrict into ACS.
acs::AcsExpr ae;
ae.min_sl(o.nMinSL).max_sl(o.iMaxSL).min_dsl(o.nMinDSL).max_dsl(o.iMaxDSL).ar_int(o.uAR).dar_int(o.uDAR);
ae.min_sl(o.nMinSL)
.max_sl(o.iMaxSL)
.min_dsl(o.nMinDSL)
.max_dsl(o.iMaxDSL)
.ar_int(o.uAR)
.dar_int(o.uDAR);
ae.sysop(o.nSysop).cosysop(o.nCoSysop);
i.acs = ae.get();
}

i.password = o.szPassWord;
i.actions.emplace_back(CreateActionFrom43Execute(o.szExecute));

if (oh.szScript[0]) {
h.enter_actions.emplace_back(CreateActionFrom43Execute(oh.szScript));
}
if (oh.szExitScript[0]) {
h.exit_actions.emplace_back(CreateActionFrom43Execute(oh.szScript));
}
h.items.emplace_back(i);
}

Expand All @@ -192,7 +196,8 @@ menu_numflag_t to_menu_numflag_t(int n) {

// What to log for this command.
menu_logtype_t to_menu_logtype(int n) {
switch (n) { case MENU_LOGTYPE_NONE:
switch (n) {
case MENU_LOGTYPE_NONE:
return menu_logtype_t::none;
case MENU_LOGTYPE_COMMAND:
return menu_logtype_t::command;
Expand All @@ -214,5 +219,4 @@ menu_help_display_t to_menu_help_display(int n) {
return menu_help_display_t::always;
}


}
} // namespace wwiv::sdk::menus
77 changes: 72 additions & 5 deletions wwivconfig/convert.cpp
Expand Up @@ -39,18 +39,21 @@
#include "sdk/acs/expr.h"
#include "sdk/files/dirs.h"
// ReSharper disable once CppUnusedIncludeDirective
#include "core/findfiles.h"
#include "sdk/files/dirs_cereal.h"
#include "sdk/menus/menu.h"
#include "wwivconfig/archivers.h"
#include "wwivconfig/convert_jsonfile.h"
#include <cstring>
#include <filesystem>

using std::string;
using std::vector;
using namespace wwiv::core;
using namespace wwiv::sdk;
using namespace wwiv::sdk::files;
using namespace wwiv::sdk::menus;
using namespace wwiv::sdk;
using namespace wwiv::strings;
using std::string;
using std::vector;

struct user_config {
char name[31]; // verify against a user
Expand Down Expand Up @@ -340,7 +343,7 @@ chain_t ConvertJsonFile<chain_55_t, chain_t>::ConvertType(const chain_55_t& oc)

static bool convert_to_v2(UIWindow* window, const std::string& datadir,
const std::string& config_filename) {
ShowBanner(window, "Updating to 5.2.2+ format...");
ShowBanner(window, "Updating to 5.2+ v2 format...");

ConvertJsonFile<subboard_52_t, subboard_t> cs(datadir, SUBS_JSON, "subs", 0, 1);
cs.Convert();
Expand All @@ -355,19 +358,83 @@ static bool convert_to_v2(UIWindow* window, const std::string& datadir,
return update_config_revision_number(config_filename, 2);
}

static bool convert_menu(const std::string& menu_dir, const std::string& menu_set,
const std::string& menu_name) {

const auto dir = FilePath(menu_dir, menu_set);
const auto fname = StrCat(menu_name, ".mnu.json");
const auto path = FilePath(dir, fname);
if (File::Exists(path)) {
LOG(INFO) << "Menu already exists in 5.6+ format: " << path.string();
return true;
}

const Menu430 m4(menu_dir, menu_set, menu_name);
if (m4.initialized()) {
if (auto om5 = Create56MenuFrom43(m4)) {
auto& m5 = om5.value();
if (m5.Save()) {
LOG(INFO) << "Converted menu: " << menu_set << File::pathSeparatorChar << menu_name
<< std::endl;
return true;
}
}
}
return false;
}

static bool convert_to_v3(UIWindow* window, const std::string& config_filename) {
ShowBanner(window, "Updating to 5.2+ v3 format...");
LOG(INFO) << "Updating to 5.2+ v3 format...";
std::filesystem::path config_path{config_filename};

const Config config(config_path.parent_path().string());
if (!config.IsInitialized()) {
LOG(ERROR) << "Failed to open CONFIG.DAT in: " << config_path.string();
return false;
}

auto dirs = FindFiles(FilePath(config.menudir(), "*"), FindFiles::FindFilesType::directories);

for (const auto& d : dirs) {
const auto& menu_set = d.name;
const auto path = FilePath(config.menudir(), menu_set);
auto menus = FindFiles(FilePath(path, "*"), FindFiles::FindFilesType::files, FindFiles::WinNameType::long_name);
for (const auto& m : menus) {
auto lm = ToStringLowerCase(m.name);
if (ends_with(lm, ".mnu")) {
const auto name = m.name.substr(0, m.name.size() - 4 );
if (!convert_menu(config.menudir(), menu_set, name)) {
LOG(ERROR) << "Unable to convert 4.3 menu:" << menu_set << File::pathSeparatorChar
<< name << std::endl;
}
}
}
}

// Mark config.dat as upgraded.
return update_config_revision_number(config_filename, 3);
}


config_upgrade_state_t ensure_latest_5x_config(UIWindow* window, const std::string& datadir,
const std::string& config_filename,
const uint32_t config_revision_number) {
if (config_revision_number >= 2) {
if (config_revision_number >= 3) {
return config_upgrade_state_t::already_latest;
}
// add others
if (config_revision_number < 1) {
convert_to_v1(window, datadir, config_filename);
}
if (config_revision_number < 2) {
// Versioned subs, chains, and dirs
convert_to_v2(window, datadir, config_filename);
}
if (config_revision_number < 3) {
// menus in JSON format.
convert_to_v3(window, config_filename);
}
return config_upgrade_state_t::upgraded;
}

Expand Down
1 change: 0 additions & 1 deletion wwivutil/menus/menus.cpp
Expand Up @@ -144,7 +144,6 @@ class MenusConvertCommand : public UtilCommand {

if (auto om5 = Create56MenuFrom43(m4)) {
auto& m5 = om5.value();
//DisplayMenu(m5);
return m5.Save() ? 0 : 1;
}
std::cout << "Failed to create 5.6 style menu from 4.3x style menu.";
Expand Down

0 comments on commit a0ef0d6

Please sign in to comment.