DELTA 17690 195 3154
SVN  ²oÍ9R»E …W €J y…h€ G €I Iœ@€ G © Iœ@€„ ƒ'ž€+ `¨s€‚p `¨s£ [¨s€…# ‚2¬j€†Y G  Iœ@€–pfc_config.h>
#endif

#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endifcapability.h"
#include "fcintl.h"
#include "log.h"
#include "netintf.h"
#include "netfile.h"
#include "registry.h"

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

****
  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)
{
  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 *baseURL;
  enum modpack_type type;
  const char *typestr;
  const char *mpname;
  const char *mpver;
  char fileURL[2048];
  const char *src_name;
  bool partial_failure = FALSE_("Installing modpack %s from %s"), URL + start_idx, URL);

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

  if (mcb != NULL) {
    mcb(_("Downloading modpack control file."));
  }

  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);
  }

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

  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);
      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 25678 831 149
SVN  „8†%m „8 €m

Typical Modpack subtypes

/* TRANS: Modpack subtype, "isometric" */
_("iso")
/* TRANS: Modpack subtype */
_("hex")
/* TRANS: Modpack subtype, isometric hex */
_("hex & iso")
/* TRANS: Modpack subtype, overhead tileset */
_("overhead")
ENDREP
id: 4pl.5lo.r28957/8026
type: file
pred: 4pl.5lo.r26906/27283
count: 32
text: 28957 0 7715 9913 e9d7aba8b5a348e1c25f6ffc557d901a
props: 26906 27236 34 0 25e6c2f7558b7484000d4d090dea5b92
cpath: /branches/S2_5/tools/download.c
copyroot: 21464 /trunk/tools

PLAIN
K 11
Makefile.am
V 24
file 4pk.5lo.r25962/5912
K 11
civmanual.c
V 24
file 2m5.5lt.r28749/3060
K 10
download.c
V 24
file 4pl.5lo.r28957/8026
K 10
download.h
V 25
file 4pm.5lo.r26906/28544
K 9
modinst.c
V 25
file bj7.5lo.r28565/17454
K 9
modinst.h
V 24
file 76i.5lo.r27301/5014
K 7
mpcli.c
V 24
file y7i.5lo.r27419/2433
K 11
mpcmdline.c
V 25
file 73v.5lo.r26906/27586
K 11
mpcmdline.h
V 25
file 73w.5lo.r26906/29155
K 6
mpdb.c
V 25
file bjc.5lo.r26906/30067
K 6
mpdb.h
V 25
file bje.5lo.r26906/30976
K 12
mpgui_gtk2.c
V 24
file 4pn.5lp.r27419/2682
K 12
mpgui_gtk3.c
V 24
file 4pn.5lq.r27419/2962
K 12
mpgui_qt.cpp
V 24
file a65.5lo.r28932/1573
K 10
mpgui_qt.h
V 24
file a67.5lo.r28932/1828
K 19
mpgui_qt_worker.cpp
V 23
file vv9.5lo.r27627/465
K 17
mpgui_qt_worker.h
V 25
file vvb.5lo.r26906/30362
END
ENDREP
id: 4pj.5lo.r28957/9094
type: dir
pred: 4pj.5lo.r28932/2897
count: 143
text: 28957 8281 800 800 16bec4fb534cb3e36514371a82b007f9
props: 28038 0 325 0 931541cd07e52416301ed56de9c70dfc
cpath: /branches/S2_5/tools
copyroot: 21464 /trunk/tools

id: his.5lx.r28957/9335
type: file
pred: his.5lx.r25678/5497
count: 3
text: 28957 7743 256 805 b18429d279555c4a05e41e4febf392c1
cpath: /branches/S2_5/translations/Strings.txt
copyroot: 23463 /branches/S2_5/translations/Strings.txt

PLAIN
K 11
Makefile.am
V 24
file t15.5kv.r25089/2091
K 11
Strings.txt
V 24
file his.5lx.r28957/9335
K 7
freeciv
V 24
dir fs.5ly.r28900/352540
K 7
nations
V 25
dir u15.5kv.r28707/820930
K 8
stats.sh
V 24
file 14eg.5kv.r25122/114
END
ENDREP
id: t0n.5kv.r28957/9806
type: dir
pred: t0n.5kv.r28900/353067
count: 111
text: 28957 9567 226 226 05bc36644bdfe97c64deb795bf7b6e22
props: 23742 534 47 0 bf36bdb5202732a1b9a911cc1234183c
cpath: /branches/S2_5/translations
copyroot: 22812 /branches/S2_5

