DELTA 17690 195 3154
SVN  ²oå)rÐ1 …W €J d…h€„) G €I Iœ@€� G © Iœ@€‚  G ¸ Iœ@€†; ƒ&Ÿ €�# \¨s€�` W¨w€„ W¨w€„ `¨s€‚p `¨s£ [¨s€…# ‚2¬j€†y G � Iœ@€–mfc_config.h>
#endif

#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endifdependencies */
#include "cvercmp.h"

/* utility */
#include "capability.h"
#include "fcintl.h"
#include "log.h"
#include "netintf.h"
#include "netfile.h"
#include "registry.h"

/* modinst */
#include "download.h"

static const char *download_modpack_recursive(const char *URL,
                                              const struct fcmp_params *fcmp,
                                              dl_msg_callback mcb,
                                              dl_pb_callback pbcb,
                                              int recursion);

****
  Message callback called by netfile module when downloading files.
*/
static void nf_cb(const char *msg, void *data)
{
  dl_msg_callback mcb = (dl_msg_callback) data;

  if (mcb != NULL) {
    mcb(msg);
  }
}

****
  Download modpack from a given URL
*/
const char *download_modpack(const char *URL,
			     const struct fcmp_params *fcmp,
                             dl_msg_callback mcb,
                             dl_pb_callback pbcb)
{
  return download_modpack_recursive(URL, fcmp, mcb, pbcb, 0);
}

****
  Download modpack and its recursive dependencies.
