|
@@ -24,6 +24,7 @@ import android.widget.Toast;
|
|
|
|
|
|
import com.xugame.gameconsole.emulator.RetroArchEmulatorActivity;
|
|
|
import com.xugame.gameconsole.preferences.UserPreferences;
|
|
|
+import com.xugame.gameconsole.util.DebugUtil;
|
|
|
import com.xugame.gameconsole.util.Util;
|
|
|
|
|
|
import java.io.BufferedOutputStream;
|
|
@@ -44,19 +45,15 @@ public class MainActivity extends PreferenceActivity implements View.OnClickList
|
|
|
public static String PACKAGE_NAME;
|
|
|
boolean checkPermissions = false;
|
|
|
|
|
|
- public void showMessageOKCancel(String message, DialogInterface.OnClickListener onClickListener)
|
|
|
- {
|
|
|
+ public void showMessageOKCancel(String message, DialogInterface.OnClickListener onClickListener) {
|
|
|
new AlertDialog.Builder(this).setMessage(message)
|
|
|
.setPositiveButton("OK", onClickListener).setCancelable(false)
|
|
|
.setNegativeButton("Cancel", null).create().show();
|
|
|
}
|
|
|
|
|
|
- private boolean addPermission(List<String> permissionsList, String permission)
|
|
|
- {
|
|
|
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M)
|
|
|
- {
|
|
|
- if (checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED)
|
|
|
- {
|
|
|
+ private boolean addPermission(List<String> permissionsList, String permission) {
|
|
|
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
|
|
+ if (checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
|
|
|
permissionsList.add(permission);
|
|
|
|
|
|
// Check for Rationale Option
|
|
@@ -68,10 +65,8 @@ public class MainActivity extends PreferenceActivity implements View.OnClickList
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- public void checkRuntimePermissions()
|
|
|
- {
|
|
|
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M)
|
|
|
- {
|
|
|
+ public void checkRuntimePermissions() {
|
|
|
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
|
|
// Android 6.0+ needs runtime permission checks
|
|
|
List<String> permissionsNeeded = new ArrayList<String>();
|
|
|
final List<String> permissionsList = new ArrayList<String>();
|
|
@@ -81,12 +76,10 @@ public class MainActivity extends PreferenceActivity implements View.OnClickList
|
|
|
if (!addPermission(permissionsList, Manifest.permission.WRITE_EXTERNAL_STORAGE))
|
|
|
permissionsNeeded.add("Write External Storage");
|
|
|
|
|
|
- if (permissionsList.size() > 0)
|
|
|
- {
|
|
|
+ if (permissionsList.size() > 0) {
|
|
|
checkPermissions = true;
|
|
|
|
|
|
- if (permissionsNeeded.size() > 0)
|
|
|
- {
|
|
|
+ if (permissionsNeeded.size() > 0) {
|
|
|
// Need Rationale
|
|
|
Log.i("MainMenuActivity", "Need to request external storage permissions.");
|
|
|
|
|
@@ -96,13 +89,10 @@ public class MainActivity extends PreferenceActivity implements View.OnClickList
|
|
|
message = message + ", " + permissionsNeeded.get(i);
|
|
|
|
|
|
showMessageOKCancel(message,
|
|
|
- new DialogInterface.OnClickListener()
|
|
|
- {
|
|
|
+ new DialogInterface.OnClickListener() {
|
|
|
@Override
|
|
|
- public void onClick(DialogInterface dialog, int which)
|
|
|
- {
|
|
|
- if (which == AlertDialog.BUTTON_POSITIVE)
|
|
|
- {
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ if (which == AlertDialog.BUTTON_POSITIVE) {
|
|
|
requestPermissions(permissionsList.toArray(new String[permissionsList.size()]),
|
|
|
REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS);
|
|
|
|
|
@@ -110,9 +100,7 @@ public class MainActivity extends PreferenceActivity implements View.OnClickList
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
requestPermissions(permissionsList.toArray(new String[permissionsList.size()]),
|
|
|
REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS);
|
|
|
|
|
@@ -121,14 +109,12 @@ public class MainActivity extends PreferenceActivity implements View.OnClickList
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (!checkPermissions)
|
|
|
- {
|
|
|
+ if (!checkPermissions) {
|
|
|
finalStartup();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void finalStartup()
|
|
|
- {
|
|
|
+ public void finalStartup() {
|
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
Intent retro = new Intent(this, RetroArchEmulatorActivity.class);
|
|
|
|
|
@@ -147,9 +133,9 @@ public class MainActivity extends PreferenceActivity implements View.OnClickList
|
|
|
startActivity(retro);
|
|
|
finish();
|
|
|
}
|
|
|
+
|
|
|
public static void startRetroActivity(Intent retro, String contentPath, String corePath,
|
|
|
- String configFilePath, String imePath, String dataDirPath, String dataSourcePath)
|
|
|
- {
|
|
|
+ String configFilePath, String imePath, String dataDirPath, String dataSourcePath) {
|
|
|
if (contentPath != null) {
|
|
|
retro.putExtra("ROM", contentPath);
|
|
|
}
|
|
@@ -161,27 +147,21 @@ public class MainActivity extends PreferenceActivity implements View.OnClickList
|
|
|
retro.putExtra("SDCARD", Environment.getExternalStorageDirectory().getAbsolutePath());
|
|
|
String external = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + PACKAGE_NAME + "/files";
|
|
|
retro.putExtra("EXTERNAL", external);
|
|
|
- Log.i("TEST_STAT","rompath="+contentPath+"\ncorePath="+corePath+"\n"+"configFilePath="+configFilePath+"\nimePath="+imePath
|
|
|
- +"\nDATADIR="+dataDirPath+"\nAPK="+dataSourcePath+
|
|
|
- "\nSDCARD="+Environment.getExternalStorageDirectory().getAbsolutePath()+"\nEXTERNAL="
|
|
|
- +external);
|
|
|
- retro.putExtra("screenMode",screenMode);
|
|
|
+ Log.i("TEST_STAT", "rompath=" + contentPath + "\ncorePath=" + corePath + "\n" + "configFilePath=" + configFilePath + "\nimePath=" + imePath
|
|
|
+ + "\nDATADIR=" + dataDirPath + "\nAPK=" + dataSourcePath +
|
|
|
+ "\nSDCARD=" + Environment.getExternalStorageDirectory().getAbsolutePath() + "\nEXTERNAL="
|
|
|
+ + external);
|
|
|
+ retro.putExtra("screenMode", screenMode);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
|
|
|
- {
|
|
|
- switch (requestCode)
|
|
|
- {
|
|
|
+ public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
|
|
+ switch (requestCode) {
|
|
|
case REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS:
|
|
|
- for (int i = 0; i < permissions.length; i++)
|
|
|
- {
|
|
|
- if(grantResults[i] == PackageManager.PERMISSION_GRANTED)
|
|
|
- {
|
|
|
+ for (int i = 0; i < permissions.length; i++) {
|
|
|
+ if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
|
|
|
Log.i("MainMenuActivity", "Permission: " + permissions[i] + " was granted.");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
Log.i("MainMenuActivity", "Permission: " + permissions[i] + " was not granted.");
|
|
|
}
|
|
|
}
|
|
@@ -194,8 +174,10 @@ public class MainActivity extends PreferenceActivity implements View.OnClickList
|
|
|
|
|
|
finalStartup();
|
|
|
}
|
|
|
- private String corePath,romPath,coreName;
|
|
|
- private static int screenMode=0;
|
|
|
+
|
|
|
+ private String baseUsbPath, corePath, romPath, coreName;
|
|
|
+ private static int screenMode = 0;
|
|
|
+
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
@@ -203,24 +185,24 @@ public class MainActivity extends PreferenceActivity implements View.OnClickList
|
|
|
// this.findView();
|
|
|
Util.init(this);
|
|
|
PACKAGE_NAME = getPackageName();
|
|
|
- romPath=getIntent().getStringExtra("romPath");
|
|
|
- corePath=getIntent().getStringExtra("corePath");
|
|
|
- coreName=getIntent().getStringExtra("coreName");
|
|
|
- screenMode=getIntent().getIntExtra("screenMode",0);
|
|
|
-
|
|
|
-
|
|
|
+ baseUsbPath = getIntent().getStringExtra("baseUsbPath");
|
|
|
+ romPath = getIntent().getStringExtra("romPath");
|
|
|
+ corePath = getIntent().getStringExtra("corePath");
|
|
|
+ coreName = getIntent().getStringExtra("coreName");
|
|
|
+ screenMode = getIntent().getIntExtra("screenMode", 0);
|
|
|
checkCores();
|
|
|
|
|
|
}
|
|
|
- private void checkCores(){
|
|
|
- if(TextUtils.isEmpty(corePath)){
|
|
|
+
|
|
|
+ private void checkCores() {
|
|
|
+ if (TextUtils.isEmpty(corePath)) {
|
|
|
finish();
|
|
|
}
|
|
|
- File file=new File(corePath);
|
|
|
- if(file.exists()){
|
|
|
+ File file = new File(corePath);
|
|
|
+ if (file.exists()) {
|
|
|
start();
|
|
|
- }else {
|
|
|
- startCopy(coreName,corePath);
|
|
|
+ } else {
|
|
|
+ startCopy(coreName, corePath);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -232,7 +214,7 @@ public class MainActivity extends PreferenceActivity implements View.OnClickList
|
|
|
new AsyncTask<String, Integer, String>() {
|
|
|
@Override
|
|
|
protected String doInBackground(String... strings) {
|
|
|
- copyFile(getFilesDir().getParent() + File.separator+"cores/" + fileName, fileName);
|
|
|
+ copyFile(getFilesDir().getParent() + File.separator + "cores/" + fileName, fileName);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
@@ -246,17 +228,23 @@ public class MainActivity extends PreferenceActivity implements View.OnClickList
|
|
|
|
|
|
|
|
|
private boolean copyFile(String file_path, String fileName) {
|
|
|
- File baseFile=new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/arcade/cores/");
|
|
|
- if(!baseFile.exists())//创建/arcade/cores文件夹
|
|
|
+ File baseFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/arcade/cores/");
|
|
|
+ if (!baseFile.exists())//创建/arcade/cores文件夹
|
|
|
baseFile.mkdirs();
|
|
|
+ File file;
|
|
|
+ if (!TextUtils.isEmpty(baseUsbPath)) {
|
|
|
+ file = new File(baseUsbPath + "/cores/" + fileName);
|
|
|
+ } else
|
|
|
+ file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/arcade/cores/" + fileName);
|
|
|
|
|
|
- File file=new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/arcade/cores/"+fileName);
|
|
|
- if(!file.exists())//检测cores文件夹下是否存在.so
|
|
|
+ if (!file.exists())//检测cores文件夹下是否存在.so
|
|
|
return false;
|
|
|
+ DebugUtil.i("COPY:", file.getAbsolutePath());
|
|
|
+
|
|
|
try {
|
|
|
InputStream in = null;
|
|
|
// in = this.getResources().getAssets().open("xucores/"+fileName);
|
|
|
- in= new FileInputStream(file);
|
|
|
+ in = new FileInputStream(file);
|
|
|
BufferedOutputStream outStream
|
|
|
= new BufferedOutputStream(new FileOutputStream(file_path, false));
|
|
|
byte[] buffer = new byte[1024];
|
|
@@ -276,11 +264,12 @@ public class MainActivity extends PreferenceActivity implements View.OnClickList
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
- private void start(){
|
|
|
+
|
|
|
+ private void start() {
|
|
|
// Bind audio stream to hardware controls.
|
|
|
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
|
|
|
|
|
- UserPreferences.updateConfigFile(this);
|
|
|
+ UserPreferences.updateConfigFile(this,baseUsbPath+File.separator+"/system");
|
|
|
|
|
|
checkRuntimePermissions();
|
|
|
}
|
|
@@ -303,9 +292,8 @@ public class MainActivity extends PreferenceActivity implements View.OnClickList
|
|
|
|
|
|
if (view == mBtnLocalGame) {
|
|
|
|
|
|
- if (!checkPermissions)
|
|
|
- {
|
|
|
- finalStartup();
|
|
|
+ if (!checkPermissions) {
|
|
|
+ finalStartup();
|
|
|
}
|
|
|
|
|
|
// String PACKAGE_NAME = this.getPackageName();
|