Skip to content

Commit

Permalink
Fixed Windows PCs
Browse files Browse the repository at this point in the history
  • Loading branch information
ThexXTURBOXx committed Jan 4, 2020
1 parent e860efa commit a439373
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>de.femtopedia</groupId>
<artifactId>CCMobileSwitcher</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>

<repositories>
<repository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public MenuWindow() {
File filePath = packages.getParentFile();
File abFile = new File(filePath, "backup.ab");
File tarFile = new File(filePath, "backup.tar");
Utils.packTar(tarFile.toString(), packages.toString());
Utils.packTar(tarFile, packages, filePath);
String[] switcher = new String[]{"pack", tarFile.toString(),
abFile.toString()};
org.nick.abe.Main.main(switcher);
Expand Down Expand Up @@ -114,9 +114,7 @@ public MenuWindow() {
StandardCharsets.UTF_8);
content = content.replaceAll(
"org\\.dashnet\\.cookieclicker(?:.*?)/",
pkg + "/").replaceAll(
"org\\.dashnet\\.cookieclicker(?:.*?)\\.",
pkg + ".");
pkg + "/");
IOUtils.write(content, new FileOutputStream(destPackage),
StandardCharsets.UTF_8);

Expand Down
34 changes: 30 additions & 4 deletions src/main/java/de/femtopedia/ccmobileswitcher/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.apache.commons.compress.utils.IOUtils;

public class Utils {

Expand Down Expand Up @@ -50,7 +51,9 @@ public static void extractTar(InputStream stream, File outputDir) throws IOExcep
TarArchiveInputStream in = new TarArchiveInputStream(stream);
TarArchiveEntry entry;
while ((entry = in.getNextTarEntry()) != null) {
if (!entry.isDirectory()) {
if (entry.isDirectory()) {
new File(outputDir, entry.getName()).mkdirs();
} else {
extractTarFile(in, entry, outputDir);
}
}
Expand Down Expand Up @@ -87,18 +90,41 @@ public static void extractTarFile(TarArchiveInputStream in,
out.close();
}

public static void packTar(String out, String list) throws IOException {
public static void packTar(File out, File list, File dir) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(list));
TarArchiveOutputStream writer =
new TarArchiveOutputStream(new FileOutputStream(out));
writer.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
writer.setAddPaxHeadersForNonAsciiNames(true);
String line;
while ((line = reader.readLine()) != null) {
File in = new File(line);
writer.createArchiveEntry(in, in.getPath());
File in = new File(dir, line);
File entryDir = new File(line).getParentFile();
addToArchiveCompression(writer, in, entryDir.toString());
}
reader.close();
writer.flush();
writer.close();
}

private static void addToArchiveCompression(TarArchiveOutputStream out, File file, String dir) throws IOException {
String entry = dir + File.separator + file.getName();
if (file.isFile()) {
out.putArchiveEntry(new TarArchiveEntry(file, entry));
try (FileInputStream in = new FileInputStream(file)) {
IOUtils.copy(in, out);
}
out.closeArchiveEntry();
} else if (file.isDirectory()) {
File[] children = file.listFiles();
if (children != null) {
for (File child : children) {
addToArchiveCompression(out, child, entry);
}
}
} else {
System.out.println(file.getName() + " is not supported");
}
}

}

0 comments on commit a439373

Please sign in to comment.