SDL: better logs when loading library

This commit is contained in:
Sergii Pylypenko
2019-04-25 18:41:09 +03:00
parent f78c911f0a
commit 3bed7f054e

View File

@@ -1197,118 +1197,33 @@ public class MainActivity extends Activity
{
String libname = System.mapLibraryName(l);
File libpath = new File(getFilesDir().getAbsolutePath() + "/../lib/" + libname);
Log.i("SDL", "libSDL: loading lib " + libpath.getAbsolutePath());
//Log.i("SDL", "libSDL: loading lib " + libpath.getAbsolutePath());
System.load(libpath.getPath());
Log.i("SDL", "libSDL: loaded lib " + libpath.getAbsolutePath());
}
catch( UnsatisfiedLinkError e )
{
Log.i("SDL", "libSDL: error loading lib " + l + ": " + e.toString());
//Log.i("SDL", "libSDL: error loading lib " + l + ": " + e.toString());
try
{
String libname = System.mapLibraryName(l);
File libpath = new File(getFilesDir().getAbsolutePath() + "/" + libname);
Log.i("SDL", "libSDL: loading lib " + libpath.getAbsolutePath());
//Log.i("SDL", "libSDL: loading lib " + libpath.getAbsolutePath());
System.load(libpath.getPath());
Log.i("SDL", "libSDL: loaded lib " + libpath.getAbsolutePath());
}
catch( UnsatisfiedLinkError ee )
{
Log.i("SDL", "libSDL: error loading lib " + l + ": " + ee.toString());
//Log.i("SDL", "libSDL: error loading lib " + l + ": " + ee.toString());
System.loadLibrary(l);
Log.i("SDL", "libSDL: loaded lib " + l + " from app lib path");
Log.i("SDL", "libSDL: loaded lib " + l + " from System.loadLibrary(l)");
}
}
}
}
catch ( UnsatisfiedLinkError e )
{
try {
Log.i("SDL", "libSDL: Extracting APP2SD-ed libs");
InputStream in = null;
try
{
for( int i = 0; ; i++ )
{
InputStream in2 = getAssets().open("bindata" + String.valueOf(i));
if( in == null )
in = in2;
else
in = new SequenceInputStream( in, in2 );
}
}
catch( IOException ee ) { }
if( in == null )
throw new RuntimeException("libSDL: Extracting APP2SD-ed libs failed, the .apk file packaged incorrectly");
ZipInputStream zip = new ZipInputStream(in);
File libDir = getFilesDir();
try {
libDir.mkdirs();
} catch( SecurityException ee ) { };
byte[] buf = new byte[16384];
while(true)
{
ZipEntry entry = null;
entry = zip.getNextEntry();
/*
if( entry != null )
Log.i("SDL", "Extracting lib " + entry.getName());
*/
if( entry == null )
{
Log.i("SDL", "Extracting libs finished");
break;
}
if( entry.isDirectory() )
{
File outDir = new File( libDir.getAbsolutePath() + "/" + entry.getName() );
if( !(outDir.exists() && outDir.isDirectory()) )
outDir.mkdirs();
continue;
}
OutputStream out = null;
String path = libDir.getAbsolutePath() + "/" + entry.getName();
try {
File outDir = new File( path.substring(0, path.lastIndexOf("/") ));
if( !(outDir.exists() && outDir.isDirectory()) )
outDir.mkdirs();
} catch( SecurityException eeeee ) { };
Log.i("SDL", "Saving to file '" + path + "'");
out = new FileOutputStream( path );
int len = zip.read(buf);
while (len >= 0)
{
if(len > 0)
out.write(buf, 0, len);
len = zip.read(buf);
}
out.flush();
out.close();
}
for(String l_unmapped : Globals.AppLibraries)
{
String l = GetMappedLibraryName(l_unmapped);
String libname = System.mapLibraryName(l);
File libpath = new File(libDir, libname);
Log.i("SDL", "libSDL: loading lib " + libpath.getPath());
System.load(libpath.getPath());
libpath.delete();
}
}
catch ( Exception ee )
{
Log.i("SDL", "libSDL: Error: " + ee.toString());
}
Log.i("SDL", "libSDL: Error: " + e.toString());
}
ZipFile myApk = null;