This repository has been archived by the owner on Aug 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da11788
commit 16d452a
Showing
13 changed files
with
431 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" name="json-20220320" level="project" /> | ||
<orderEntry type="library" name="zip4j-2.10.0" level="project" /> | ||
</component> | ||
</module> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import java.io.BufferedReader; | ||
import java.io.InputStreamReader; | ||
|
||
public class ExecuteCommand{ | ||
public ExecuteCommand(String cmd){ | ||
String s; | ||
Process p; | ||
try { | ||
String[] arr = cmd.split(" "); | ||
p = Runtime.getRuntime().exec(arr); | ||
BufferedReader br = new BufferedReader( | ||
new InputStreamReader(p.getInputStream())); | ||
while ((s = br.readLine()) != null) | ||
System.out.println("line: " + s); | ||
p.waitFor(); | ||
System.out.println ("exit: " + p.exitValue()); | ||
p.destroy(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.net.URISyntaxException; | ||
|
||
public class FileChooserFrame extends JFrame { | ||
public FileChooserFrame() throws URISyntaxException { | ||
this.setSize(200,200); | ||
JFileChooser fileChooser = new JFileChooser(String.valueOf(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath())); | ||
this.add(fileChooser); | ||
|
||
this.setVisible(true); | ||
this.getContentPane().setBackground(Color.GRAY); | ||
|
||
} | ||
public FileChooserFrame(String path) throws URISyntaxException { | ||
this.setSize(200,200); | ||
JFileChooser fileChooser = new JFileChooser(path); | ||
this.add(fileChooser); | ||
|
||
this.setVisible(true); | ||
this.getContentPane().setBackground(Color.GRAY); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import java.net.URISyntaxException; | ||
|
||
public class Main { | ||
public static SearchFrame search; | ||
public static void main(String[] args) throws URISyntaxException { | ||
search = new SearchFrame(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
import net.lingala.zip4j.ZipFile; | ||
import net.lingala.zip4j.exception.ZipException; | ||
import net.lingala.zip4j.util.FileUtils; | ||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import javax.swing.*; | ||
import javax.swing.border.Border; | ||
import java.awt.*; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
import java.io.*; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.net.http.HttpClient; | ||
import java.net.http.HttpRequest; | ||
import java.net.http.HttpResponse; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.nio.file.StandardCopyOption; | ||
import java.util.Scanner; | ||
|
||
public class MainFrame extends JFrame implements ActionListener { | ||
JButton startBtn = new JButton("Download the Modpack"); | ||
JButton chooseBtn = new JButton("Choose the path"); | ||
JLabel label = new JLabel("The install can take a long time be patient"); | ||
static File path; | ||
String modpackName = ""; | ||
String modpackDownload = ""; | ||
MainFrame(String[] info) { | ||
this.modpackName = info[1]; | ||
this.modpackDownload = info[0]; | ||
this.setLocation(SearchFrame.select.getLocation()); | ||
path = new File(System.getProperty("user.home") + "/.linuxcurse/"); | ||
if(!path.exists()){ | ||
boolean success = path.mkdir(); | ||
if(!success){ | ||
System.out.println("Could not create the directory: " + path.getAbsolutePath()); | ||
} | ||
} | ||
|
||
// System.out.println(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()); | ||
Border border = BorderFactory.createLineBorder(Color.RED, 3); | ||
int width = 800, height = 500; | ||
startBtn.setBounds(0,0, 180, 40); | ||
startBtn.setLocation((width / 2) - (startBtn.getWidth() / 2),(height/2) - (startBtn.getHeight()/2) + 80); | ||
startBtn.setFocusable(false); | ||
startBtn.addActionListener(this); | ||
chooseBtn.setBounds(0,0, 180, 40); | ||
chooseBtn.setLocation((width / 2) - (startBtn.getWidth() / 2),(height/2) - (startBtn.getHeight()/2)); | ||
chooseBtn.setFocusable(false); | ||
chooseBtn.addActionListener(this); | ||
label.setBounds(0,0,300,40); | ||
label.setLocation((width / 2) - (startBtn.getWidth() / 2) - 40,(height/2) - (startBtn.getHeight()/2) - 80); | ||
this.setSize(width,height); | ||
this.setLayout(null); | ||
this.setTitle("LinuxCurse"); | ||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
|
||
this.add(startBtn); | ||
this.add(chooseBtn); | ||
this.add(label); | ||
|
||
this.setVisible(true); | ||
this.getContentPane().setBackground(Color.GRAY); | ||
} | ||
/* Shoutout to this guy: https://stackoverflow.com/a/5368745/14269129 */ | ||
public void copy(File sourceLocation, File targetLocation) throws IOException { | ||
if (sourceLocation.isDirectory()) { | ||
copyDirectory(sourceLocation, targetLocation); | ||
} else { | ||
copyFile(sourceLocation, targetLocation); | ||
} | ||
} | ||
|
||
private void copyDirectory(File source, File target) throws IOException { | ||
if (!target.exists()) { | ||
target.mkdir(); | ||
} | ||
|
||
for (String f : source.list()) { | ||
copy(new File(source, f), new File(target, f)); | ||
} | ||
} | ||
|
||
private void copyFile(File source, File target) throws IOException { | ||
try ( | ||
InputStream in = new FileInputStream(source); | ||
OutputStream out = new FileOutputStream(target) | ||
) { | ||
byte[] buf = new byte[1024]; | ||
int length; | ||
while ((length = in.read(buf)) > 0) { | ||
out.write(buf, 0, length); | ||
} | ||
} | ||
} | ||
static String folderName = ""; | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
if(e.getSource() == chooseBtn){ | ||
JFileChooser fileChooser = new JFileChooser(); | ||
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); | ||
fileChooser.setCurrentDirectory(new File(System.getProperty("user.home"))); | ||
int result = fileChooser.showOpenDialog(this); | ||
if (result == JFileChooser.APPROVE_OPTION) { | ||
File selectedFile = fileChooser.getSelectedFile(); | ||
System.out.println("Selected file: " + selectedFile.getAbsolutePath()); | ||
path = new File(selectedFile.getAbsolutePath()); | ||
if(!path.exists()){ | ||
System.out.println("Path: " + path + " doesn't exist"); | ||
} | ||
} | ||
} | ||
if(e.getSource() == startBtn){ | ||
System.out.println("Download link: " + modpackDownload + " Modpack: " + modpackName); | ||
InputStream inputStream = null; | ||
try { | ||
inputStream = new URL(modpackDownload).openStream(); | ||
Files.copy(inputStream, Paths.get(path.getAbsolutePath() + "/modpack.zip"), StandardCopyOption.REPLACE_EXISTING); | ||
} catch (IOException ex) { | ||
ex.printStackTrace(); | ||
}finally { | ||
try { | ||
folderName = modpackName.replaceAll("[^A-Za-z0-9\",]|,(?!(([^\"]*\"){2})*[^\"]*$)", "").replace("\"", "").replace(",", "").replace(" ", ""); | ||
new ZipFile(Paths.get(path.getAbsolutePath() + "/modpack.zip").toFile()) | ||
.extractAll(Paths.get(path.getAbsolutePath() + "/unzip/").toString()); | ||
new File(path.getAbsolutePath() + "/" + folderName + "/").mkdirs(); | ||
if(new File(path.getAbsolutePath() + "/unzip/overrides/").exists()){ | ||
File srcDir = new File(path.getAbsolutePath() + "/unzip/overrides/"); | ||
File destDir = new File(path.getAbsolutePath() + "/" + folderName + "/" + ".minecraft/"); | ||
|
||
copyDirectory(srcDir,destDir); | ||
} | ||
new File(path.getAbsolutePath() + "/" + folderName + "/" + ".minecraft/mods").mkdir(); | ||
new File(path.getAbsolutePath() + "/" + folderName + "/" + ".minecraft/versions").mkdir(); | ||
if(new File(path.getAbsolutePath() + "/unzip/manifest.json").exists()){ | ||
File file = new File(path.getAbsolutePath() + "/unzip/manifest.json"); | ||
Scanner reader = new Scanner(file); | ||
String text = ""; | ||
while (reader.hasNextLine()) { | ||
text = text + reader.nextLine(); | ||
} | ||
reader.close(); | ||
JSONObject json = new JSONObject(text); | ||
String forgeID = json.getJSONObject("minecraft").getJSONArray("modLoaders").getJSONObject(0).get("id").toString(); | ||
String strippedID = forgeID.replace("forge-", ""); | ||
String forgeVersion = json.getJSONObject("minecraft").get("version").toString(); | ||
String forgelink = "https://maven.minecraftforge.net/net/minecraftforge/forge/" + forgeVersion + "-" + strippedID + "/" + "forge-" + forgeVersion + "-" + strippedID + "-installer.jar"; | ||
inputStream = new URL(forgelink).openStream(); | ||
Files.copy(inputStream, Paths.get(path.getAbsolutePath() + "/forge.jar"), StandardCopyOption.REPLACE_EXISTING); | ||
int result = JOptionPane.showConfirmDialog(this, "Minecraft launcher will be openend. Sign in then wait until u see the play button then close the window"); | ||
if(result == 0) { | ||
new ExecuteCommand("minecraft-launcher --workDir " + path.getAbsolutePath() + "/" + folderName + "/" + ".minecraft/"); | ||
}else { | ||
System.exit(0); | ||
} | ||
int r = JOptionPane.showConfirmDialog(this, "Forge installer will be opened just click the button OK"); | ||
if(r == 0) { | ||
new ExecuteCommand("java -Duser.home=" + path.getAbsolutePath() + "/" + folderName + "/ -jar " + path.getAbsolutePath() + "/forge.jar"); | ||
}else{ | ||
System.exit(0); | ||
} | ||
System.out.println("java -Duser.home=" + path.getAbsolutePath() + "/" + folderName + "/ -jar " + path.getAbsolutePath() + "/forge.jar"); | ||
JSONArray files = json.getJSONArray("files"); | ||
files.forEach(f -> { | ||
if(f instanceof JSONObject){ | ||
JSONObject jsFile = (JSONObject) f; | ||
String projectID = jsFile.get("projectID").toString(); | ||
String fileID = jsFile.get("fileID").toString(); | ||
String modlink = "https://addons-ecs.forgesvc.net/api/v2/addon/" + projectID + "/file/" + fileID; | ||
HttpClient client = HttpClient.newHttpClient(); | ||
HttpRequest request = HttpRequest.newBuilder() | ||
.uri(URI.create(modlink)).setHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:92.0) Gecko/20100101 Firefox/92.0").build(); | ||
|
||
|
||
client.sendAsync(request, HttpResponse.BodyHandlers.ofString()) | ||
.thenApply(HttpResponse::body) | ||
.thenAccept(MainFrame::downloadMod) | ||
.join(); | ||
} | ||
}); | ||
int re = JOptionPane.showConfirmDialog(this, "This is the final step. Minecraft launcher will open just click play."); | ||
new ExecuteCommand("minecraft-launcher --workDir " + path.getAbsolutePath() + "/" + folderName + "/" + ".minecraft/"); | ||
}else{ | ||
throw new FileNotFoundException("Could not find manifest.json"); | ||
} | ||
} catch (IOException ex) { | ||
ex.printStackTrace(); | ||
} | ||
} | ||
} | ||
} | ||
public static void downloadMod(String responce){ | ||
try { | ||
JSONObject jsonObject = new JSONObject(responce); | ||
String downloadLink = jsonObject.get("downloadUrl").toString(); | ||
String fileName = jsonObject.get("fileName").toString(); | ||
InputStream inputStream = null; | ||
try { | ||
System.out.println("Downloading " + fileName); | ||
inputStream = new URL(downloadLink).openStream(); | ||
Files.copy(inputStream, Paths.get(path.getAbsolutePath() + "/" + folderName + "/" + ".minecraft/mods/" + fileName), StandardCopyOption.REPLACE_EXISTING); | ||
inputStream.close(); | ||
} catch (IOException ex){ | ||
ex.printStackTrace(); | ||
} | ||
}catch (JSONException e){ | ||
System.out.println("Err with the json: " + responce + " Retrying..."); | ||
downloadMod(responce); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
|
||
import javax.swing.*; | ||
import javax.swing.border.Border; | ||
import java.awt.*; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
import java.lang.reflect.Array; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.net.http.HttpClient; | ||
import java.net.http.HttpRequest; | ||
import java.net.http.HttpResponse; | ||
import java.util.ArrayList; | ||
|
||
public class SearchFrame extends JFrame implements ActionListener { | ||
static SelectFrame select; | ||
JButton searchBtn = new JButton("Search"); | ||
int c = 0; | ||
JTextField searchTerm = new JTextField(); | ||
SearchFrame() { | ||
Border border = BorderFactory.createLineBorder(Color.RED, 3); | ||
int width = 800, height = 500; | ||
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); | ||
|
||
double screenHeight = dimension.getHeight(); | ||
double screenWidth = dimension.getWidth(); | ||
this.setLocation((int)(screenWidth / 2) - (width / 2), (int)(screenHeight / 2) - (height / 2)); | ||
searchBtn.setBounds(0,0, 180, 40); | ||
searchBtn.setLocation((width / 2) - (searchBtn.getWidth() / 2),(height/2) - (searchBtn.getHeight()/2) + 80); | ||
searchBtn.setFocusable(false); | ||
searchBtn.addActionListener(this); | ||
searchTerm.setBounds(0,0,200,40); | ||
searchTerm.setLocation((width / 2) - (searchBtn.getWidth() / 2) - 10,(height/2) - (searchBtn.getHeight()/2)); | ||
this.setSize(width,height); | ||
this.setLayout(null); | ||
this.setTitle("LinuxCurse"); | ||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
|
||
this.add(searchBtn); | ||
this.add(searchTerm); | ||
|
||
this.setVisible(true); | ||
this.getContentPane().setBackground(Color.GRAY); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
|
||
if(e.getSource() == searchBtn){ | ||
search(searchTerm.getText()); | ||
|
||
} | ||
} | ||
|
||
public void search(String searchTerm){ | ||
HttpClient client = HttpClient.newHttpClient(); | ||
HttpRequest request = HttpRequest.newBuilder() | ||
.uri(URI.create("https://addons-ecs.forgesvc.net/api/v2/addon/search?categoryId=0&gameId=432&index=1&pageSize=0&searchFilter=" + searchTerm.replace(" ", "%20"))).setHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:92.0) Gecko/20100101 Firefox/92.0").build(); | ||
|
||
|
||
System.out.println("Searching..."); | ||
client.sendAsync(request, HttpResponse.BodyHandlers.ofString()) | ||
.thenApply(HttpResponse::body) | ||
.thenAccept(SearchFrame::processResponce) | ||
.join(); | ||
} | ||
public static void processResponce(String responce) { | ||
JSONArray obj = new JSONArray(responce); | ||
System.out.println(obj.get(0)); | ||
ArrayList<String> modpackNames = new ArrayList<>(); | ||
for (Object object : obj){ | ||
if(object instanceof JSONObject modpack){ | ||
String modpackName = modpack.get("name").toString();/*.replaceAll("[^A-Za-z0-9\", ]|,(?!(([^\"]*\"){2})*[^\"]*$)", "").replace("\"", "").replace(",", "");*/ | ||
String downloadLink = modpack.getJSONArray("latestFiles").getJSONObject(modpack.getJSONArray("latestFiles").length() - 1).get("downloadUrl").toString().replace(" ", "%20"); | ||
modpackNames.add(modpackName + "A:W:B]" + downloadLink); | ||
System.out.println(modpackName); | ||
} | ||
} | ||
if(!modpackNames.isEmpty()){ | ||
Main.search.setVisible(false); | ||
select = new SelectFrame(modpackNames); | ||
|
||
}else{ | ||
JOptionPane.showMessageDialog(Main.search, "No modpacks found."); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.