*/
static const char *download_modpack_recursive(const char *URL,
                                              const struct fcmp_params *fcmp,
                                              dl_msg_callback mcb,
                                              dl_pb_callback pbcb,
                                              int recursion)
{
  char local_dir[2048];
  char local_name[2048];
  int start_idx;
  int filenbr, total_files;
  struct section_file *control;
  const char *control_capstr;
  const char *baseURLpart;
  enum modpack_type type;
  const char *typestr;
  const char *mpname;
  const char *mpver;
  char baseURL[2048];
  char fileURL[2048];
  const char *src_name;
  bool partial_failure = FALSE;
  int dep;
  const char *dep_name;

  if (recursion > 5) {
    return _("Recursive dependencies too deep");
  }_("Installing modpack %s from %s"), URL + start_idx, URL);

  if (fcmp->inst_prefix == NULL) {
    return _("Cannot install to given directory hierarchy");
  }

  if (mcb != NULL) {
    char buf[2048];

    fc_snprintf(buf, sizeof(buf), _("Downloading \"%s\" control file."), URL + start_idx);
    mcb(buf);
  }

  control = netfile_get_section_file(URL, nf_cb, mcb);

  if (control == NULL) {
    return _("Failed to get and parse modpack control file");
  }

  control_capstr = secfile_lookup_str(control, "info.options");
  if (control_capstr == NULL) {
    secfile_destroy(control);
    return _("Modpack control file has no capability string");
  }

  if (!has_capabilities(MODPACK_CAPSTR, control_capstr)) {
    log_error("Incompatible control file:");
    log_error("  control file options: %s", control_capstr);
    log_error("  supported options:    %s", MODPACK_CAPSTR);

    secfile_destroy(control);

    return _("Modpack control file is incompatible");  
  }

  mpname = secfile_lookup_str(control, "info.name");
  if (mpname == NULL) {
    return _("Modpack name not defined in control file");
  }
  mpver = secfile_lookup_str(control, "info.version");
  if (mpver  == NULL) {
    return _("Modpack version not defined in control file");
  }

  typestr = secfile_lookup_str(control, "info.type");
  type = modpack_type_by_name(typestr, fc_strcasecmp);
  if (!modpack_type_is_valid(type)) {
    return _("Illegal modpack type");
  }

  if (type == MPT_SCENARIO) {
    fc_snprintf(local_dir, sizeof(local_dir),
                "%s/scenarios", fcmp->inst_prefix);
  } else {
    fc_snprintf(local_dir, sizeof(local_dir),
                "%s/" DATASUBDIR, fcmp->inst_prefix);
  }

  baseURLpart = secfile_lookup_str(control, "info.baseURL");

  if (baseURLpart[0] == '.') {
    char URLstart[start_idx];

    strncpy(URLstart, URL, start_idx - 2);
    URLstart[start_idx - 1] = '\0';
    fc_snprintf(baseURL, sizeof(baseURL), "%s%s",
                URLstart, baseURLpart + 1);
  } else {
    strncpy(baseURL, baseURLpart, sizeof(baseURL));
  }

  dep = 0;
  do {
    dep_dependencies.list%d.modpack", dep);
    if (dep_name != NULL) {
      const char *dep_URL;
      const char *inst_ver;
      const char *dep_typestr;
      enum modpack_type dep_type;
      bool needed = TRUE;

      dep_URL "dependencies.list%d.URL", dep);

      if (dep_URL == NULL) {
        return _("Dependency has no download URL");
      }

      dep_typestr = secfile_lookup_str(control, "dependencies.list%d.type", dep);
      dep_type = modpack_type_by_name(dep_typestr, fc_strcasecmp);
      if (!modpack_type_is_valid(dep_type)) {
        return _("Illegal dependency modpack type");
      }

      inst_ver = get_installed_version(dep_name, type);

      if (inst_ver != NULL) {
        const char *dep_ver;

        dep_ver   "dependencies.list%d.version", dep);

        if (dep_ver != NULL && cvercmp_max(dep_ver, inst_ver)) {
          needed = FALSE;
        }
      }

      if (needed) {
        const char *msg;

        if (mcb != NULL) {
          mcb(_("Download dependency modpack"));
        }

        msg = download_modpack_recursive(dep_URL, fcmp, mcb, pbcb, recursion + 1);

        if (msg != NULL) {
          return msg;
        }
      }
    }

    dep++;
    
  } while (dep_name != NULL);


  total_files = 0;
  do {
    src_s.list%d.src", total_files);

    if (src_name != NULL) {
      total_files++;
    }
  } while (src_name != NULL);

  if (pbcb != NULL) {
    /* Control file already downloaded */
    pbcb(1, total_files + 1);
  }

  filenbr = 0;
  for (filenbr = 0; filenbr < total_files; filenbr++) {
    const char *dest_name;
    int i;
    bool illegal_filename = FALSE;

    src_s.list%d.src", filenbr);

    dest_ "files.list%d.dest", filenbr);

    if (dest_name == NULL || dest_name[0] == '\0') {
      /* Missing dest name is ok, we just default to src_name */
      dest_name = src_name;
    }

    for (i = 0; dest_name[i] != '\0'; i++) {
      if (dest_name[i] == '.' && dest_name[i+1] == '.') {
        if (mcb != NULL) {
          char buf[2048];

          fc_snprintf(buf, sizeof(buf), _("Illegal path for %s"),
                      dest_name);
          mcb(buf);
        }
        partial_failure = TRUE;
        illegal_filename = TRUE;
      }
    }

    if (!illegal_filename) {
      fc_snprintf(local_name, sizeof(local_name),
                  "%s/%s", local_dir, dest_mcb != NULL) {
        char buf[2048];

        fc_snprintf(buf, sizeof(buf), _("Downloading %s"), src_name);
        mcb(buf);
      }

      fc_snprintf(fileURL, sizeof(fileURL), "%s/%s", baseURL, src_name);
      log_debug("%s", fileURL);
      if (!netfile_download_file(fileURL, local_name, nf_cb, mcb)) {
        if (mcb != NULL) {
          char buf[2048];

          fc_snprintf(buf, sizeof(buf), _("Failed to download %s"),
                      src_name);
          mcb(buf);
        }
        partial_failure = TRUE;
      }
    }

    if (pbcb != NULL) {
      /* Count download of control file also */
      pbcb(filenbr + 2, total_files + 1);
    }
  }

  if (partial_failure) {
    secfile_destroy(control);

    return _("Some parts of the modpack failed to install.");
  }

  update_install_info_lists(mpname, type, mpver);

  secfile_destroy(control);

  return NULL;
}

****
  Download modpack list
