Example #1
0
int main(int argc, char* argv[])
{
  if (argc > 1 && (IsArg(argv[1], "h") ||
                   IsArg(argv[1], "help") ||
                   IsArg(argv[1], "?")))
  {
    Usage(argv[0]);
    return 0;
  }

  if (argc == 2 && (IsArg(argv[1], "v") || IsArg(argv[1], "version")))
  {
    nsCAutoString milestone;
    nsCAutoString version;
    GetGREVersion(argv[0], &milestone, &version);
    Output(PR_FALSE, "Mozilla XULRunner %s - %s\n",
           milestone.get(), version.get());
    return 0;
  }

  if (argc > 1) {
    nsCAutoString milestone;
    nsresult rv = GetGREVersion(argv[0], &milestone, nsnull);
    if (NS_FAILED(rv))
      return 2;

    if (IsArg(argv[1], "gre-version")) {
      if (argc != 2) {
        Usage(argv[0]);
        return 1;
      }

      printf("%s\n", milestone.get());
      return 0;
    }

    if (IsArg(argv[1], "install-app")) {
      if (argc < 3 || argc > 5) {
        Usage(argv[0]);
        return 1;
      }

      char *appLocation = argv[2];

      char *installTo = nsnull;
      if (argc > 3) {
        installTo = argv[3];
        if (!*installTo) // left blank?
          installTo = nsnull;
      }

      char *leafName = nsnull;
      if (argc > 4) {
        leafName = argv[4];
        if (!*leafName)
          leafName = nsnull;
      }

      nsCOMPtr<nsIFile> regDir;
      rv = GetXULRunnerDir(argv[0], getter_AddRefs(regDir));
      if (NS_FAILED(rv))
        return 2;

      return InstallXULApp(regDir, appLocation, installTo, leafName);
    }
  }

  const char *appDataFile = PR_GetEnv("XUL_APP_FILE");

  if (!(appDataFile && *appDataFile)) {
    if (argc < 2) {
      Usage(argv[0]);
      return 1;
    }

    if (IsArg(argv[1], "app")) {
      if (argc == 2) {
        Usage(argv[0]);
        return 1;
      }
      argv[1] = argv[0];
      ++argv;
      --argc;
    }

    appDataFile = argv[1];
    argv[1] = argv[0];
    ++argv;
    --argc;

    static char kAppEnv[MAXPATHLEN];
    PR_snprintf(kAppEnv, MAXPATHLEN, "XUL_APP_FILE=%s", appDataFile);
    PR_SetEnv(kAppEnv);
  }

  nsCOMPtr<nsILocalFile> appDataLF;
  nsresult rv = XRE_GetFileFromPath(appDataFile, getter_AddRefs(appDataLF));
  if (NS_FAILED(rv)) {
    Output(PR_TRUE, "Error: unrecognized application.ini path.\n");
    return 2;
  }

  AutoAppData appData(appDataLF);
  if (!appData) {
    Output(PR_TRUE, "Error: couldn't parse application.ini.\n");
    return 2;
  }

  return XRE_main(argc, argv, appData);
}
Example #2
0
int main(int argc, char* argv[])
{
  if (argc > 1 && (IsArg(argv[1], "h") ||
                   IsArg(argv[1], "help") ||
                   IsArg(argv[1], "?")))
  {
    Usage();
    return 0;
  }

  if (argc == 2 && (IsArg(argv[1], "v") || IsArg(argv[1], "version")))
  {
    Output(PR_FALSE, "Mozilla XULRunner %s\n", GRE_BUILD_ID);
    return 0;
  }

  if (argc > 1) {
    PRBool registerGlobal = IsArg(argv[1], "register-global");
    PRBool registerUser   = IsArg(argv[1], "register-user");
    if (registerGlobal || registerUser) {
      if (argc != 2) {
        Usage();
        return 1;
      }

      nsCOMPtr<nsIFile> regDir;
      nsresult rv = GetXULRunnerDir(argv[0], getter_AddRefs(regDir));
      if (NS_FAILED(rv))
        return 2;

      return RegisterXULRunner(registerGlobal, regDir,
                               kGREProperties,
                               NS_ARRAY_LENGTH(kGREProperties)) ? 0 : 2;
    }

    registerGlobal = IsArg(argv[1], "unregister-global");
    registerUser   = IsArg(argv[1], "unregister-user");
    if (registerGlobal || registerUser) {
      if (argc != 2) {
        Usage();
        return 1;
      }

      nsCOMPtr<nsIFile> regDir;
      nsresult rv = GetXULRunnerDir(argv[0], getter_AddRefs(regDir));
      if (NS_FAILED(rv))
        return 2;
      UnregisterXULRunner(registerGlobal, regDir);
      return 0;
    }

    if (IsArg(argv[1], "find-gre")) {
      if (argc != 3) {
        Usage();
        return 1;
      }

      char path[MAXPATHLEN];
      static const GREVersionRange vr = {
        argv[2], PR_TRUE,
        argv[2], PR_TRUE
      };
      static const GREProperty kProperties[] = {
        { "xulrunner", "true" }
      };

      nsresult rv = GRE_GetGREPathWithProperties(&vr, 1, kProperties,
                                                 NS_ARRAY_LENGTH(kProperties),
                                                 path, sizeof(path));
      if (NS_FAILED(rv))
        return 1;

      printf("%s\n", path);
      return 0;
    }

    if (IsArg(argv[1], "gre-version")) {
      if (argc != 2) {
        Usage();
        return 1;
      }

      printf("%s\n", GRE_BUILD_ID);
      return 0;
    }

    if (IsArg(argv[1], "install-app")) {
      if (argc < 3 || argc > 5) {
        Usage();
        return 1;
      }

      char *appLocation = argv[2];

      char *installTo = nsnull;
      if (argc > 3) {
        installTo = argv[3];
        if (!*installTo) // left blank?
          installTo = nsnull;
      }

      char *leafName = nsnull;
      if (argc > 4) {
        leafName = argv[4];
        if (!*leafName)
          leafName = nsnull;
      }

      nsCOMPtr<nsIFile> regDir;
      nsresult rv = GetXULRunnerDir(argv[0], getter_AddRefs(regDir));
      if (NS_FAILED(rv))
        return 2;

      return InstallXULApp(regDir, appLocation, installTo, leafName);
    }
  }

  geckoVersion = ParseVersion(GRE_BUILD_ID);

  const char *appDataFile = PR_GetEnv("XUL_APP_FILE");

  if (!(appDataFile && *appDataFile)) {
    if (argc < 2) {
      Usage();
      return 1;
    }

    if (IsArg(argv[1], "app")) {
      if (argc == 2) {
        Usage();
        return 1;
      }
      argv[1] = argv[0];
      ++argv;
      --argc;
    }

    appDataFile = argv[1];
    argv[1] = argv[0];
    ++argv;
    --argc;

    static char kAppEnv[MAXPATHLEN];
    PR_snprintf(kAppEnv, MAXPATHLEN, "XUL_APP_FILE=%s", appDataFile);
    PR_SetEnv(kAppEnv);
  }

  nsCAutoString vendor, name, version, buildID, appID, copyright;

  nsXREAppData appData = { sizeof(nsXREAppData), 0 };

  int rv = LoadAppData(appDataFile, &appData,
                       vendor, name, version, buildID, appID, copyright);
  if (!rv)
    rv = XRE_main(argc, argv, &appData);

  NS_IF_RELEASE(appData.directory);

  return rv;
}