mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-03 00:37:55 +00:00
Fixed imports
This commit is contained in:
@@ -1,161 +1,154 @@
|
||||
package org.parabot.core;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
|
||||
import org.parabot.environment.OperatingSystem;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds parabot's used directories
|
||||
*
|
||||
*
|
||||
* @author Everel
|
||||
* @author Matt
|
||||
*
|
||||
*/
|
||||
public class Directories {
|
||||
|
||||
private static Map<String, File> cached = new HashMap<String, File>();
|
||||
private static Map<String, File> cached = new HashMap<String, File>();
|
||||
|
||||
static {
|
||||
static {
|
||||
|
||||
switch (OperatingSystem.getOS()) {
|
||||
case WINDOWS:
|
||||
cached.put("Root", new JFileChooser().getFileSystemView().getDefaultDirectory());
|
||||
break;
|
||||
default:
|
||||
cached.put("Root", new File(System.getProperty("user.home")));
|
||||
}
|
||||
switch (OperatingSystem.getOS()) {
|
||||
case WINDOWS:
|
||||
cached.put("Root", new JFileChooser().getFileSystemView().getDefaultDirectory());
|
||||
break;
|
||||
default:
|
||||
cached.put("Root", new File(System.getProperty("user.home")));
|
||||
}
|
||||
|
||||
Core.verbose("Caching directories...");
|
||||
cached.put("Root", getDefaultDirectory());
|
||||
cached.put("Workspace", new File(cached.get("Root"), "/Parabot/"));
|
||||
cached.put("Sources", new File(cached.get("Root"), "/Parabot/scripts/sources/"));
|
||||
cached.put("Compiled", new File(cached.get("Root"), "/Parabot/scripts/compiled/"));
|
||||
cached.put("Resources", new File(cached.get("Root"), "/Parabot/scripts/resources/"));
|
||||
cached.put("Settings", new File(cached.get("Root"), "/Parabot/settings/"));
|
||||
cached.put("Servers", new File(cached.get("Root"), "/Parabot/servers/"));
|
||||
cached.put("Cache", new File(cached.get("Root"), "/Parabot/cache/"));
|
||||
Core.verbose("Directories cached.");
|
||||
}
|
||||
Core.verbose("Caching directories...");
|
||||
cached.put("Root", getDefaultDirectory());
|
||||
cached.put("Workspace", new File(cached.get("Root"), "/Parabot/"));
|
||||
cached.put("Sources", new File(cached.get("Root"), "/Parabot/scripts/sources/"));
|
||||
cached.put("Compiled", new File(cached.get("Root"), "/Parabot/scripts/compiled/"));
|
||||
cached.put("Resources", new File(cached.get("Root"), "/Parabot/scripts/resources/"));
|
||||
cached.put("Settings", new File(cached.get("Root"), "/Parabot/settings/"));
|
||||
cached.put("Servers", new File(cached.get("Root"), "/Parabot/servers/"));
|
||||
cached.put("Cache", new File(cached.get("Root"), "/Parabot/cache/"));
|
||||
Core.verbose("Directories cached.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the root directory outside of the main Parabot folder.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static File getDefaultDirectory() {
|
||||
return cached.get("Root");
|
||||
}
|
||||
/**
|
||||
* Returns the root directory outside of the main Parabot folder.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static File getDefaultDirectory() {
|
||||
return cached.get("Root");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Parabot folder.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static File getWorkspace() {
|
||||
return cached.get("Workspace");
|
||||
}
|
||||
/**
|
||||
* Returns the Parabot folder.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static File getWorkspace() {
|
||||
return cached.get("Workspace");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the script sources folder.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static File getScriptSourcesPath() {
|
||||
return cached.get("Sources");
|
||||
}
|
||||
/**
|
||||
* Returns the script sources folder.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static File getScriptSourcesPath() {
|
||||
return cached.get("Sources");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the compiled scripts folder.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static File getScriptCompiledPath() {
|
||||
return cached.get("Compiled");
|
||||
}
|
||||
/**
|
||||
* Returns the compiled scripts folder.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static File getScriptCompiledPath() {
|
||||
return cached.get("Compiled");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the scripts resources folder.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static File getResourcesPath() {
|
||||
return cached.get("Resources");
|
||||
}
|
||||
/**
|
||||
* Returns the scripts resources folder.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static File getResourcesPath() {
|
||||
return cached.get("Resources");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Parabot settings folder.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static File getSettingsPath() {
|
||||
return cached.get("Settings");
|
||||
}
|
||||
/**
|
||||
* Returns the Parabot settings folder.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static File getSettingsPath() {
|
||||
return cached.get("Settings");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Parabot servers folder.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static File getServerPath() {
|
||||
return cached.get("Servers");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Parabot cache folder.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static File getCachePath() {
|
||||
return cached.get("Cache");
|
||||
}
|
||||
/**
|
||||
* Returns the Parabot servers folder.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static File getServerPath() {
|
||||
return cached.get("Servers");
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates all directories and makes them if necessary
|
||||
*/
|
||||
public static void validate() {
|
||||
final File defaultPath = getDefaultDirectory();
|
||||
if (defaultPath == null || !defaultPath.exists()) {
|
||||
throw new RuntimeException("Default path not found");
|
||||
}
|
||||
final Queue<File> files = new LinkedList<File>();
|
||||
files.add(getWorkspace());
|
||||
files.add(getServerPath());
|
||||
files.add(getSettingsPath());
|
||||
files.add(getScriptSourcesPath());
|
||||
files.add(getScriptCompiledPath());
|
||||
files.add(getResourcesPath());
|
||||
files.add(getCachePath());
|
||||
while (files.size() > 0) {
|
||||
final File file = files.poll();
|
||||
if (!file.exists()) {
|
||||
Core.verbose("Generating directory: " + file.getAbsolutePath());
|
||||
file.mkdirs();
|
||||
if(!file.exists()) {
|
||||
System.err.println("Failed to make directory: " + file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns the Parabot cache folder.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static File getCachePath() {
|
||||
return cached.get("Cache");
|
||||
}
|
||||
|
||||
private static File temp = null;
|
||||
/**
|
||||
* Validates all directories and makes them if necessary
|
||||
*/
|
||||
public static void validate() {
|
||||
final File defaultPath = getDefaultDirectory();
|
||||
if (defaultPath == null || !defaultPath.exists()) {
|
||||
throw new RuntimeException("Default path not found");
|
||||
}
|
||||
final Queue<File> files = new LinkedList<File>();
|
||||
files.add(getWorkspace());
|
||||
files.add(getServerPath());
|
||||
files.add(getSettingsPath());
|
||||
files.add(getScriptSourcesPath());
|
||||
files.add(getScriptCompiledPath());
|
||||
files.add(getResourcesPath());
|
||||
files.add(getCachePath());
|
||||
while (files.size() > 0) {
|
||||
final File file = files.poll();
|
||||
if (!file.exists()) {
|
||||
Core.verbose("Generating directory: " + file.getAbsolutePath());
|
||||
file.mkdirs();
|
||||
if (!file.exists()) {
|
||||
System.err.println("Failed to make directory: " + file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static File getTempDirectory() {
|
||||
if (temp != null) {
|
||||
return temp;
|
||||
}
|
||||
int randomNum = new Random().nextInt(999999999);
|
||||
temp = new File(getResourcesPath(), randomNum + "/");
|
||||
temp.mkdirs();
|
||||
temp.deleteOnExit();
|
||||
return temp;
|
||||
}
|
||||
private static File temp = null;
|
||||
|
||||
public static File getTempDirectory() {
|
||||
if (temp != null) {
|
||||
return temp;
|
||||
}
|
||||
int randomNum = new Random().nextInt(999999999);
|
||||
temp = new File(getResourcesPath(), randomNum + "/");
|
||||
temp.mkdirs();
|
||||
temp.deleteOnExit();
|
||||
return temp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user