Skip to content

Commit 1494eca

Browse files
committed
Replaced Old Disk-Lib Library
1 parent 17d9736 commit 1494eca

21 files changed

Lines changed: 144 additions & 98 deletions

src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
import com.google.gson.Gson;
2222
import com.google.gson.GsonBuilder;
23+
import com.konloch.disklib.DiskReader;
2324
import com.konloch.taskmanager.TaskManager;
24-
import me.konloch.kontainer.io.DiskReader;
2525
import org.apache.commons.io.FileUtils;
2626
import org.objectweb.asm.tree.ClassNode;
2727
import the.bytecode.club.bytecodeviewer.api.BCV;
@@ -588,7 +588,7 @@ public static void startPlugin(File file)
588588

589589
try
590590
{
591-
PluginWriter writer = new PluginWriter(DiskReader.loadAsString(file.getAbsolutePath()), file.getName());
591+
PluginWriter writer = new PluginWriter(DiskReader.readString(file.getAbsolutePath()), file.getName());
592592
writer.setSourceFile(file);
593593
writer.setVisible(true);
594594
}

src/main/java/the/bytecode/club/bytecodeviewer/Settings.java

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919
package the.bytecode.club.bytecodeviewer;
2020

2121
import com.google.gson.reflect.TypeToken;
22-
import me.konloch.kontainer.io.DiskReader;
23-
import me.konloch.kontainer.io.DiskWriter;
22+
import com.konloch.disklib.DiskReader;
23+
import com.konloch.disklib.DiskWriter;
2424
import the.bytecode.club.bytecodeviewer.util.MiscUtils;
2525

2626
import javax.swing.*;
2727
import java.io.File;
28+
import java.io.IOException;
2829
import java.util.ArrayList;
30+
import java.util.Arrays;
2931
import java.util.List;
3032

3133
import static the.bytecode.club.bytecodeviewer.BytecodeViewer.gson;
@@ -52,14 +54,14 @@ public class Settings
5254
try
5355
{
5456
if (new File(FILES_NAME).exists())
55-
recentFiles = gson.fromJson(DiskReader.loadAsString(FILES_NAME), new TypeToken<ArrayList<String>>() {}.getType());
57+
recentFiles = gson.fromJson(DiskReader.readString(FILES_NAME), new TypeToken<ArrayList<String>>() {}.getType());
5658
else
57-
recentFiles = DiskReader.loadArrayList(getBCVDirectory() + FS + "recentfiles.bcv", false);
59+
recentFiles = Arrays.asList(DiskReader.readArray(getBCVDirectory() + FS + "recentfiles.bcv"));
5860

5961
if (new File(PLUGINS_NAME).exists())
60-
recentPlugins = gson.fromJson(DiskReader.loadAsString(PLUGINS_NAME), new TypeToken<ArrayList<String>>() {}.getType());
62+
recentPlugins = gson.fromJson(DiskReader.readString(PLUGINS_NAME), new TypeToken<ArrayList<String>>() {}.getType());
6163
else
62-
recentPlugins = DiskReader.loadArrayList(getBCVDirectory() + FS + "recentplugins.bcv", false);
64+
recentPlugins = Arrays.asList(DiskReader.readArray(getBCVDirectory() + FS + "recentplugins.bcv"));
6365

6466
MiscUtils.deduplicateAndTrim(recentFiles, maxRecentFiles);
6567
MiscUtils.deduplicateAndTrim(recentPlugins, maxRecentFiles);
@@ -80,19 +82,31 @@ public static synchronized void addRecentFile(File f)
8082
recentFiles.remove(f.getAbsolutePath()); // already added on the list
8183
recentFiles.add(0, f.getAbsolutePath());
8284
MiscUtils.deduplicateAndTrim(recentFiles, maxRecentFiles);
83-
DiskWriter.replaceFile(FILES_NAME, MiscUtils.listToString(recentFiles), false);
85+
saveRecentFiles();
8486
resetRecentFilesMenu();
8587
}
8688