*/
const char *download_modpack_list(const struct fcmp_params *fcmp,
                                  modpack_list_setup_cb cb,
                                  dl_msg_callback mcb)
{
  struct section_file *list_file;
  const char *list_capstr;
  int modpack_count;
  const char *msg;
  const char *mp_name;

  list_file = netfile_get_section_file(fcmp->list_url, nf_cb, mcb);

  if (list_file == NULL) {
    return _("Cannot fetch and parse modpack list");
  }

  list_capstr = secfile_lookup_str(list_file, "info.options");
  if (list_capstr == NULL) {
    secfile_destroy(list_file);
    return _("Modpack list has no capability string");
  }

  if (!has_capabilities(MODLIST_CAPSTR, list_capstr)) {
    log_error("Incompatible modpack list file:");
    log_error("  list file options: %s", list_capstr);
    log_error("  supported options: %s", MODLIST_CAPSTR);

    secfile_destroy(list_file);

    return _("Modpack list is incompatible");  
  }

  msg = secfile_lookup_str_default(list_file, NULL, "info.message");

  if (msg != NULL) {
    mcb(msg);
  }

  modpack_count = 0;
  do {
    const char *mpURL;
    const char *mpver;
    const char *mplic;
    const char *mp_type_str;
    const char *mp_subtype;
    const char *mp_notes;

    mp_name = secfile_lookup_str_default(list_file, NULL,
                                         "modpacks.list%d.name", modpack_count);
    mpver = secfile_lookup_str_default(list_file, NULL,
                                       "modpacks.list%d.version",
                                       modpack_count);
    mplic = secfile_lookup_str_default(list_file, NULL,
                                       "modpacks.list%d.license",
                                       modpack_count);
    mp_type_str = secfile_lookup_str_default(list_file, NULL,
                                             "modpacks.list%d.type",
                                             modpack_count);
    mp_subtype = secfile_lookup_str_default(list_file, NULL,
                                            "modpacks.list%d.subtype",
                                            modpack_count);
    mpURL = secfile_lookup_str_default(list_file, NULL,
                                       "modpacks.list%d.URL", modpack_count);
    mp_notes = secfile_lookup_str_default(list_file, NULL,
                                          "modpacks.list%d.notes", modpack_count);

    if (mp_name != NULL && mpURL != NULL) {
      enum modpack_type type = modpack_type_by_name(mp_type_str, fc_strcasecmp);
      if (!modpack_type_is_valid(type)) {
        log_error("Illegal modpack type \"%s\"", mp_type_str ? mp_type_str : "NULL");
      }
      if (mpver == NULL) {
        mpver = "-";
      }
      if (mp_subtype == NULL) {
        mp_subtype = "-";
      }
      cb(mp_name, mpURL, mpver, mplic, type, mp_subtype, mp_notes);
    }
    modpack_count++;
  } while (mp_name != NULL);

  return NULL;
}
ENDREP
DELTA 24423 2813 381
SVN  �8�8
 ‡, † ˆ‡2Apr.13ENDREP
id: 4pl.5js.r24756/10498
type: file
pred: 4pl.5js.r24423/3223
count: 32
text: 24756 0 10415 12969 2da941c61b909e0eafa8faac34c68c89
cpath: /trunk/tools/download.c
copyroot: 21464 /trunk/tools

id: 4pm.5js.r24756/10690
type: file
pred: 4pm.5js.r24423/3413
count: 21
text: 24756 10443 27 1976 f45d4d7371ad23b1c1e1be1fe6d5f4ca
cpath: /trunk/tools/download.h
copyroot: 21464 /trunk/tools

