diff --git a/app/src/main/java/org/emunix/unipatcher/Action.java b/app/src/main/java/org/emunix/unipatcher/Action.java new file mode 100644 index 0000000..00be808 --- /dev/null +++ b/app/src/main/java/org/emunix/unipatcher/Action.java @@ -0,0 +1,35 @@ +/* + Copyright (c) 2017 Boris Timofeev + + This file is part of UniPatcher. + + UniPatcher is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + UniPatcher is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with UniPatcher. If not, see . + + */ + +package org.emunix.unipatcher; + +public class Action { + public static final int SELECT_ROM_FILE = 1; + public static final int SELECT_PATCH_FILE = 2; + public static final int SELECT_SOURCE_FILE = 3; + public static final int SELECT_MODIFIED_FILE = 4; + public static final int SELECT_HEADER_FILE = 5; + + public static final int APPLY_PATCH = 101; + public static final int CREATE_PATCH = 102; + public static final int SMD_FIX_CHECKSUM = 103; + public static final int SNES_ADD_SMC_HEADER = 104; + public static final int SNES_DELETE_SMC_HEADER = 105; +} diff --git a/app/src/main/java/org/emunix/unipatcher/Globals.java b/app/src/main/java/org/emunix/unipatcher/Globals.java index 35a37f0..fc74bc2 100644 --- a/app/src/main/java/org/emunix/unipatcher/Globals.java +++ b/app/src/main/java/org/emunix/unipatcher/Globals.java @@ -29,10 +29,4 @@ public class Globals { public static void setCmdArgument(String cmdArgument) { Globals.cmdArgument = cmdArgument; } - - public static final int ACTION_PATCHING = 1; - public static final int ACTION_CREATE_PATCH = 2; - public static final int ACTION_SMD_FIX_CHECKSUM = 3; - public static final int ACTION_SNES_ADD_SMC_HEADER = 4; - public static final int ACTION_SNES_DELETE_SMC_HEADER = 5; } diff --git a/app/src/main/java/org/emunix/unipatcher/WorkerService.java b/app/src/main/java/org/emunix/unipatcher/WorkerService.java index d0be9ac..d77a770 100644 --- a/app/src/main/java/org/emunix/unipatcher/WorkerService.java +++ b/app/src/main/java/org/emunix/unipatcher/WorkerService.java @@ -75,19 +75,19 @@ public class WorkerService extends IntentService { try { int action = intent.getIntExtra("action", 0); switch (action) { - case Globals.ACTION_PATCHING: + case Action.APPLY_PATCH: actionPatching(intent); break; - case Globals.ACTION_CREATE_PATCH: + case Action.CREATE_PATCH: actionCreatePatch(intent); break; - case Globals.ACTION_SMD_FIX_CHECKSUM: + case Action.SMD_FIX_CHECKSUM: actionSmdFixChecksum(intent); break; - case Globals.ACTION_SNES_ADD_SMC_HEADER: + case Action.SNES_ADD_SMC_HEADER: actionSnesAddSmcHeader(intent); break; - case Globals.ACTION_SNES_DELETE_SMC_HEADER: + case Action.SNES_DELETE_SMC_HEADER: actionSnesDeleteSmcHeader(intent); break; } diff --git a/app/src/main/java/org/emunix/unipatcher/ui/fragment/CreatePatchFragment.java b/app/src/main/java/org/emunix/unipatcher/ui/fragment/CreatePatchFragment.java index 6181e0f..b3c90e9 100644 --- a/app/src/main/java/org/emunix/unipatcher/ui/fragment/CreatePatchFragment.java +++ b/app/src/main/java/org/emunix/unipatcher/ui/fragment/CreatePatchFragment.java @@ -37,7 +37,7 @@ import android.widget.TextView; import android.widget.Toast; import org.apache.commons.io.FilenameUtils; -import org.emunix.unipatcher.Globals; +import org.emunix.unipatcher.Action; import org.emunix.unipatcher.R; import org.emunix.unipatcher.Settings; import org.emunix.unipatcher.Utils; @@ -50,8 +50,6 @@ public class CreatePatchFragment extends ActionFragment implements View.OnClickL private static final String LOG_TAG = "org.emunix.unipatcher"; - private static final int SELECT_SOURCE_FILE = 1; - private static final int SELECT_MODIFIED_FILE = 2; private TextView sourceNameTextView; private TextView modifiedNameTextView; private TextView patchNameTextView; @@ -136,12 +134,12 @@ public class CreatePatchFragment extends ActionFragment implements View.OnClickL case R.id.sourceFileCardView: intent.putExtra("title", getString(R.string.file_picker_activity_title_select_source_file)); intent.putExtra("directory", Settings.getRomDir(getActivity())); - startActivityForResult(intent, SELECT_SOURCE_FILE); + startActivityForResult(intent, Action.SELECT_SOURCE_FILE); break; case R.id.modifiedFileCardView: intent.putExtra("title", getString(R.string.file_picker_activity_title_select_modified_file)); intent.putExtra("directory", Settings.getRomDir(getActivity())); - startActivityForResult(intent, SELECT_MODIFIED_FILE); + startActivityForResult(intent, Action.SELECT_MODIFIED_FILE); break; case R.id.patchFileCardView: renamePatchFile(); @@ -157,13 +155,13 @@ public class CreatePatchFragment extends ActionFragment implements View.OnClickL File fpath = new File(path); switch (requestCode) { - case SELECT_SOURCE_FILE: + case Action.SELECT_SOURCE_FILE: sourcePath = path; sourceNameTextView.setVisibility(View.VISIBLE); sourceNameTextView.setText(fpath.getName()); Settings.setLastRomDir(getActivity(), fpath.getParent()); break; - case SELECT_MODIFIED_FILE: + case Action.SELECT_MODIFIED_FILE: modifiedPath = path; modifiedNameTextView.setVisibility(View.VISIBLE); modifiedNameTextView.setText(fpath.getName()); @@ -198,7 +196,7 @@ public class CreatePatchFragment extends ActionFragment implements View.OnClickL } Intent intent = new Intent(getActivity(), WorkerService.class); - intent.putExtra("action", Globals.ACTION_CREATE_PATCH); + intent.putExtra("action", Action.CREATE_PATCH); intent.putExtra("sourcePath", sourcePath); intent.putExtra("modifiedPath", modifiedPath); intent.putExtra("patchPath", patchPath); diff --git a/app/src/main/java/org/emunix/unipatcher/ui/fragment/PatchingFragment.java b/app/src/main/java/org/emunix/unipatcher/ui/fragment/PatchingFragment.java index b486499..4f621d6 100644 --- a/app/src/main/java/org/emunix/unipatcher/ui/fragment/PatchingFragment.java +++ b/app/src/main/java/org/emunix/unipatcher/ui/fragment/PatchingFragment.java @@ -36,6 +36,7 @@ import android.widget.TextView; import android.widget.Toast; import org.apache.commons.io.FilenameUtils; +import org.emunix.unipatcher.Action; import org.emunix.unipatcher.Globals; import org.emunix.unipatcher.R; import org.emunix.unipatcher.Settings; @@ -49,8 +50,6 @@ public class PatchingFragment extends ActionFragment implements View.OnClickList private static final String LOG_TAG = "org.emunix.unipatcher"; - private static final int SELECT_ROM_FILE = 1; - private static final int SELECT_PATCH_FILE = 2; private TextView romNameTextView; private TextView patchNameTextView; private TextView outputNameTextView; @@ -147,12 +146,12 @@ public class PatchingFragment extends ActionFragment implements View.OnClickList case R.id.patchCardView: intent.putExtra("title", getString(R.string.file_picker_activity_title_select_patch)); intent.putExtra("directory", Settings.getPatchDir(getActivity())); - startActivityForResult(intent, SELECT_PATCH_FILE); + startActivityForResult(intent, Action.SELECT_PATCH_FILE); break; case R.id.romCardView: intent.putExtra("title", getString(R.string.file_picker_activity_title_select_rom)); intent.putExtra("directory", Settings.getRomDir(getActivity())); - startActivityForResult(intent, SELECT_ROM_FILE); + startActivityForResult(intent, Action.SELECT_ROM_FILE); break; case R.id.outputCardView: renameOutputRom(); @@ -172,7 +171,7 @@ public class PatchingFragment extends ActionFragment implements View.OnClickList } switch (requestCode) { - case SELECT_ROM_FILE: + case Action.SELECT_ROM_FILE: romPath = path; romNameTextView.setVisibility(View.VISIBLE); romNameTextView.setText(fpath.getName()); @@ -180,7 +179,7 @@ public class PatchingFragment extends ActionFragment implements View.OnClickList outputPath = makeOutputPath(path); outputNameTextView.setText(new File(outputPath).getName()); break; - case SELECT_PATCH_FILE: + case Action.SELECT_PATCH_FILE: patchPath = path; patchNameTextView.setVisibility(View.VISIBLE); patchNameTextView.setText(fpath.getName()); @@ -214,7 +213,7 @@ public class PatchingFragment extends ActionFragment implements View.OnClickList } Intent intent = new Intent(getActivity(), WorkerService.class); - intent.putExtra("action", Globals.ACTION_PATCHING); + intent.putExtra("action", Action.APPLY_PATCH); intent.putExtra("romPath", romPath); intent.putExtra("patchPath", patchPath); intent.putExtra("outputPath", outputPath); diff --git a/app/src/main/java/org/emunix/unipatcher/ui/fragment/SmdFixChecksumFragment.java b/app/src/main/java/org/emunix/unipatcher/ui/fragment/SmdFixChecksumFragment.java index 43b241f..c97a8a0 100644 --- a/app/src/main/java/org/emunix/unipatcher/ui/fragment/SmdFixChecksumFragment.java +++ b/app/src/main/java/org/emunix/unipatcher/ui/fragment/SmdFixChecksumFragment.java @@ -31,7 +31,7 @@ import android.view.ViewGroup; import android.widget.TextView; import android.widget.Toast; -import org.emunix.unipatcher.Globals; +import org.emunix.unipatcher.Action; import org.emunix.unipatcher.R; import org.emunix.unipatcher.Settings; import org.emunix.unipatcher.Utils; @@ -43,7 +43,6 @@ import java.io.File; public class SmdFixChecksumFragment extends ActionFragment implements View.OnClickListener { private static final String LOG_TAG = "org.emunix.unipatcher"; - private static final int SELECT_ROM_FILE = 1; private TextView romNameTextView; private TextView fixChecksumInfoTextview; @@ -108,7 +107,7 @@ public class SmdFixChecksumFragment extends ActionFragment implements View.OnCli case R.id.romCardView: intent.putExtra("title", getString(R.string.file_picker_activity_title_select_rom)); intent.putExtra("directory", Settings.getRomDir(getActivity())); - startActivityForResult(intent, SELECT_ROM_FILE); + startActivityForResult(intent, Action.SELECT_ROM_FILE); break; } } @@ -124,7 +123,7 @@ public class SmdFixChecksumFragment extends ActionFragment implements View.OnCli } switch (requestCode) { - case SELECT_ROM_FILE: + case Action.SELECT_ROM_FILE: romPath = path; romNameTextView.setVisibility(View.VISIBLE); romNameTextView.setText(new File(path).getName()); @@ -142,8 +141,8 @@ public class SmdFixChecksumFragment extends ActionFragment implements View.OnCli } Intent intent = new Intent(getActivity(), WorkerService.class); - intent.putExtra("action", Globals.ACTION_SMD_FIX_CHECKSUM); intent.putExtra("romPath", romPath); + intent.putExtra("action", Action.SMD_FIX_CHECKSUM); getActivity().startService(intent); Toast.makeText(getActivity(), R.string.notify_smd_fix_checksum_started_check_notify, Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/org/emunix/unipatcher/ui/fragment/SnesSmcHeaderFragment.java b/app/src/main/java/org/emunix/unipatcher/ui/fragment/SnesSmcHeaderFragment.java index 8c918c3..8bfb6c4 100644 --- a/app/src/main/java/org/emunix/unipatcher/ui/fragment/SnesSmcHeaderFragment.java +++ b/app/src/main/java/org/emunix/unipatcher/ui/fragment/SnesSmcHeaderFragment.java @@ -31,7 +31,7 @@ import android.view.ViewGroup; import android.widget.TextView; import android.widget.Toast; -import org.emunix.unipatcher.Globals; +import org.emunix.unipatcher.Action; import org.emunix.unipatcher.R; import org.emunix.unipatcher.Settings; import org.emunix.unipatcher.Utils; @@ -43,8 +43,6 @@ import java.io.File; public class SnesSmcHeaderFragment extends ActionFragment implements View.OnClickListener { private static final String LOG_TAG = "org.emunix.unipatcher"; - private static final int SELECT_ROM_FILE = 1; - private static final int SELECT_HEADER_FILE = 2; private TextView romNameTextView; private TextView headerNameTextView; @@ -104,10 +102,10 @@ public class SnesSmcHeaderFragment extends ActionFragment implements View.OnClic romPath = savedInstanceState.getString("romPath"); headerPath = savedInstanceState.getString("headerPath"); action = savedInstanceState.getInt("action"); - if (action == Globals.ACTION_SNES_ADD_SMC_HEADER) { + if (action == Action.SNES_ADD_SMC_HEADER) { headerInfoTextView.setText(R.string.snes_smc_header_will_be_added); headerCardView.setVisibility(View.VISIBLE); - } else if (action == Globals.ACTION_SNES_DELETE_SMC_HEADER) { + } else if (action == Action.SNES_DELETE_SMC_HEADER) { headerInfoTextView.setText(R.string.snes_smc_header_will_be_removed); headerCardView.setVisibility(View.GONE); } @@ -133,11 +131,11 @@ public class SnesSmcHeaderFragment extends ActionFragment implements View.OnClic case R.id.romCardView: intent.putExtra("title", getString(R.string.file_picker_activity_title_select_rom)); intent.putExtra("directory", Settings.getRomDir(getActivity())); - startActivityForResult(intent, SELECT_ROM_FILE); + startActivityForResult(intent, Action.SELECT_ROM_FILE); break; case R.id.headerCardView: intent.putExtra("title", getString(R.string.file_picker_activity_title_select_header)); - startActivityForResult(intent, SELECT_HEADER_FILE); + startActivityForResult(intent, Action.SELECT_HEADER_FILE); break; } } @@ -153,25 +151,25 @@ public class SnesSmcHeaderFragment extends ActionFragment implements View.OnClic } switch (requestCode) { - case SELECT_ROM_FILE: + case Action.SELECT_ROM_FILE: romPath = path; romNameTextView.setVisibility(View.VISIBLE); romNameTextView.setText(new File(path).getName()); Settings.setLastRomDir(getActivity(), new File(path).getParent()); SnesSmcHeader checker = new SnesSmcHeader(); if (checker.isHasSmcHeader(new File(path))) { - action = Globals.ACTION_SNES_DELETE_SMC_HEADER; + action = Action.SNES_DELETE_SMC_HEADER; headerCardView.setVisibility(View.GONE); headerInfoTextView.setText(R.string.snes_smc_header_will_be_removed); } else { - action = Globals.ACTION_SNES_ADD_SMC_HEADER; + action = Action.SNES_ADD_SMC_HEADER; headerCardView.setVisibility(View.VISIBLE); headerInfoTextView.setText(R.string.snes_smc_header_will_be_added); } headerPath = null; headerNameTextView.setText(R.string.main_activity_tap_to_select); break; - case SELECT_HEADER_FILE: + case Action.SELECT_HEADER_FILE: headerPath = path; headerNameTextView.setText(new File(path).getName()); break; @@ -192,7 +190,7 @@ public class SnesSmcHeaderFragment extends ActionFragment implements View.OnClic intent.putExtra("headerPath", headerPath); getActivity().startService(intent); - if (action == Globals.ACTION_SNES_ADD_SMC_HEADER) { + if (action == Action.SNES_ADD_SMC_HEADER) { Toast.makeText(getActivity(), R.string.notify_snes_add_smc_header_stared_check_noify, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getActivity(), R.string.notify_snes_delete_smc_header_stared_check_noify, Toast.LENGTH_SHORT).show();