Beispiel #1
0
static void edit_net(const Config& config, Networks& networks, int nn) {
  static const vector<pair<network_type_t, string>> nettypes = {
    {network_type_t::wwivnet, "WWIVnet "},
    {network_type_t::ftn, "Fido    "},
    {network_type_t::internet, "Internet"}
  };

  Subs subs(syscfg.datadir, networks.networks());
  bool subs_loaded = subs.Load();

  net_networks_rec& n = networks.at(nn);
  const string orig_network_name(n.name);

  const int COL1_POSITION = 14;
  int y = 1;
  EditItems items{
    new ToggleEditItem<network_type_t>(out, COL1_POSITION, y++, nettypes, &n.type),
    new StringEditItem<char*>(COL1_POSITION, y++, 15, n.name, false),
    new NumberEditItem<uint16_t>(COL1_POSITION, y++, &n.sysnum),
    new StringFilePathItem(COL1_POSITION, y++, 60, config.root_directory(), n.dir)
  };
  if (n.type == network_type_t::ftn) {
    auto net_dir = File::MakeAbsolutePath(config.root_directory(), n.dir);
    items.add(new FidoNetworkConfigSubDialog(net_dir, COL1_POSITION, y++, "Network Settings", 76, n));
    items.add(new FidoPacketConfigSubDialog(net_dir, COL1_POSITION, y++, "Node Settings", 76, config, n));
  }

  const string title = StrCat("Network Configuration; Net #", nn);
  unique_ptr<CursesWindow> window(out->CreateBoxedWindow(title, items.size() + 2, 76));
  items.set_curses_io(out, window.get());

  y = 1;
  window->PutsXY(2, y++, "Net Type  :");
  window->PutsXY(2, y++, "Net Name  :");
  window->PutsXY(2, y++, "Node #    :");
  window->PutsXY(2, y++, "Directory :");
  if (n.type == network_type_t::ftn) {
    window->PutsXY(2, y++, "Settings  :");
    window->PutsXY(2, y++, "Addresses :");
  }
  items.Run();

  if (subs_loaded && orig_network_name != n.name) {
    subs.Save();
  }

  networks.Save();
}
Beispiel #2
0
static void edit_net(Networks& networks, int nn) {
  static const vector<string> nettypes = {
    "WWIVnet ",
    "Fido    ",
    "Internet",
  };

  out->Cls(ACS_CKBOARD);
  unique_ptr<CursesWindow> window(out->CreateBoxedWindow("Network Configuration", 6, 76));
  net_networks_rec& n = networks.at(nn);
  char szOldNetworkName[20];
  strcpy(szOldNetworkName, n.name);

  if (n.type >= nettypes.size()) {
    n.type = 0;
  }

  const int COL1_POSITION = 14;
  EditItems items{
    new ToggleEditItem<uint8_t>(COL1_POSITION, 1, nettypes, &n.type),
    new StringEditItem<char*>(COL1_POSITION, 2, 15, n.name, false),
    new NumberEditItem<uint16_t>(COL1_POSITION, 3, &n.sysnum),
    new FilePathItem(COL1_POSITION, 4, 60, n.dir),
  };
  items.set_curses_io(out, window.get());

  int y = 1;
  window->PutsXY(2, y++, "Net Type  :");
  window->PutsXY(2, y++, "Net Name  :");
  window->PutsXY(2, y++, "Node #    :");
  window->PutsXY(2, y++, "Directory :");

  items.Run();

  if (strcmp(szOldNetworkName, n.name)) {
    const string input_filename = StringPrintf("%ssubs.xtr", syscfg.datadir);
    const string output_filename = StringPrintf("%ssubsxtr.new", syscfg.datadir);
    FILE *pInputFile = fopen(input_filename.c_str(), "r");
    if (pInputFile) {
      FILE *pOutputFile = fopen(output_filename.c_str(), "w");
      if (pOutputFile) {
        char buffer[255];
        while (fgets(buffer, 80, pInputFile)) {
          if (buffer[0] == '$') {
            char* ss = strchr(buffer, ' ');
            if (ss) {
              *ss = 0;
              if (strcasecmp(szOldNetworkName, buffer + 1) == 0) {
                fprintf(pOutputFile, "$%s %s", n.name, ss + 1);
              } else {
                fprintf(pOutputFile, "%s %s", buffer, ss + 1);
              }
            } else {
              fprintf(pOutputFile, "%s", buffer);
            }
          } else {
            fprintf(pOutputFile, "%s", buffer);
          }
        }
        fclose(pOutputFile);
        fclose(pInputFile);
        const string old_filename = StringPrintf("%ssubsxtr.old", syscfg.datadir);
        File::Remove(old_filename);
        File::Rename(input_filename, old_filename);
        File::Remove(input_filename);
        File::Rename(output_filename, input_filename);
      } else {
        fclose(pInputFile);
      }
    }
  }
  networks.Save();
}