PLAIN
K 11
Makefile.am
V 24
file 4pk.5js.r24745/1990
K 11
civmanual.c
V 24
file 2m5.5jt.r24638/6936
K 10
download.c
V 25
file 4pl.5js.r24756/10498
K 10
download.h
V 25
file 4pm.5js.r24756/10690
K 9
modinst.c
V 24
file bj7.5ck.r21139/5112
K 9
modinst.h
V 24
file 76i.5js.r24628/1449
K 7
mpcli.c
V 24
file y74.5js.r24225/9612
K 11
mpcmdline.c
V 24
file 73v.5js.r24286/1008
K 11
mpcmdline.h
V 25
file 73w.5ck.r20760/16287
K 6
mpdb.c
V 23
file bjc.5ck.r21142/258
K 6
mpdb.h
V 24
file bje.5ck.r20961/5129
K 12
mpgui_gtk2.c
V 24
file 4pn.5lm.r24225/9966
K 12
mpgui_gtk3.c
V 25
file 4pn.5ln.r24225/10174
K 12
mpgui_qt.cpp
V 25
file a65.5js.r24225/10571
K 10
mpgui_qt.h
V 25
file a67.5js.r24225/10956
K 19
mpgui_qt_worker.cpp
V 24
file vuz.5js.r23875/3825
K 17
mpgui_qt_worker.h
V 24
file vv1.5js.r23868/2651
K 7
ruledit
V 22
dir ssm.5js.r24748/781
END
ENDREP
id: 4pj.5js.r24756/11734
type: dir
pred: 4pj.5js.r24748/1871
count: 153
text: 24756 10882 839 839 a357d99766eb074e46fd18f0597ec5ec
props: 24238 2030 216 0 ecd4e82177b0a82a2138833b7e9a5bd7
cpath: /trunk/tools
copyroot: 21464 /trunk/tools

PLAIN
K 9
ABOUT-NLS
V 24
file fu.5ck.r23462/85000
K 7
AUTHORS
V 24
file 5u.5ck.r22143/14016
K 7
COPYING
V 19
file 1h.0.r9643/400
K 9
ChangeLog
V 26
file 6l.5ck.r22811/6091752
K 7
INSTALL
V 22
file 6.5ck.r24055/8187
K 11
Makefile.am
V 23
file 59.5ck.r24665/2620
K 4
NEWS
V 24
file 6m.5ck.r23374/75525
K 6
README
V 20
file 7.0.r4421/96382
K 2
ai
V 22
dir 8.5ck.r24752/10399
K 10
autogen.sh
V 23
file 12o.5ck.r24091/228
K 9
bootstrap
V 23
dir 2p5.5ck.r24665/4665
K 6
client
V 22
dir d.5ck.r24745/13077
K 6
common
V 21
dir p.5ck.r24754/5858
K 12
configure.ac
V 24
file 149.5ck.r24665/2382
K 4
data
V 22
dir w.5ck.r24755/22485
K 12
dependencies
V 23
dir 2yu.5ck.r23968/4002
K 11
diff_ignore
V 23
file qq.5ck.r24665/2850
K 3
doc
V 22
dir k7.5ck.r24714/9345
K 10
fc_version
V 25
file 2lo.5en.r24744/12993
K 2
m4
V 23
dir 12p.5ck.r24684/2342
K 7
scripts
V 22
dir 2yo.5ck.r24495/862
K 6
server
V 22
dir z.5ck.r24752/14861
K 5
tests
V 23
dir 2g9.5ck.r23807/1326
K 5
tools
V 24
dir 4pj.5js.r24756/11734
K 12
translations
V 26
dir t0a.5ck.r24751/2203522
K 7
utility
V 23
dir 1c.5ck.r24682/13588
K 3
vms
V 25
dir u9.5ck.r21528/1396085
K 5
win32
V 23
dir 2eu.5ck.r24543/3121
END
ENDREP
id: 3.5ck.r24756/13144
type: dir
pred: 3.5ck.r24755/23888
count: 17308
text: 24756 11972 1159 1159 7ef265a58e952827b78042efd45e6e18
props: 23244 4830 282 0 e4bb46e81629a60eef613b169b23a9ea
cpath: /trunk
copyroot: 15280 /trunk

PLAIN
K 8
branches
V 22
dir 1.0.r24750/1668768
K 4
tags
V 19
dir 2.0.r24394/6245
K 5
trunk
V 22
dir 3.5ck.r24756/13144
K 7
website
V 21
dir 3ge.0.r22980/2263
END
ENDREP
id: 0.0.r24756/13540
type: dir
pred: 0.0.r24755/24283
count: 24756
text: 24756 13371 156 156 7c8d7a3a992495ffd30ed4a09b760b49
cpath: /
copyroot: 0 /

4pl.5js.t24755-1 modify true false /trunk/tools/download.c

4pm.5js.t24755-1 modify true false /trunk/tools/download.h


13540 13690
