|
11 | 11 | public class FileManager { |
12 | 12 |
|
13 | 13 | public static File configFile = new File(Main.instance.getDataFolder(), "config.yml"); |
14 | | - public static File webFolder = new File(Main.instance.getDataFolder(), "web"); |
15 | | - public static File logsFolder = new File(Main.instance.getDataFolder(), "logs"); |
| 14 | + public static File webFolder = new File(Main.instance.getDataFolder(), "/web"); |
| 15 | + public static File logsFolder = new File(Main.instance.getDataFolder(), "/logs"); |
16 | 16 | public static File logsFile = new File(Main.instance.getDataFolder(), "/logs/access.log"); |
17 | 17 | public static YamlConfiguration config; |
18 | 18 | public static String ipaddr; |
@@ -75,7 +75,52 @@ public void startup() throws UnknownHostException { |
75 | 75 | } |
76 | 76 | if (!logsFolder.exists()) logsFolder.mkdir(); |
77 | 77 | if(!webFolder.exists()) webFolder.mkdir(); |
| 78 | + saveMyResource("index.html", false); |
78 | 79 | } |
| 80 | + |
| 81 | + public void saveMyResource(String resourceName, boolean replace) { |
| 82 | + // Get the plugin's data folder |
| 83 | + File dataFolder = Main.instance.getDataFolder(); |
| 84 | + |
| 85 | + // Create the destination file |
| 86 | + File destFile = new File(dataFolder, resourceName); |
| 87 | + |
| 88 | + // If the file already exists and 'replace' is false, return early |
| 89 | + if (destFile.exists() && !replace) { |
| 90 | + return; |
| 91 | + } |
| 92 | + |
| 93 | + // Open the resource file |
| 94 | + InputStream is = Main.instance.getResource(resourceName); |
| 95 | + |
| 96 | + // If the resource file is not found, throw an exception |
| 97 | + if (is == null) { |
| 98 | + throw new IllegalArgumentException("Resource not found: " + resourceName); |
| 99 | + } |
| 100 | + |
| 101 | + try { |
| 102 | + // Create the parent directories if they don't exist |
| 103 | + destFile.getParentFile().mkdirs(); |
| 104 | + |
| 105 | + // Open the destination file for writing |
| 106 | + OutputStream os = new FileOutputStream(destFile); |
| 107 | + |
| 108 | + // Copy the contents of the resource to the destination file |
| 109 | + byte[] buffer = new byte[1024]; |
| 110 | + int length; |
| 111 | + while ((length = is.read(buffer)) > 0) { |
| 112 | + os.write(buffer, 0, length); |
| 113 | + } |
| 114 | + |
| 115 | + // Close the input and output streams |
| 116 | + is.close(); |
| 117 | + os.close(); |
| 118 | + } catch (IOException e) { |
| 119 | + e.printStackTrace(); |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + |
79 | 124 | public String getStringFromConfig(String string) { |
80 | 125 | if (config == null) { |
81 | 126 | config = new YamlConfiguration().loadConfiguration(configFile); |
|
0 commit comments