Skip to content

Commit 450b532

Browse files
committed
Skip installer dialog when input same as installed app
1 parent d955720 commit 450b532

File tree

3 files changed

+43
-23
lines changed

3 files changed

+43
-23
lines changed

app/src/main/java/ru/woesss/j2me/installer/AppInstaller.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 Yury Kharchenko
2+
* Copyright 2020-2024 Yury Kharchenko
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -59,6 +59,7 @@ public class AppInstaller {
5959
static final int STATUS_NEW = 2;
6060
static final int STATUS_UNMATCHED = 3;
6161
static final int STATUS_SUCCESS = 4;
62+
static final int STATUS_SAME = 5;
6263

6364
private final int id;
6465
private final Application context;
@@ -374,7 +375,22 @@ private int checkDescriptor() {
374375
}
375376
appDirName = currentApp.getPath();
376377
targetDir = new File(Config.getAppDir(), appDirName);
377-
return newDesc.compareVersion(currentApp.getVersion());
378+
int result = newDesc.compareVersion(currentApp.getVersion());
379+
if (result == 0) {
380+
if (srcJar != null && srcJar.exists()) {
381+
File targetJar = new File(targetDir, Config.MIDLET_RES_FILE);
382+
if (targetJar.exists() && targetJar.length() == srcJar.length()) {
383+
try (FileInputStream one = new FileInputStream(srcJar);
384+
FileInputStream two = new FileInputStream(targetJar)) {
385+
if (one.read() != two.read()) {
386+
return STATUS_EQUAL;
387+
}
388+
return STATUS_SAME;
389+
} catch (IOException ignored) {}
390+
}
391+
}
392+
}
393+
return result;
378394
}
379395

380396
private void generatePathName(String name) {

app/src/main/java/ru/woesss/j2me/installer/InstallerDialog.java

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 Yury Kharchenko
2+
* Copyright 2020-2024 Yury Kharchenko
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -240,20 +240,18 @@ private void onProgress(@NonNull Integer status) {
240240
Descriptor nd = installer.getNewDescriptor();
241241
SpannableStringBuilder message;
242242
switch (status) {
243-
case AppInstaller.STATUS_NEW:
243+
case AppInstaller.STATUS_NEW -> {
244244
if (installer.getJar() != null) {
245245
convert();
246246
return;
247247
}
248248
message = nd.getInfo(requireActivity());
249-
break;
250-
case AppInstaller.STATUS_OLDEST:
251-
message = new SpannableStringBuilder(getString(
252-
R.string.reinstall_older,
253-
nd.getVersion(),
254-
installer.getCurrentVersion()));
255-
break;
256-
case AppInstaller.STATUS_EQUAL:
249+
}
250+
case AppInstaller.STATUS_OLDEST -> message = new SpannableStringBuilder(getString(
251+
R.string.reinstall_older,
252+
nd.getVersion(),
253+
installer.getCurrentVersion()));
254+
case AppInstaller.STATUS_EQUAL -> {
257255
message = new SpannableStringBuilder(getString(R.string.reinstall));
258256
AppItem app = installer.getExistsApp();
259257
btnRun.setVisibility(View.VISIBLE);
@@ -263,20 +261,26 @@ private void onProgress(@NonNull Integer status) {
263261
Config.startApp(v.getContext(), app.getTitle(), app.getPathExt(), false);
264262
dismiss();
265263
});
266-
break;
267-
case AppInstaller.STATUS_NEWEST:
268-
message = new SpannableStringBuilder(getString(
269-
R.string.reinstall_newest,
270-
nd.getVersion(),
271-
installer.getCurrentVersion()));
272-
break;
273-
case AppInstaller.STATUS_UNMATCHED:
264+
}
265+
case AppInstaller.STATUS_NEWEST -> message = new SpannableStringBuilder(getString(
266+
R.string.reinstall_newest,
267+
nd.getVersion(),
268+
installer.getCurrentVersion()));
269+
case AppInstaller.STATUS_UNMATCHED -> {
274270
SpannableStringBuilder info = installer.getManifest().getInfo(requireActivity());
275271
info.append(getString(R.string.install_jar_non_matched_jad));
276272
alertConfirm(info, v -> installApp(installer.getJar(), null));
277273
return;
278-
default:
279-
throw new IllegalStateException("Unexpected value: " + status);
274+
}
275+
case AppInstaller.STATUS_SAME -> {
276+
installer.clearCache();
277+
installer.deleteTemp();
278+
AppItem app = installer.getExistsApp();
279+
Config.startApp(getContext(), app.getTitle(), app.getPathExt(), false);
280+
dismiss();
281+
return;
282+
}
283+
default -> throw new IllegalStateException("Unexpected value: " + status);
280284
}
281285
if (installer.getJar() == null) {
282286
message.append('\n').append(getString(R.string.warn_install_from_net));

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<string name="_MINUS_ONE" translatable="false">-1</string>
55
<string name="about">About</string>
66
<string name="about_4pda" translatable="false">&lt;BR>4PDA: &lt;a href="http://4pda.ru/forum/index.php?showtopic=824201">4pda.ru/forum/index.php?showtopic=824201&lt;/a></string>
7-
<string name="about_copyright" translatable="false">\n\nCopyright 2020-2023 Yury Kharchenko</string>
7+
<string name="about_copyright" translatable="false">\n\nCopyright 2020-2024 Yury Kharchenko</string>
88
<string name="about_crowdin" translatable="false">&lt;BR>Crowdin(translation): &lt;a href="https://crowdin.com/project/j2me-loader">crowdin.com/project/j2me-loader&lt;/a></string>
99
<string name="about_email" translatable="false">\n\nEmail: <a href="mailto:j2me.forever@gmail.com">j2me.forever@gmail.com</a>\n</string>
1010
<string name="about_github" translatable="false">\nGithub: <a href="https://github.com/woesss/JL-Mod">woesss/JL-Mod</a>\n</string>

0 commit comments

Comments
 (0)