aboutsummaryrefslogtreecommitdiffstats
path: root/src/cmd-version.c
blob: fbf87b1ac930ae145fabde7ea95710b4fe423912 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "command.h"
#include "commands.h"
#include "digest/digest.h"
#include "version.h"
#include "l2su.h"
#include "macros.h"
#include "args.h"
#include "assets.h"
#include "launch.h"
#include "instance.h"

#include <jansson.h>
#include <stdio.h>
#include <unistd.h>

unsigned cmd_version_list_remote(struct l2_context_node *ctx, char **args)
{
  unsigned res;
  L2_UNUSED(ctx);

  if (*args) {
    CMD_FATAL(CMD_MSG_UNKNOWN_ARGUMENT, *args);
  }

  res = l2_version_load_remote();
  if (res != VERSION_SUCCESS) {
    CMD_FATAL("Failed to load versions: %s", l2_version_strerror(res));
  }

  for (struct l2_version_remote *rv = l2_state.ver_remote_head; rv; rv = rv->next) {
    printf("%s\n", rv->id);
  }

  return CMD_RESULT_SUCCESS;
}

unsigned cmd_version_list_local(struct l2_context_node *ctx, char **args)
{
  return CMD_RESULT_SUCCESS;
}

bool feat_match_cb(const char *name, json_t *js, void *unused) {
  L2_UNUSED(name);
  L2_UNUSED(js);
  L2_UNUSED(unused);
  return false;
}

unsigned cmd_version_install(struct l2_context_node *ctx, char **args)
{
  unsigned res = l2_version_load_remote();
  if (res != VERSION_SUCCESS) {
    CMD_FATAL("Failed to load versions: %s", l2_version_strerror(res));
  }

  if ((res = l2_instance_load_all()) != INSTANCE_SUCCESS) {
    CMD_FATAL("Failed to load instances: %s", l2_instance_errormsg[res]);
  }

  struct l2_launch launch = { 0 };
  if (l2_launch_init(&launch, *args, l2_state.instance_head) < 0) {
    CMD_FATAL0("Failed to launch the game");
  }

  if (l2_launch_init_substitutor(&launch) < 0) {
    CMD_FATAL0("Failed to initialize argument substitutor");
  }

  if (l2_launch_init_args(&launch) < 0) {
    CMD_FATAL0("Failed to set JVM and game arguments");
  }

  if (l2_launch_jni(&launch) < 0) {
    CMD_FATAL0("Failed to launch the game.");
  }

  l2_launch_free_contents(&launch);

  return CMD_RESULT_SUCCESS;
}