Skip to content

Commit

Permalink
Merge pull request #2 from rokuosan/develop
Browse files Browse the repository at this point in the history
コマンドライン引数の一部対応
  • Loading branch information
rokuosan authored Nov 6, 2021
2 parents dbf20bc + d0ed024 commit eaf8d44
Show file tree
Hide file tree
Showing 8 changed files with 391 additions and 64 deletions.
108 changes: 52 additions & 56 deletions src/main/java/com/deviseworks/CuberiteActionsClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,112 +9,108 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Scanner;

public class CuberiteActionsClass {
public void download(){
public URL setDownloadLink(){
MediaUtilitiesClass util = new MediaUtilitiesClass();
Scanner scanner = new Scanner(System.in);

// ダウンロードURLの指定
URL download_url;
System.out.print("\t- アーキテクチャを取得中...");
final String arch = System.getProperty("os.arch").toLowerCase();
System.out.print("\t- アーキテクチャを取得中...");

if(util.isWindows()) {
try {
if (arch.equalsIgnoreCase("amd64")) {
System.out.println("[64bit]");
download_url = new URL("https://download.cuberite.org/windows-x86_64/Cuberite.zip");
System.out.println("[Windows-64bit]");
return new URL("https://download.cuberite.org/windows-x86_64/Cuberite.zip");
} else if (arch.equalsIgnoreCase("x86")) {
System.out.println("[32bit]");
download_url = new URL("https://download.cuberite.org/windows-i386/Cuberite.zip");
} else {
System.out.println("[Windows-32bit]");
return new URL("https://download.cuberite.org/windows-i386/Cuberite.zip");
}else{
System.out.println("[UNKNOWN]");
System.out.println("\t- アーキテクチャ取得に失敗");
return;
return null;
}
System.out.println("\t- ダウンロードリンクを更新しました");
} catch (MalformedURLException e) {
System.out.println("[失敗]\n\t- アーキテクチャ取得に失敗");
return;
return null;
}
}else if(util.isLinux()){
try {
if (arch.equalsIgnoreCase("amd64")) {
System.out.println("[64bit]");
download_url = new URL("https://download.cuberite.org/linux-x86_64/Cuberite.tar.gz");
System.out.println("[Linux-64bit]");
return new URL("https://download.cuberite.org/linux-x86_64/Cuberite.tar.gz");
} else if (arch.equalsIgnoreCase("x86")) {
System.out.println("[32bit]");
download_url = new URL("https://download.cuberite.org/linux-i386/Cuberite.tar.gz");
System.out.println("[Linux-32bit]");
return new URL("https://download.cuberite.org/linux-i386/Cuberite.tar.gz");
} else {
System.out.println("[UNKNOWN]");
System.out.println("\t- アーキテクチャ取得に失敗");
return;
return null;
}
System.out.println("\t- ダウンロードリンクを更新しました");
} catch (MalformedURLException e) {
System.out.println("[失敗]\n\t- アーキテクチャ取得に失敗");
return;
return null;
}
}else{
System.out.println("[失敗]");
System.out.println("\t- Windows/Linuxのみサポートしています");
return;
}
return null;
}

// ダウンロード先を指定
Path current = Paths.get("").toAbsolutePath();
Path full_path;
public void download(){
this.download(false, null);
}
public void download(boolean isAutoApprove, String directory){
MediaUtilitiesClass util = new MediaUtilitiesClass();

int tag = 100;
// ダウンロードURLの指定
URL download_url = setDownloadLink();
if(download_url == null){
return;
}

System.out.print("\t- インストールディレクトリをサーチ中...");
while(true){
full_path = Paths.get(current + "/Cuberite/" + tag);
if(util.checkDirectory(full_path)){
break;
}else{
tag++;
// ダウンロード先を指定
Path path;
if(directory != null){
try{
path = Paths.get(directory);
}catch(InvalidPathException e){
System.out.println("\t- 無効なディレクトリパス");
return;
}
}else{
path = Paths.get("").toAbsolutePath();
int tag = 100;
while(true) {
if(!Files.exists(Paths.get(path + "/Cuberite/"+ tag + "/"))) {
path = Paths.get(path + "/Cuberite/" + tag + "/");
break;
}else{
tag++;
}
}
}

// ダウンロード
System.out.print("\n\t- 以下のリンクからダウンロードを行います\n\t- " + download_url + "\n\nよろしいですか?(Y/n): ");
String confirm = scanner.nextLine();
if(!(confirm.equalsIgnoreCase("yes") || confirm.equalsIgnoreCase("y"))){
System.out.println("\t- キャンセルしました");
if(!(util.confirm(isAutoApprove, "cuberite", "latest", "latest", String.valueOf(path), String.valueOf(download_url)))){
return;
}

// ディレクトリ作成
if(util.createDirectory(full_path)){
System.out.println("\t- ディレクトリを作成");
System.out.println("\t- " + full_path);
}else{
System.out.println("\t- ディレクトリの作成に失敗しました");
return;
}

// DL開始
System.out.print("\t- ダウンロードしています...");
if(util.downloadFile(download_url, full_path)){
System.out.println("[完了]");
}else{
System.out.println("[失敗]");
}
util.check(path, String.valueOf(download_url));

// 解凍
// URLからファイル名を取得
String filename = download_url.getPath().substring(download_url.getPath().lastIndexOf("/") +1);
String filepath = full_path + "/" + filename;
String filepath = path + "/" + filename;
boolean isSuccess = false;
if(util.isWindows()) {
System.out.print("\t- ファイルを解凍中...");
try {
new ZipFile(filepath).extractAll(full_path.toString());
new ZipFile(filepath).extractAll(path.toString());
System.out.println("[完了]");
isSuccess = true;
} catch (ZipException e) {
Expand All @@ -135,7 +131,7 @@ public void download(){
System.out.println("\t- ファイルを解凍します...");
try {
Runtime runtime = Runtime.getRuntime();
Process result = runtime.exec("tar -zxvf " + filepath + " -C " + full_path + "/");
Process result = runtime.exec("tar -zxvf " + filepath + " -C " + path + "/");
BufferedReader br = new BufferedReader(new InputStreamReader(result.getInputStream()));
while (true) {
String line = br.readLine();
Expand Down
Loading

0 comments on commit eaf8d44

Please sign in to comment.