2222
2323import org .libsdl .app .SDLActivity ;
2424
25- import java .io .InputStream ;
26- import java .io .IOException ;
27- import java .io .OutputStream ;
28- import java .io .File ;
29- import java .io .FileOutputStream ;
30-
3125import android .util .Log ;
3226import android .os .Bundle ;
3327import android .content .Context ;
3428import android .os .Build ;
35- import android .content .pm .PackageManager ;
3629import android .content .pm .ApplicationInfo ;
3730import android .os .PowerManager ;
38- import android .os .PowerManager .*;
31+ import android .os .PowerManager .WakeLock ; // Explicitly import WakeLock if you want to be specific, or keep PowerManager.*
3932import android .view .View ;
4033import android .view .WindowManager ;
41- import android .content .res .*;
42- import android .Manifest ;
43- //msmalik681 added imports for new pak copy!
44- import android .os .Environment ;
45- import android .widget .Toast ;
46- //msmalik681 added import for permission check
47- import androidx .core .content .ContextCompat ;
48- import androidx .core .app .ActivityCompat ;
34+ import android .view .WindowManager ;
4935import android .os .Vibrator ;
5036import android .os .VibrationEffect ;
51- import android .view .*;
5237
53- //needed to fix sdk 34+ crashing
5438import android .content .BroadcastReceiver ;
5539import android .content .Intent ;
5640import android .content .IntentFilter ;
57- import android .os .Build ;
5841import org .jetbrains .annotations .Nullable ;
5942
6043/**
@@ -137,7 +120,7 @@ protected void onCreate(Bundle savedInstanceState) {
137120 super .onCreate (savedInstanceState );
138121 Log .v ("OpenBOR" , "onCreate called" );
139122 //msmalik681 copy pak for custom apk and notify is paks folder empty
140- CopyPak ();
123+ // CopyPak();
141124
142125 //CRxTRDude - Added FLAG_KEEP_SCREEN_ON to prevent screen timeout.
143126 getWindow ().addFlags (WindowManager .LayoutParams .FLAG_KEEP_SCREEN_ON );
@@ -151,102 +134,6 @@ protected void onCreate(Bundle savedInstanceState) {
151134 }
152135 }
153136
154- /**
155- * Proceed in copying paks files, or just prepare the destination Paks directory depending
156- * on which type of app it is.
157- */
158- public void CopyPak ()
159- {
160- try {
161- Context ctx = getContext ();
162- Context appCtx = getApplicationContext ();
163- String toast = null ;
164-
165- // if package name is literally "org.openbor.engine" then we have no need to copy any .pak files
166- if (appCtx .getPackageName ().equals ("org.openbor.engine" ))
167- {
168- // Default output folder
169- File outFolderDefault = new File (Environment .getExternalStorageDirectory () + "/OpenBOR/Paks" );
170-
171- if (!outFolderDefault .isDirectory ())
172- {
173- outFolderDefault .mkdirs ();
174- toast = "Folder: (" + outFolderDefault + ") is empty!" ;
175- Toast .makeText (appCtx , toast , Toast .LENGTH_LONG ).show ();
176- }
177- else
178- {
179- String [] files = outFolderDefault .list ();
180- if (files .length == 0 )
181- {
182- // directory is empty
183- toast = "Paks Folder: (" + outFolderDefault + ") is empty!" ;
184- Toast .makeText (appCtx , toast , Toast .LENGTH_LONG ).show ();
185- }
186- }
187- }
188- // otherwise it acts like a dedicated app (commercial title, standalone app)
189- // intend to work with pre-baked single .pak file at build time
190- else
191- {
192- String version = null ;
193- // versionName is "android:versionName" in AndroidManifest.xml
194- version = appCtx .getPackageManager ().getPackageInfo (appCtx .getPackageName (), 0 ).versionName ; // get version number as string
195- // set local output folder (primary shared/external storage)
196- File outFolder = new File (ctx .getExternalFilesDir (null ) + "/Paks" );
197- // set local output filename as version number
198- File outFile = new File (outFolder , version + ".pak" );
199-
200- // check if existing pak directory is actually directory, and pak file with matching version
201- // for this build is there, if not then delete all files residing in such
202- // directory (old pak files) preparing for updating new one
203- if (outFolder .isDirectory () && !outFile .exists ()) // if local folder true and file does not match version empty folder
204- {
205- toast = "Updating please wait!" ;
206- String [] children = outFolder .list ();
207- for (int i = 0 ; i < children .length ; i ++)
208- {
209- new File (outFolder , children [i ]).delete ();
210- }
211- }
212- else
213- {
214- toast = "First time setup, please wait..." ;
215- }
216-
217- if (!outFile .exists ())
218- {
219- Toast .makeText (appCtx , toast , Toast .LENGTH_LONG ).show ();
220- outFolder .mkdirs ();
221-
222- //custom pak should be saved in "app\src\main\assets\bor.pak"
223- InputStream in = ctx .getAssets ().open ("bor.pak" );
224- FileOutputStream out = new FileOutputStream (outFile );
225-
226- copyFile (in , out );
227- in .close ();
228- in = null ;
229- out .flush ();
230- out .close ();
231- out = null ;
232- }
233- }
234- } catch (IOException e ) {
235- // not handled
236- } catch (Exception e ) {
237- // not handled
238- }
239- }
240-
241- private void copyFile (InputStream in , OutputStream out ) throws IOException {
242- byte [] buffer = new byte [1024 ];
243- int read ;
244- while ((read = in .read (buffer )) != -1 )
245- {
246- out .write (buffer , 0 , read );
247- }
248- }
249-
250137 @ Override
251138 public void onLowMemory () {
252139 super .onLowMemory ();
0 commit comments