[steamcmd]Update layout, refactor code, fix minor bugs
This commit is contained in:
parent
0978b30e34
commit
9a4468477d
2 changed files with 78 additions and 37 deletions
|
@ -90,19 +90,24 @@ public class SteamActivity extends Activity {
|
||||||
});
|
});
|
||||||
|
|
||||||
LinearLayout buttons = new LinearLayout(this);
|
LinearLayout buttons = new LinearLayout(this);
|
||||||
|
buttons.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
|
||||||
buttons.addView(startButton);
|
buttons.addView(startButton);
|
||||||
buttons.addView(stopButton);
|
buttons.addView(stopButton);
|
||||||
launcher.addView(buttons);
|
LinearLayout progressLayout = new LinearLayout(this);
|
||||||
scroll.addView(output);
|
progressLayout.setOrientation(LinearLayout.VERTICAL);
|
||||||
|
progressLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
|
||||||
progress = new ProgressBar(this, null,
|
progress = new ProgressBar(this, null,
|
||||||
android.R.attr.progressBarStyleHorizontal);
|
android.R.attr.progressBarStyleHorizontal);
|
||||||
progress.setMax(100);
|
progress.setMax(100);
|
||||||
progress.setVisibility(View.GONE);
|
progress.setVisibility(View.GONE);
|
||||||
progressLine = new TextView(this);
|
progressLine = new TextView(this);
|
||||||
progressLine.setVisibility(View.GONE);
|
progressLine.setVisibility(View.GONE);
|
||||||
progressLine.setTextAppearance(this, android.R.attr.textAppearanceLarge);
|
progressLine.setTextAppearance(this, android.R.style.TextAppearance_Medium);
|
||||||
launcher.addView( progressLine );
|
progressLayout.addView( progressLine );
|
||||||
launcher.addView(progress);
|
progressLayout.addView(progress);
|
||||||
|
buttons.addView(progressLayout);
|
||||||
|
launcher.addView(buttons);
|
||||||
|
scroll.addView(output);
|
||||||
launcher.addView(scroll);
|
launcher.addView(scroll);
|
||||||
setContentView(launcher);
|
setContentView(launcher);
|
||||||
try
|
try
|
||||||
|
@ -158,6 +163,7 @@ public class SteamActivity extends Activity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.setCancelable(false)
|
||||||
.show();
|
.show();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -184,7 +190,7 @@ public class SteamActivity extends Activity {
|
||||||
TextView line = new TextView(SteamActivity.this);
|
TextView line = new TextView(SteamActivity.this);
|
||||||
line.setText(str);
|
line.setText(str);
|
||||||
|
|
||||||
line.setTextAppearance(SteamActivity.this, android.R.attr.textAppearanceSmall);
|
line.setTextAppearance(SteamActivity.this, android.R.style.TextAppearance_Small);
|
||||||
line.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
|
line.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
|
||||||
progress.setVisibility(View.GONE);
|
progress.setVisibility(View.GONE);
|
||||||
progressLine.setVisibility(View.GONE);
|
progressLine.setVisibility(View.GONE);
|
||||||
|
|
|
@ -21,18 +21,18 @@ enum ProcessState{ UNPACK, LAUNCH, COMMAND, WAIT, DOWNLOAD };
|
||||||
|
|
||||||
public class SteamService extends Service
|
public class SteamService extends Service
|
||||||
{
|
{
|
||||||
final String TAG = "SteamService";
|
final static String TAG = "SteamService";
|
||||||
public static SteamService mSingleton;
|
public static SteamService mSingleton;
|
||||||
Notification notification;
|
private Notification notification;
|
||||||
NotificationManager notificationManager = null;
|
private NotificationManager notificationManager = null;
|
||||||
String localPath;
|
private String localPath;
|
||||||
String filesDir;
|
private String filesDir;
|
||||||
class RestartException extends Exception {};
|
class RestartException extends Exception {};
|
||||||
class CancelException extends Exception {};
|
class CancelException extends Exception {};
|
||||||
|
|
||||||
|
|
||||||
static BackgroundThread mBgThread;
|
static BackgroundThread mBgThread;
|
||||||
SharedPreferences mPref;
|
private SharedPreferences mPref;
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
mSingleton = this;
|
mSingleton = this;
|
||||||
|
@ -48,7 +48,7 @@ public class SteamService extends Service
|
||||||
Log.d(TAG, "onCreate");
|
Log.d(TAG, "onCreate");
|
||||||
}
|
}
|
||||||
|
|
||||||
void notificationInit()
|
private void notificationInit()
|
||||||
{
|
{
|
||||||
// init notification and foreground service
|
// init notification and foreground service
|
||||||
Intent intent = new Intent(this, SteamActivity.class);
|
Intent intent = new Intent(this, SteamActivity.class);
|
||||||
|
@ -71,7 +71,7 @@ public class SteamService extends Service
|
||||||
|
|
||||||
// Dont create too much notification intents, it may crash system
|
// Dont create too much notification intents, it may crash system
|
||||||
long lastNotify = 0;
|
long lastNotify = 0;
|
||||||
void progressUpdate( String text, int progress) {
|
private void progressUpdate( String text, int progress) {
|
||||||
if( SteamActivity.mSingleton != null )
|
if( SteamActivity.mSingleton != null )
|
||||||
SteamActivity.mSingleton.progressUpdate( text, progress );
|
SteamActivity.mSingleton.progressUpdate( text, progress );
|
||||||
if( notification == null )
|
if( notification == null )
|
||||||
|
@ -142,7 +142,7 @@ public class SteamService extends Service
|
||||||
Log.d(TAG, "onBind");
|
Log.d(TAG, "onBind");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
void printText(String text)
|
private void printText(String text)
|
||||||
{
|
{
|
||||||
// register notification first
|
// register notification first
|
||||||
if( notification == null )
|
if( notification == null )
|
||||||
|
@ -169,7 +169,7 @@ public class SteamService extends Service
|
||||||
}
|
}
|
||||||
|
|
||||||
// block current thread and show dialog
|
// block current thread and show dialog
|
||||||
String promptDialog(String title, String message, boolean passwd)
|
private String promptDialog(String title, String message, boolean passwd)
|
||||||
{
|
{
|
||||||
Intent intent = new Intent(this, SteamActivity.class);
|
Intent intent = new Intent(this, SteamActivity.class);
|
||||||
final PendingIntent pendingIntent = PendingIntent.getActivity(
|
final PendingIntent pendingIntent = PendingIntent.getActivity(
|
||||||
|
@ -304,7 +304,7 @@ public class SteamService extends Service
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void waitForActivity()
|
private void waitForActivity()
|
||||||
{
|
{
|
||||||
if( SteamActivity.mSingleton != null )
|
if( SteamActivity.mSingleton != null )
|
||||||
// Nothing to wait
|
// Nothing to wait
|
||||||
|
@ -327,13 +327,14 @@ public class SteamService extends Service
|
||||||
OutputStream processInput = null;
|
OutputStream processInput = null;
|
||||||
|
|
||||||
ProcessState state;;
|
ProcessState state;;
|
||||||
boolean need_reset_config = false;
|
private boolean need_reset_config = false;
|
||||||
boolean skipQemu = false;
|
private boolean skipQemu = false;
|
||||||
String lastID;
|
private String lastID;
|
||||||
Process process;
|
public Process process;
|
||||||
AtomicBoolean needDestroy = new AtomicBoolean();
|
public AtomicBoolean needDestroy = new AtomicBoolean();
|
||||||
|
public InputStream httpInput = null;
|
||||||
|
|
||||||
void downloadFile( String strurl, String path ) throws IOException, CancelException
|
private void downloadFile( String strurl, String path ) throws IOException, CancelException
|
||||||
{
|
{
|
||||||
URL url = new URL(strurl);
|
URL url = new URL(strurl);
|
||||||
int count;
|
int count;
|
||||||
|
@ -347,7 +348,7 @@ public class SteamService extends Service
|
||||||
int lenghtOfFile = conection.getContentLength();
|
int lenghtOfFile = conection.getContentLength();
|
||||||
|
|
||||||
// download the file
|
// download the file
|
||||||
InputStream input = new BufferedInputStream(url.openStream(), 8192);
|
httpInput = new BufferedInputStream(url.openStream(), 8192);
|
||||||
|
|
||||||
// Output stream
|
// Output stream
|
||||||
OutputStream output = new FileOutputStream(path);
|
OutputStream output = new FileOutputStream(path);
|
||||||
|
@ -357,7 +358,7 @@ public class SteamService extends Service
|
||||||
long total = 0;
|
long total = 0;
|
||||||
int lastprogress = 0;
|
int lastprogress = 0;
|
||||||
|
|
||||||
while ( !needDestroy.get() && (count = input.read(data)) != -1) {
|
while ( !needDestroy.get() && (count = httpInput.read(data)) != -1) {
|
||||||
total += count;
|
total += count;
|
||||||
// publishing the progress....
|
// publishing the progress....
|
||||||
try
|
try
|
||||||
|
@ -376,13 +377,14 @@ public class SteamService extends Service
|
||||||
|
|
||||||
// closing streams
|
// closing streams
|
||||||
output.close();
|
output.close();
|
||||||
input.close();
|
httpInput.close();
|
||||||
|
httpInput = null;
|
||||||
if(needDestroy.get())
|
if(needDestroy.get())
|
||||||
throw new CancelException();
|
throw new CancelException();
|
||||||
}
|
}
|
||||||
|
|
||||||
// called on every line, encef with \n
|
// called on every line, encef with \n
|
||||||
void processLine( String str ) throws RestartException,IOException
|
private void processLine( String str ) throws RestartException,IOException
|
||||||
{
|
{
|
||||||
// downloading game
|
// downloading game
|
||||||
if( str.startsWith( " Update state (") )
|
if( str.startsWith( " Update state (") )
|
||||||
|
@ -476,7 +478,7 @@ public class SteamService extends Service
|
||||||
}
|
}
|
||||||
|
|
||||||
// called on every char in line until return true
|
// called on every char in line until return true
|
||||||
boolean processPartial( String str ) throws CancelException, IOException
|
private boolean processPartial( String str ) throws CancelException, IOException
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
if( str.contains( "Steam>" ) )
|
if( str.contains( "Steam>" ) )
|
||||||
|
@ -544,7 +546,7 @@ public class SteamService extends Service
|
||||||
}
|
}
|
||||||
|
|
||||||
// launch procesc and process all outout
|
// launch procesc and process all outout
|
||||||
int launchProcess( String command ) throws Exception
|
private int launchProcess( String command ) throws Exception
|
||||||
{
|
{
|
||||||
int result = 255;
|
int result = 255;
|
||||||
printText("process start: " + command);
|
printText("process start: " + command);
|
||||||
|
@ -603,7 +605,7 @@ public class SteamService extends Service
|
||||||
}
|
}
|
||||||
|
|
||||||
// download all files if not yet downloaded
|
// download all files if not yet downloaded
|
||||||
void downloadAll() throws IOException,CancelException
|
private void downloadAll() throws IOException,CancelException
|
||||||
{
|
{
|
||||||
if( !skipQemu && !new File( filesDir + "/qemu.downloaded").exists() )
|
if( !skipQemu && !new File( filesDir + "/qemu.downloaded").exists() )
|
||||||
{
|
{
|
||||||
|
@ -643,18 +645,18 @@ public class SteamService extends Service
|
||||||
|
|
||||||
new File( localPath + ".downloaded").createNewFile();
|
new File( localPath + ".downloaded").createNewFile();
|
||||||
}
|
}
|
||||||
int launchX86(String command) throws Exception
|
private int launchX86(String command) throws Exception
|
||||||
{
|
{
|
||||||
if( skipQemu )
|
if( skipQemu )
|
||||||
return launchProcess( "sh " + localPath + "start-x86.sh " + localPath + ' ' + command );
|
return launchProcess( "sh " + localPath + "start-x86.sh " + localPath + ' ' + command );
|
||||||
else
|
else
|
||||||
return launchProcess( "sh " + localPath + "start-qemu.sh " + localPath + " "+ filesDir + "/qemu " + command );
|
return launchProcess( "sh " + localPath + "start-qemu.sh " + localPath + " "+ filesDir + "/qemu " + command );
|
||||||
}
|
}
|
||||||
void unpackAll() throws Exception
|
private void unpackAll() throws Exception
|
||||||
{
|
{
|
||||||
|
launchProcess( "chmod 777 " + filesDir + "/qemu" );
|
||||||
if( new File( localPath + ".unpacked").exists() )
|
if( new File( localPath + ".unpacked").exists() )
|
||||||
return;
|
return;
|
||||||
launchProcess( "chmod 777 " + filesDir + "/qemu" );
|
|
||||||
launchX86( localPath + "gzip -d steamcmd_linux.tar.gz" );
|
launchX86( localPath + "gzip -d steamcmd_linux.tar.gz" );
|
||||||
launchX86( localPath + "tar xvf steamcmd_linux.tar" );
|
launchX86( localPath + "tar xvf steamcmd_linux.tar" );
|
||||||
new File( localPath + "steamcmd_linux.tar" ).delete();
|
new File( localPath + "steamcmd_linux.tar" ).delete();
|
||||||
|
@ -664,9 +666,9 @@ public class SteamService extends Service
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
super.run();
|
super.run();
|
||||||
needDestroy = new AtomicBoolean(false);
|
needDestroy.getAndSet(false);
|
||||||
try {
|
try {
|
||||||
if( skipQemu = (System.getProperty("ro.product.cpu.abi") == "x86") )
|
if( skipQemu = isX86() )
|
||||||
localPath = filesDir + '/';
|
localPath = filesDir + '/';
|
||||||
state = ProcessState.UNPACK;
|
state = ProcessState.UNPACK;
|
||||||
downloadAll();
|
downloadAll();
|
||||||
|
@ -689,6 +691,7 @@ public class SteamService extends Service
|
||||||
// 42 is restart magick in steam
|
// 42 is restart magick in steam
|
||||||
result = 42;
|
result = 42;
|
||||||
}
|
}
|
||||||
|
needDestroy.getAndSet(false);
|
||||||
}
|
}
|
||||||
while( result == 42 || getVerify() != null || getDownload() != null ) ;
|
while( result == 42 || getVerify() != null || getDownload() != null ) ;
|
||||||
|
|
||||||
|
@ -730,16 +733,48 @@ public class SteamService extends Service
|
||||||
mBgThread.needDestroy.getAndSet(true);
|
mBgThread.needDestroy.getAndSet(true);
|
||||||
mBgThread.interrupt();
|
mBgThread.interrupt();
|
||||||
// destroy process
|
// destroy process
|
||||||
mBgThread.process.destroy();
|
if( mBgThread.process != null )
|
||||||
|
mBgThread.process.destroy();
|
||||||
|
// cancel stalled download
|
||||||
|
if( mBgThread.httpInput != null )
|
||||||
|
mBgThread.httpInput.close();
|
||||||
}catch( Exception e ){
|
}catch( Exception e ){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private boolean isX86()
|
||||||
|
{
|
||||||
|
String s = System.getProperty("ro.product.cpu.abi");
|
||||||
|
|
||||||
|
if( s != null && s.contains("x86"))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
s = System.getProperty("ro.product.cpu.abi2");
|
||||||
|
|
||||||
|
if( s != null && s.contains("x86"))
|
||||||
|
return true;
|
||||||
|
s = System.getProperty("ro.product.cpu.abilist");
|
||||||
|
|
||||||
|
if( s != null && s.contains("x86"))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
s = System.getProperty("ro.product.cpu.abilist32");
|
||||||
|
|
||||||
|
if( s != null && s.contains("x86"))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
s = System.getProperty("ro.dalvik.vm.isa.arm");
|
||||||
|
|
||||||
|
if( s != null && s.contains("x86"))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
public void silentKillAll()
|
public void silentKillAll()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if( System.getProperty("ro.product.cpu.abi") == "x86" )
|
if( isX86() )
|
||||||
Runtime.getRuntime().exec( "sh " + localPath + "start-x86.sh " + localPath + ' ' +
|
Runtime.getRuntime().exec( "sh " + localPath + "start-x86.sh " + localPath + ' ' +
|
||||||
localPath + "killall -o5s -9 ld-linux.so.2" );
|
localPath + "killall -o5s -9 ld-linux.so.2" );
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Reference in a new issue