forked from opZywl/FDPClient-legacy
-
Notifications
You must be signed in to change notification settings - Fork 23
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
LaoShui
committed
Jul 9, 2024
1 parent
c1abea8
commit 7104ab6
Showing
4 changed files
with
144 additions
and
6 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
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
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,103 @@ | ||
package com.guimc.fuckpcl | ||
|
||
import com.guimc.fuckpcl.utils.WindowUtils | ||
import java.io.File | ||
import java.util.* | ||
|
||
/** | ||
* A library checks Plain Craft Launcher | ||
* @author guimc, liuli (The UnlegitMC Team) | ||
*/ | ||
object PCLChecker { | ||
/** | ||
* This method will delete in next version and this can only check PCL title because the minecraft folder path not given | ||
* @return check result | ||
*/ | ||
@Deprecated("This method will delete in next version", ReplaceWith("fullCheck(mcDir, deleteFolder)", "com.guimc.fuckpcl.PCLChecker.fullCheck")) | ||
fun runCheck(): Boolean { | ||
return titleCheck() | ||
} | ||
|
||
/** | ||
* run full PCL check | ||
* @param mcDir minecraft folder path | ||
* @param deleteFolder delete PCL data folder for next PCL deleted check | ||
* @return check result | ||
*/ | ||
@JvmOverloads | ||
fun fullCheck(mcDir: File, deleteFolder: Boolean = true): Boolean { | ||
// check if there is a window named PCL | ||
if (titleCheck()) | ||
return true | ||
|
||
// maybe the window not exists like close the window after launched , so we need to check the PCL data folder | ||
if (folderCheck(mcDir, deleteFolder)) | ||
return true | ||
|
||
// PCL is not exists in the PC | ||
return false | ||
} | ||
|
||
/** | ||
* run PCL title check | ||
* check if there exists a title name contained "Plain Craft Launcher" | ||
* @return check result | ||
*/ | ||
fun titleCheck(): Boolean { | ||
return if (!WindowUtils.isWindows()) { | ||
false // PCL and the native file only support windows | ||
} else { | ||
WindowUtils.findWindow("Plain Craft Launcher") // PCL Title "Plain Craft Launcher 2" | ||
} | ||
} | ||
|
||
/** | ||
* run PCL data folder check | ||
* @param mcDir minecraft folder path | ||
* @param deleteFolder delete PCL data folder for next PCL deleted check | ||
* @return check result | ||
*/ | ||
fun folderCheck(mcDir: File, deleteFolder: Boolean): Boolean { | ||
require(mcDir.exists()) { "Argument \"mcDir\" is not exists" } | ||
require(mcDir.isDirectory) { "Argument \"mcDir\" should be a folder" } | ||
|
||
var exists = false | ||
val pclDataDir = File(mcDir, "PCL") | ||
if (pclDataDir.exists()) { | ||
if (deleteFolder) | ||
deleteFolder(pclDataDir) | ||
exists=true | ||
} // me need to delete all folders | ||
|
||
val mcVersionDir = File(mcDir, "versions") | ||
if (mcVersionDir.exists()) { // I think this should be existed but ... | ||
Arrays.stream(mcVersionDir.listFiles()).forEach { folder: File? -> | ||
val pclVersionDataDir = File(folder, "PCL") | ||
if (pclVersionDataDir.exists()) { | ||
if (deleteFolder) | ||
deleteFolder(pclVersionDataDir) | ||
exists = true | ||
} | ||
} | ||
} | ||
if(exists) | ||
return true | ||
|
||
return false | ||
} | ||
|
||
private fun deleteFolder(folder: File){ | ||
require(folder.exists()) { "Argument \"folder\" is not exists" } | ||
require(folder.isDirectory) { "Argument \"folder\" should be a folder" } | ||
|
||
folder.listFiles().forEach { | ||
if(it.isFile){ | ||
it.delete() | ||
}else if(it.isDirectory){ | ||
deleteFolder(it) | ||
} | ||
} | ||
|
||
folder.delete() | ||
} | ||
} |
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,39 @@ | ||
package com.guimc.fuckpcl.utils; | ||
|
||
import com.sun.jna.Native; | ||
import com.sun.jna.Pointer; | ||
import com.sun.jna.platform.win32.WinDef.HWND; | ||
import com.sun.jna.platform.win32.WinUser; | ||
import com.sun.jna.win32.StdCallLibrary; | ||
|
||
public class WindowUtils { | ||
public interface User32 extends StdCallLibrary { | ||
User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class); | ||
boolean EnumWindows(WinUser.WNDENUMPROC lpEnumFunc, Pointer arg); | ||
int GetWindowTextA(HWND hWnd, byte[] lpString, int nMaxCount); | ||
} | ||
|
||
public static boolean isWindows() { | ||
String OS = System.getProperty("os.name").toLowerCase(); | ||
return OS.contains("windows"); | ||
} | ||
|
||
public static Boolean findWindow(String Text) { | ||
final User32 user32 = User32.INSTANCE; | ||
final Boolean[] windowFunded = new Boolean[1]; | ||
|
||
windowFunded[0] = false; | ||
|
||
user32.EnumWindows((hwnd, arg1) -> { | ||
byte[] windowText = new byte[512]; | ||
user32.GetWindowTextA(hwnd, windowText, 512); | ||
String wText = Native.toString(windowText); | ||
if(wText.contains(Text)) { | ||
windowFunded[0] = true; | ||
} | ||
return true; | ||
}, null); | ||
|
||
return windowFunded[0]; | ||
} | ||
} |