8789
public static synchronized void removeRecentFile(File f)
8890
{
8991
if (recentFiles.remove(f.getAbsolutePath()))
9092
{
91-
DiskWriter.replaceFile(FILES_NAME, MiscUtils.listToString(recentFiles), false);
93+
saveRecentFiles();
9294
resetRecentFilesMenu();
9395
}
9496
}
9597

98+
private static void saveRecentFiles()
99+
{
100+
try
101+
{
102+
DiskWriter.write(FILES_NAME, MiscUtils.listToString(recentFiles));
103+
}
104+
catch (IOException e)
105+
{
106+
e.printStackTrace();
107+
}
108+
}
109+
96110
public static String getRecentFile()
97111
{
98112
if (recentFiles.isEmpty())
@@ -111,19 +125,31 @@ public static synchronized void addRecentPlugin(File f)
111125
recentPlugins.remove(f.getAbsolutePath()); // already added on the list
112126
recentPlugins.add(0, f.getAbsolutePath());
113127
MiscUtils.deduplicateAndTrim(recentPlugins, maxRecentFiles);
114-
DiskWriter.replaceFile(PLUGINS_NAME, MiscUtils.listToString(recentPlugins), false);
128+
saveRecentPlugins();
115129
resetRecentFilesMenu();
116130
}
117131

118132
public static synchronized void removeRecentPlugin(File f)
119133
{
120134
if (recentPlugins.remove(f.getAbsolutePath()))
121135
{
122-
DiskWriter.replaceFile(PLUGINS_NAME, MiscUtils.listToString(recentPlugins), false);
136+
saveRecentPlugins();
123137
resetRecentFilesMenu();
124138
}
125139
}
126140

141+
private static void saveRecentPlugins()
142+
{
143+
try
144+
{
145+
DiskWriter.write(PLUGINS_NAME, MiscUtils.listToString(recentPlugins));
146+
}
147+
catch (IOException e)
148+
{
149+
e.printStackTrace();
150+
}
151+
}
152+
127153
/**
128154
* resets the recent files menu
129155
*/

src/main/java/the/bytecode/club/bytecodeviewer/SettingsSerializer.java

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@
1818

1919
package the.bytecode.club.bytecodeviewer;
2020

21-
import me.konloch.kontainer.io.DiskReader;
22-
import me.konloch.kontainer.io.DiskWriter;
21+
import com.konloch.disklib.DiskReader;
22+
import com.konloch.disklib.DiskWriter;
2323
import the.bytecode.club.bytecodeviewer.decompilers.Decompiler;
2424
import the.bytecode.club.bytecodeviewer.gui.theme.LAFTheme;
2525
import the.bytecode.club.bytecodeviewer.gui.theme.RSTATheme;
2626
import the.bytecode.club.bytecodeviewer.translation.Language;
2727

2828
import javax.swing.*;
2929
import java.io.File;
30+
import java.io.IOException;
3031