PLAIN
K 9
ABOUT-NLS
V 24
file fu.5kv.r23463/86338
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.5kv.r28526/1139931
K 7
INSTALL
V 21
file 6.5kv.r28850/212
K 11
Makefile.am
V 22
file 59.5kv.r27141/100
K 4
NEWS
V 22
file 6m.5kv.r28524/894
K 8
NEWS-2.5
V 25
file 1h59.5kv.r28524/1138
K 6
README
V 20
file 7.0.r4421/96382
K 2
ai
V 21
dir 8.5kv.r28953/3909
K 10
autogen.sh
V 23
file 12o.5kv.r24092/228
K 9
bootstrap
V 23
dir 2p5.5kv.r28599/3351
K 6
client
V 21
dir d.5kv.r28940/9851
K 6
common
V 21
dir p.5kv.r28925/5687
K 12
configure.ac
V 24
file 149.5kv.r28884/3386
K 4
data
V 22
dir w.5kv.r28937/51887
K 6
debian
V 22
dir 5w.5kv.r23304/4091
K 12
dependencies
V 23
dir 2yu.5kv.r28816/1070
K 11
diff_ignore
V 24
file qq.5ck.r21039/26581
K 3
doc
V 23
dir k7.5kv.r28937/47704
K 10
fc_version
V 22
file 2lo.5kw.r28525/44
K 2
m4
V 23
dir 12p.5kv.r28884/3146
K 7
scripts
V 23
dir 2yo.5kv.r28718/5390
K 6
server
V 21
dir z.5kv.r28919/8156
K 5
tests
V 22
dir 2g9.5kv.r27024/930
K 5
tools
V 23
dir 4pj.5lo.r28957/9094
K 12
translations
V 23
dir t0n.5kv.r28957/9806
K 7
utility
V 23
dir 1c.5kv.r28759/10840
K 3
vms
V 25
dir u9.5ck.r21528/1396085
K 5
win32
V 23
dir 2eu.5kv.r28344/1663
END
ENDREP
id: 3.5kv.r28957/11302
type: dir
pred: 3.5kv.r28953/5394
count: 17925
text: 28957 10059 1230 1230 f872803bca34ba78f50bac904dc22c79
props: 20140 3888 282 0 e4bb46e81629a60eef613b169b23a9ea
cpath: /branches/S2_5
copyroot: 22812 /branches/S2_5

PLAIN
K 5
S1_14
V 21
dir 3.21.r18109/18803
K 4
S2_0
V 21
dir 3.10x.r21862/4178
K 4
S2_1
V 22
dir 3.59e.r20026/11014
K 4
S2_2
V 21
dir 3.5cy.r21861/5036
K 4
S2_3
V 21
dir 3.5f2.r24391/5183
K 4
S2_4
V 21
dir 3.5ii.r28954/4360
K 4
S2_5
V 22
dir 3.5kv.r28957/11302
K 4
S2_6
V 21
dir 3.5qi.r28956/3610
K 11
freeciv-web
V 22
dir 3.5bl.r13594/14918
END
ENDREP
id: 1.0.r28957/11897
type: dir
pred: 1.0.r28956/4204
count: 9309
text: 28957 11544 340 340 76e9ad842719643d1e28cf98b34a289f
cpath: /branches
copyroot: 0 /

PLAIN
K 8
branches
V 20
dir 1.0.r28957/11897
K 4
tags
V 19
dir 2.0.r28528/6475
K 5
trunk
V 21
dir 3.5ck.r28955/3633
K 7
website
V 21
dir 3ge.0.r22980/2263
END
ENDREP
id: 0.0.r28957/12219
type: dir
pred: 0.0.r28956/4523
count: 28957
text: 28957 12053 153 153 2a4417707930392ee6f32c8a7393ad7b
cpath: /
copyroot: 0 /

4pl.5lo.t28956-1 modify true false /branches/S2_5/tools/download.c

his.5lx.t28956-1 modify true false /branches/S2_5/translations/Strings.txt


12219 12368
