Exemplo n.º 1
0
  private void initLoader() {
    if (loaderStartupDone) return;
    loaderStartupDone = true;

    // Set up base class overrides
    prepareClassOverrides();

    // Set up loader, initialises any reflection methods needed
    if (prepareLoader()) {
      logger.info("LiteLoader " + LOADER_VERSION + " starting up...");
      logger.info(
          String.format("Java reports OS=\"%s\"", System.getProperty("os.name").toLowerCase()));

      // Examines the class path and mods folder and locates loadable mods
      prepareMods();

      // Initialises enumerated mods
      initMods();

      // Initialises the required hooks for loaded mods
      initHooks();

      loaderStartupComplete = true;
    }
  }
Exemplo n.º 2
0
  /** Enumerate the java class path and "mods" folder to find mod classes, then load the classes */
  private void prepareMods() {
    // List of mod files in the "mods" folder
    LinkedList<File> modFiles = new LinkedList<File>();

    // Find and enumerate the "mods" folder
    File modFolder = getModsFolder();
    if (modFolder.exists() && modFolder.isDirectory()) {
      logger.info("Mods folder found, searching " + modFolder.getPath());
      findModFiles(modFolder, modFiles);
      logger.info("Found " + modFiles.size() + " mod file(s)");
    }

    // Find and enumerate classes on the class path
    HashMap<String, Class> modsToLoad = null;
    try {
      logger.info("Enumerating class path...");

      String classPath = System.getProperty("java.class.path");
      String classPathSeparator = System.getProperty("path.separator");
      String[] classPathEntries = classPath.split(classPathSeparator);

      logger.info(String.format("Class path separator=\"%s\"", classPathSeparator));
      logger.info(
          String.format(
              "Class path entries=(\n   classpathEntry=%s\n)",
              classPath.replace(classPathSeparator, "\n   classpathEntry=")));

      logger.info("Loading mods from class path...");

      modsToLoad = findModClasses(classPathEntries, modFiles);

      logger.info("Mod class discovery completed");
    } catch (Throwable th) {
      logger.log(Level.WARNING, "Mod class discovery failed", th);
      return;
    }

    loadMods(modsToLoad);
  }
Exemplo n.º 3
0
  public static File getAppDir(String s) {
    String s1 = System.getProperty("user.home", ".");
    File file;
    switch (EnumOSMappingHelper.enumOSMappingArray[getOs().ordinal()]) {
      case 1: // '\001'
      case 2: // '\002'
        file = new File(s1, (new StringBuilder()).append('.').append(s).append('/').toString());
        break;

      case 3: // '\003'
        String s2 = System.getenv("APPDATA");
        if (s2 != null) {
          file = new File(s2, (new StringBuilder()).append(".").append(s).append('/').toString());
        } else {
          file = new File(s1, (new StringBuilder()).append('.').append(s).append('/').toString());
        }
        break;

      case 4: // '\004'
        file =
            new File(
                s1,
                (new StringBuilder()).append("Library/Application Support/").append(s).toString());
        break;

      default:
        file = new File(s1, (new StringBuilder()).append(s).append('/').toString());
        break;
    }
    if (!file.exists() && !file.mkdirs()) {
      throw new RuntimeException(
          (new StringBuilder())
              .append("The working directory could not be created: ")
              .append(file)
              .toString());
    } else {
      return file;
    }
  }
Exemplo n.º 4
0
 private static EnumOS2 getOs() {
   String s = System.getProperty("os.name").toLowerCase();
   if (s.contains("win")) {
     return EnumOS2.windows;
   }
   if (s.contains("mac")) {
     return EnumOS2.macos;
   }
   if (s.contains("solaris")) {
     return EnumOS2.solaris;
   }
   if (s.contains("sunos")) {
     return EnumOS2.solaris;
   }
   if (s.contains("linux")) {
     return EnumOS2.linux;
   }
   if (s.contains("unix")) {
     return EnumOS2.linux;
   } else {
     return EnumOS2.unknown;
   }
 }