3132
import static the.bytecode.club.bytecodeviewer.Constants.VERSION;
3233
import static the.bytecode.club.bytecodeviewer.Constants.SETTINGS_NAME;
@@ -40,6 +41,7 @@
4041
public class SettingsSerializer
4142
{
4243
private static boolean settingsFileExists;
44+
private static String[] settings;
4345

4446
public static void saveSettingsAsync()
4547
{
@@ -53,7 +55,7 @@ public static synchronized void saveSettings()
5355

5456
try
5557
{
56-
DiskWriter.replaceFile(SETTINGS_NAME, "BCV: " + VERSION, false);
58+
DiskWriter.write(SETTINGS_NAME, "BCV: " + VERSION, true);
5759
save(BytecodeViewer.viewer.rbr.isSelected());
5860
save(BytecodeViewer.viewer.rsy.isSelected());
5961
save(BytecodeViewer.viewer.din.isSelected());
@@ -169,9 +171,9 @@ public static synchronized void saveSettings()
169171
save(Configuration.deleteForeignLibraries);
170172

171173
if (BytecodeViewer.viewer.apkConversionGroup.isSelected(BytecodeViewer.viewer.apkConversionDex.getModel()))
172-
DiskWriter.writeNewLine(SETTINGS_NAME, "0");
174+
DiskWriter.append(SETTINGS_NAME, "0", true);
173175
else if (BytecodeViewer.viewer.apkConversionGroup.isSelected(BytecodeViewer.viewer.apkConversionEnjarify.getModel()))
174-
DiskWriter.writeNewLine(SETTINGS_NAME, "1");
176+
DiskWriter.append(SETTINGS_NAME, "1", true);
175177

176178
save(Configuration.python3);
177179
save(Configuration.javac);
@@ -224,7 +226,7 @@ public static void preloadSettingsFile()
224226
return;
225227

226228
//precache the file
227-
DiskReader.loadString(SETTINGS_NAME, 0, true);
229+
settings = DiskReader.readArray(SETTINGS_NAME);
228230

229231
//process the cached file
230232
Configuration.lafTheme = LAFTheme.valueOf(asString(127));
@@ -425,21 +427,28 @@ public static void loadSettings()
425427

426428
public static void save(Object o)
427429
{
428-
DiskWriter.writeNewLine(SETTINGS_NAME, String.valueOf(o), false);
430+
try
431+
{
432+
DiskWriter.append(SETTINGS_NAME, String.valueOf(o), true);
433+
}
434+
catch (IOException e)
435+
{
436+
e.printStackTrace();
437+
}
429438
}
430439

431-
public static String asString(int lineNumber) throws Exception
440+
public static String asString(int lineNumber)
432441
{
433-
return DiskReader.loadString(SETTINGS_NAME, lineNumber, false);
442+
return settings[lineNumber];
434443
}
435444

436-
public static boolean asBoolean(int lineNumber) throws Exception
445+
public static boolean asBoolean(int lineNumber)
437446
{
438-
return Boolean.parseBoolean(DiskReader.loadString(SETTINGS_NAME, lineNumber, false));
447+
return Boolean.parseBoolean(settings[lineNumber]);
439448
}
440449

441-
public static int asInt(int lineNumber) throws Exception
450+
public static int asInt(int lineNumber)
442451
{
443-
return Integer.parseInt(DiskReader.loadString(SETTINGS_NAME, lineNumber, false));
452+
return Integer.parseInt(settings[lineNumber]);
444453
}
445454
}

src/main/java/the/bytecode/club/bytecodeviewer/cli/CommandLineInput.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
package the.bytecode.club.bytecodeviewer.cli;
2020

21-
import me.konloch.kontainer.io.DiskWriter;
21+
import com.konloch.disklib.DiskWriter;
2222
import org.apache.commons.cli.CommandLine;
2323
import org.apache.commons.cli.CommandLineParser;
2424
import org.apache.commons.cli.DefaultParser;
@@ -250,7 +250,7 @@ public static void executeCommandLine(String[] args)
250250
ClassNode cn = BytecodeViewer.blindlySearchForClassNode(target);
251251
final ClassWriter cw = accept(cn);
252252
String contents = Decompiler.PROCYON_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray());
253-
DiskWriter.replaceFile(output.getAbsolutePath(), contents, false);
253+
DiskWriter.write(output.getAbsolutePath(), contents);
254254
}
255255
catch (Exception e)
256256
{
@@ -276,7 +276,7 @@ else if (decompiler.equalsIgnoreCase("cfr"))
276276
ClassNode cn = BytecodeViewer.blindlySearchForClassNode(target);
277277
final ClassWriter cw = accept(cn);
278278
String contents = Decompiler.CFR_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray());
279-
DiskWriter.replaceFile(output.getAbsolutePath(), contents, false);
279+
DiskWriter.write(output.getAbsolutePath(), contents);
280280
}
281281
catch (Exception e)
282282
{
@@ -302,7 +302,7 @@ else if (decompiler.equalsIgnoreCase("fernflower"))
302302
ClassNode cn = BytecodeViewer.blindlySearchForClassNode(target);
303303
final ClassWriter cw = accept(cn);
304304
String contents = Decompiler.FERNFLOWER_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray());
305-
DiskWriter.replaceFile(output.getAbsolutePath(), contents, false);
305+
DiskWriter.write(output.getAbsolutePath(), contents);
306306
}
307307
catch (Exception e)
308308
{
@@ -328,7 +328,7 @@ else if (decompiler.equalsIgnoreCase("krakatau"))
328328
ClassNode cn = BytecodeViewer.blindlySearchForClassNode(target);
329329
final ClassWriter cw = accept(cn);
330330
String contents = Decompiler.KRAKATAU_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray());
331-
DiskWriter.replaceFile(output.getAbsolutePath(), contents, false);
331+
DiskWriter.write(output.getAbsolutePath(), contents);
332332
}
333333
catch (Exception e)
334334
{
@@ -355,7 +355,7 @@ else if (decompiler.equalsIgnoreCase("krakatau-bytecode"))
355355
ClassNode cn = BytecodeViewer.blindlySearchForClassNode(target);
356356
final ClassWriter cw = accept(cn);
357357
String contents = Decompiler.KRAKATAU_DISASSEMBLER.getDecompiler().decompileClassNode(cn, cw.toByteArray());
358-
DiskWriter.replaceFile(output.getAbsolutePath(), contents, false);
358+
DiskWriter.write(output.getAbsolutePath(), contents);
359359
}
360360
catch (Exception e)
361361
{
@@ -382,7 +382,7 @@ else if (decompiler.equalsIgnoreCase("jd-gui"))
382382
ClassNode cn = BytecodeViewer.blindlySearchForClassNode(target);
383383
final ClassWriter cw = accept(cn);
384384
String contents = Decompiler.JD_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray());
385-
DiskWriter.replaceFile(output.getAbsolutePath(), contents, false);
385+
DiskWriter.write(output.getAbsolutePath(), contents);
386386
}
387387
catch (Exception e)
388388
{
@@ -409,7 +409,7 @@ else if (decompiler.equalsIgnoreCase("smali"))
409409
ClassNode cn = BytecodeViewer.blindlySearchForClassNode(target);
410410
final ClassWriter cw = accept(cn);
411411
String contents = Decompiler.SMALI_DISASSEMBLER.getDecompiler().decompileClassNode(cn, cw.toByteArray());
412-
DiskWriter.replaceFile(output.getAbsolutePath(), contents, false);
412+
DiskWriter.write(output.getAbsolutePath(), contents);
413413
}
414414
catch (Exception e)
415415
{
@@ -436,7 +436,7 @@ else if (decompiler.equalsIgnoreCase("jadx"))
436436
ClassNode cn = BytecodeViewer.blindlySearchForClassNode(target);
437437
final ClassWriter cw = accept(cn);
438438
String contents = Decompiler.JADX_DECOMPILER.getDecompiler().decompileClassNode(cn, cw.toByteArray());
439-
DiskWriter.replaceFile(output.getAbsolutePath(), contents, false);
439+
DiskWriter.write(output.getAbsolutePath(), contents);
440440
}
441441
catch (Exception e)
442442
{
@@ -463,7 +463,7 @@ else if (decompiler.equalsIgnoreCase("asmifier"))
463463
ClassNode cn = BytecodeViewer.blindlySearchForClassNode(target);
464464
final ClassWriter cw = accept(cn);
465465
String contents = Decompiler.ASMIFIER_CODE_GEN.getDecompiler().decompileClassNode(cn, cw.toByteArray());
466-
DiskWriter.replaceFile(output.getAbsolutePath(), contents, false);
466+
DiskWriter.write(output.getAbsolutePath(), contents);
467467
}
468468
catch (Exception e)
469469
{

src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/JavaCompiler.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
package the.bytecode.club.bytecodeviewer.compilers.impl;
2020

21-
import me.konloch.kontainer.io.DiskWriter;
21+
import com.konloch.disklib.DiskWriter;
2222
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
2323
import the.bytecode.club.bytecodeviewer.Configuration;
2424
import the.bytecode.club.bytecodeviewer.compilers.AbstractCompiler;
@@ -69,15 +69,15 @@ public byte[] compile(String contents, String fullyQualifiedName)
6969
return null;
7070
}
7171

