Revize 98da6ab0
Přidáno uživatelem Michal Horký před asi 4 roky(ů)
project/Deserializer/src/io/FileWorker.java | ||
---|---|---|
6 | 6 |
import java.io.File; |
7 | 7 |
import java.io.FileInputStream; |
8 | 8 |
import java.io.FileNotFoundException; |
9 |
import java.io.FileOutputStream; |
|
9 | 10 |
import java.io.FileWriter; |
10 | 11 |
import java.io.IOException; |
11 | 12 |
import java.io.PrintStream; |
13 |
import java.net.URISyntaxException; |
|
14 |
import java.net.URL; |
|
12 | 15 |
import java.util.ArrayList; |
16 |
import java.util.Enumeration; |
|
13 | 17 |
import java.util.List; |
14 | 18 |
import java.util.NoSuchElementException; |
19 |
import java.util.Properties; |
|
20 |
import java.util.jar.JarEntry; |
|
21 |
import java.util.jar.JarFile; |
|
15 | 22 |
|
16 |
import javafx.collections.FXCollections; |
|
17 | 23 |
import javafx.collections.ObservableList; |
18 | 24 |
|
19 | 25 |
public class FileWorker { |
20 | 26 |
|
21 |
public static ObservableList<String> getAceModes() { |
|
22 |
File dir = new File(FileWorker.class.getResource("/ace/").toExternalForm().substring(6)); // TODO v JAR |
|
23 |
String names[] = dir.list(); |
|
24 |
ObservableList<String> modes = FXCollections.observableArrayList(); |
|
25 |
for (int i = 0; i < names.length; i++) { |
|
26 |
if (names[i].startsWith("mode-")) { |
|
27 |
modes.add(names[i].substring(5, names[i].lastIndexOf('.'))); |
|
28 |
} |
|
27 |
private static final String CONFIG = "app.config"; |
|
28 |
public static final String ACE_MODE = "ace_mode"; |
|
29 |
public static final String ACE_THEME = "ace_theme"; |
|
30 |
public static final String DB_TYPE = "db_type"; |
|
31 |
public static final String DB_URL = "db_url"; |
|
32 |
public static final String DB_USER = "db_user"; |
|
33 |
|
|
34 |
public static String getResource(String path) { |
|
35 |
return FileWorker.class.getResource(path).toString(); |
|
36 |
} |
|
37 |
|
|
38 |
public static Properties getConfig() { |
|
39 |
Properties properties = new Properties(); |
|
40 |
|
|
41 |
try { |
|
42 |
File config = new File(CONFIG); |
|
43 |
config.createNewFile(); |
|
44 |
properties.load(new FileInputStream(config)); |
|
45 |
} catch (IOException e) { } |
|
46 |
|
|
47 |
return properties; |
|
48 |
} |
|
49 |
|
|
50 |
public static void saveConfig(Properties properties) { |
|
51 |
try { |
|
52 |
properties.store(new FileOutputStream(CONFIG), null); |
|
53 |
} catch (IOException e) { |
|
54 |
e.printStackTrace(); |
|
29 | 55 |
} |
30 |
return modes; |
|
31 | 56 |
} |
32 | 57 |
|
33 |
public static ObservableList<String> getAceThemes() { |
|
34 |
File dir = new File(FileWorker.class.getResource("/ace/").toExternalForm().substring(6)); // TODO v JAR |
|
35 |
String names[] = dir.list(); |
|
36 |
ObservableList<String> themes = FXCollections.observableArrayList(); |
|
37 |
for (int i = 0; i < names.length; i++) { |
|
38 |
if (names[i].startsWith("theme-")) { |
|
39 |
themes.add(names[i].substring(6, names[i].lastIndexOf('.'))); |
|
58 |
public static void getAceModesAndThemes(ObservableList<String> modes, ObservableList<String> themes) { |
|
59 |
final String aceFolder = "ace"; |
|
60 |
List<String> names = new ArrayList<String>(); |
|
61 |
|
|
62 |
|
|
63 |
String path = FileWorker.class.getResource(FileWorker.class.getSimpleName() + ".class").getFile(); |
|
64 |
if (!path.startsWith("/")) { |
|
65 |
path = ClassLoader.getSystemClassLoader().getResource(path).getFile(); |
|
66 |
File jarFile = new File(path.substring(6, path.lastIndexOf('!'))); |
|
67 |
|
|
68 |
try { |
|
69 |
JarFile jar = new JarFile(jarFile); |
|
70 |
Enumeration<JarEntry> entries = jar.entries(); |
|
71 |
while (entries.hasMoreElements()) { |
|
72 |
String name = entries.nextElement().getName(); |
|
73 |
if (name.startsWith(aceFolder + "/")) { |
|
74 |
name = name.substring(name.lastIndexOf("/") + 1); |
|
75 |
if (name.length() > 0) { |
|
76 |
names.add(name); |
|
77 |
} |
|
78 |
} |
|
79 |
} |
|
80 |
jar.close(); |
|
81 |
} catch (IOException e) { |
|
82 |
e.printStackTrace(); |
|
83 |
} |
|
84 |
} else { |
|
85 |
URL url = FileWorker.class.getResource("/" + aceFolder); |
|
86 |
if (url != null) { |
|
87 |
try { |
|
88 |
File dir = new File(url.toURI()); |
|
89 |
for (File file : dir.listFiles()) { |
|
90 |
names.add(file.getName()); |
|
91 |
} |
|
92 |
} catch (URISyntaxException e) { |
|
93 |
e.printStackTrace(); |
|
94 |
} |
|
95 |
} |
|
96 |
} |
|
97 |
|
|
98 |
|
|
99 |
for (int i = 0; i < names.size(); i++) { |
|
100 |
if (names.get(i).startsWith("mode-")) { |
|
101 |
modes.add(names.get(i).substring(5, names.get(i).lastIndexOf('.'))); |
|
102 |
} else if (names.get(i).startsWith("theme-")) { |
|
103 |
themes.add(names.get(i).substring(6, names.get(i).lastIndexOf('.'))); |
|
40 | 104 |
} |
41 | 105 |
} |
42 |
return themes; |
|
43 | 106 |
} |
44 | 107 |
|
45 | 108 |
public static PrintStream createRedirectStream() throws FileNotFoundException { |
Také k dispozici: Unified diff
re #7895
Ukládání určitých dat do configu. Konkrétně nastavení editoru a základní konfigurace DB spojení. Vyřešeny problémy při exportu do .jar.