72-
//write the file we're assembling to disk
73-
DiskWriter.replaceFile(javaFile.getAbsolutePath(), contents, false);
74-
75-
//write the entire temporary classpath to disk
76-
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), classPath.getAbsolutePath());
77-
7872
boolean cont = true;
7973
try
8074
{
75+
//write the file we're assembling to disk
76+
DiskWriter.write(javaFile.getAbsolutePath(), contents);
77+
78+
//write the entire temporary classpath to disk
79+
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), classPath.getAbsolutePath());
80+
8181
StringBuilder log = new StringBuilder();
8282
ProcessBuilder pb;
8383

src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/KrakatauAssembler.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
package the.bytecode.club.bytecodeviewer.compilers.impl;
2020

21-
import me.konloch.kontainer.io.DiskWriter;
21+
import com.konloch.disklib.DiskWriter;
2222
import org.apache.commons.io.FileUtils;
2323
import org.apache.commons.lang3.ArrayUtils;
2424
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
@@ -55,21 +55,20 @@ public byte[] compile(String contents, String fullyQualifiedName)
5555
final File tempDirectory2 = new File(Constants.TEMP_DIRECTORY + FS + MiscUtils.randomString(32) + FS);
5656
final File javaFile = new File(tempDirectory1.getAbsolutePath() + FS + fullyQualifiedName + ".j");
5757
final File tempJar = new File(Constants.TEMP_DIRECTORY + FS + "temp" + MiscUtils.randomString(32) + ".jar");
58+
final StringBuilder log = new StringBuilder();
5859

5960
//create the temp directories
6061
tempDirectory1.mkdir();
6162
tempDirectory2.mkdir();
6263

63-
//write the file we're assembling to disk
64-
DiskWriter.replaceFile(javaFile.getAbsolutePath(), contents, true);
65-
66-
//write the entire temporary classpath to disk
67-
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath());
68-
69-
StringBuilder log = new StringBuilder();
70-
7164
try
7265
{
66+
//write the file we're assembling to disk
67+
DiskWriter.write(javaFile.getAbsolutePath(), contents);
68+
69+
//write the entire temporary classpath to disk
70+
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), tempJar.getAbsolutePath());
71+
7372
String[] pythonCommands = new String[]{Configuration.python2};
7473
if (Configuration.python2Extra)
7574
pythonCommands = ArrayUtils.addAll(pythonCommands, "-2");

src/main/java/the/bytecode/club/bytecodeviewer/compilers/impl/SmaliAssembler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
package the.bytecode.club.bytecodeviewer.compilers.impl;
2020

21-
import me.konloch.kontainer.io.DiskWriter;
21+
import com.konloch.disklib.DiskWriter;
2222
import org.apache.commons.io.FileUtils;
2323
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
2424
import the.bytecode.club.bytecodeviewer.compilers.AbstractCompiler;
@@ -59,7 +59,7 @@ public byte[] compile(String contents, String fullyQualifiedName)
5959
try
6060
{
6161
//write the file we're assembling to disk
62-
DiskWriter.replaceFile(tempSmali.getAbsolutePath(), contents, false);
62+
DiskWriter.write(tempSmali.getAbsolutePath(), contents);
6363
}
6464
catch (Exception e)
6565
{

0 commit comments

Comments
 (0)