pmt: initial 2.8.0 update
This commit is contained in:
37
.github/workflows/build.yml
vendored
37
.github/workflows/build.yml
vendored
@@ -39,26 +39,21 @@ jobs:
|
|||||||
echo "PMT_VERSION=${PMT_VERSION}" >> $GITHUB_ENV
|
echo "PMT_VERSION=${PMT_VERSION}" >> $GITHUB_ENV
|
||||||
echo "PMT_VERSION_CODE=${PMT_VERSION_CODE}" >> $GITHUB_ENV
|
echo "PMT_VERSION_CODE=${PMT_VERSION_CODE}" >> $GITHUB_ENV
|
||||||
echo "NDK_VERSION=${NDK_VERSION}" >> $GITHUB_ENV
|
echo "NDK_VERSION=${NDK_VERSION}" >> $GITHUB_ENV
|
||||||
echo "NDK_LINK=${NDK_LINK}" >> $GITHUB_ENV
|
|
||||||
echo "NDK_IS=${NDK_IS}" >> $GITHUB_ENV
|
|
||||||
cd /home
|
cd /home
|
||||||
sudo git clone https://github.com/ShawkTeam/pmt -b ${PMT_VERSION}
|
sudo git clone https://github.com/ShawkTeam/pmt -b ${PMT_VERSION}
|
||||||
sudo chmod 777 pmt
|
sudo chmod -R 777 pmt
|
||||||
echo "PMT_SRCDIR=/home/pmt" >> $GITHUB_ENV
|
echo "PMT_SRCDIR=/home/pmt" >> $GITHUB_ENV
|
||||||
echo "NDK_DIR=/home/ndk/android-ndk" >> $GITHUB_ENV
|
echo "NDK_DIR=/home/ndk/android-ndk" >> $GITHUB_ENV
|
||||||
echo "NDK_IN_DIR=/home/ndk" >> $GITHUB_ENV
|
|
||||||
sudo mkdir -p "/home/ndk" && cd "/home/ndk" && sudo chmod 777 "/home/ndk"
|
sudo mkdir -p "/home/ndk" && cd "/home/ndk" && sudo chmod 777 "/home/ndk"
|
||||||
|
|
||||||
- name: Download and extract NDK
|
- name: Setup Android NDK
|
||||||
id: setup-ndk
|
id: setup-ndk
|
||||||
run: |
|
uses: nttld/setup-ndk@v1
|
||||||
echo "Downloading NDK ${{ env.NDK_VERSION }}..."
|
with:
|
||||||
aria2c "${{ env.NDK_LINK }}"
|
ndk-version: ${{ env.NDK_VERSION }}
|
||||||
echo "Extracting..."
|
add-to-path: false
|
||||||
unzip -q *.zip && rm *.zip
|
env:
|
||||||
mv * "${{ env.NDK_IS }}"
|
ANDROID_NDK_HOME: ${{ env.NDK_DIR }}
|
||||||
sudo chmod -R 777 *
|
|
||||||
working-directory: ${{ env.NDK_IN_DIR }}
|
|
||||||
|
|
||||||
- name: Build pmt
|
- name: Build pmt
|
||||||
id: build-pmt
|
id: build-pmt
|
||||||
@@ -75,11 +70,11 @@ jobs:
|
|||||||
- name: Last small transactions
|
- name: Last small transactions
|
||||||
id: small-transactions
|
id: small-transactions
|
||||||
run: |
|
run: |
|
||||||
export CC_64="${PWD}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang"
|
export CXX_64="${PWD}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang++"
|
||||||
export CC_32="${PWD}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi21-clang"
|
export CXX_32="${PWD}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi21-clang++"
|
||||||
export AR="${PWD}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar"
|
export AR="${PWD}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar"
|
||||||
export CC_VERSION=$(${CC_64} --version | head -n 1)
|
export CXX_VERSION=$(${CXX_64} --version | head -n 1)
|
||||||
echo "CC_VERSION=${CC_VERSION}" >> $GITHUB_ENV
|
echo "CXX_VERSION=${CXX_VERSION}" >> $GITHUB_ENV
|
||||||
. ${{ env.PMT_SRCDIR }}/build/workflow/build.config
|
. ${{ env.PMT_SRCDIR }}/build/workflow/build.config
|
||||||
. ${{ env.PMT_SRCDIR }}/build/workflow/relnotes > /home/pmt/release_body.txt
|
. ${{ env.PMT_SRCDIR }}/build/workflow/relnotes > /home/pmt/release_body.txt
|
||||||
cd ${{ env.PMT_SRCDIR }}
|
cd ${{ env.PMT_SRCDIR }}
|
||||||
@@ -88,11 +83,11 @@ jobs:
|
|||||||
xz libs/${arch}/pmt
|
xz libs/${arch}/pmt
|
||||||
mv libs/${arch}/pmt.xz ${PWD}/pmt-${arch}-$(date +%Y%m%d).xz
|
mv libs/${arch}/pmt.xz ${PWD}/pmt-${arch}-$(date +%Y%m%d).xz
|
||||||
done
|
done
|
||||||
for CC_COMP in ${CC_64} ${CC_32}; do
|
for CXX_COMP in ${CXX_64} ${CXX_32}; do
|
||||||
make clean
|
make clean
|
||||||
make CC="${CC_COMP}" AR="${AR}" PMT_EXTRA_CFLAGS="-D__NDK_BUILD"
|
make PMT_CXX="${CXX_COMP}" PMT_AR="${AR}" PMT_EXTRA_CFLAGS="-D__NDK_BUILD"
|
||||||
[[ "${CC_COMP}" == *"aarch64"* ]] && make deb FOR_THIS=64
|
[[ "${CXX_COMP}" == *"aarch64"* ]] && make deb FOR_THIS=64
|
||||||
[[ "${CC_COMP}" == *"armv7a"* ]] && make deb FOR_THIS=32
|
[[ "${CXX_COMP}" == *"armv7a"* ]] && make deb FOR_THIS=32
|
||||||
mv out/debpackage/*.deb .
|
mv out/debpackage/*.deb .
|
||||||
make clean
|
make clean
|
||||||
done
|
done
|
||||||
|
|||||||
2
.github/workflows/check_commits.yml
vendored
2
.github/workflows/check_commits.yml
vendored
@@ -14,7 +14,7 @@ jobs:
|
|||||||
id: check-commit-type
|
id: check-commit-type
|
||||||
run: |
|
run: |
|
||||||
echo "BRANCH=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_ENV
|
echo "BRANCH=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_ENV
|
||||||
COMM_MSG=$(git log -1 --pretty=%B)
|
readonly COMM_MSG=$(git log -1 --pretty=%B)
|
||||||
if [ "${GITHUB_EVENT_NAME}" == "push" ]; then
|
if [ "${GITHUB_EVENT_NAME}" == "push" ]; then
|
||||||
if [[ "${COMM_MSG}" == *"initial"* ]]; then
|
if [[ "${COMM_MSG}" == *"initial"* ]]; then
|
||||||
echo "run_builder=true" >> $GITHUB_ENV
|
echo "run_builder=true" >> $GITHUB_ENV
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ On this page, I will tell you how to add languages to pmt. This is not a difficu
|
|||||||
##### Little important notes
|
##### Little important notes
|
||||||
- You don't have to be a professional to do this thing.
|
- You don't have to be a professional to do this thing.
|
||||||
- There will be only one place you need to pay attention to, I will explain it.
|
- There will be only one place you need to pay attention to, I will explain it.
|
||||||
- There is no need to know C.
|
- There is no need to know C/C++.
|
||||||
- You can edit existing translations.
|
- You can edit existing translations.
|
||||||
- You may need ready pmt to understand some things.
|
- You may need ready pmt to understand some things.
|
||||||
- If you are on an x86 PC, you can compile and use it, but the functions will never work.
|
- If you are on an x86 PC, you can compile and use it, but the functions will never work.
|
||||||
@@ -47,7 +47,7 @@ On this page, I will tell you how to add languages to pmt. This is not a difficu
|
|||||||
Try `pmt --help' for more information.
|
Try `pmt --help' for more information.
|
||||||
~ $
|
~ $
|
||||||
|
|
||||||
Code pieces (C)
|
Code pieces (C++)
|
||||||
struct pmt_langdb_general en = {
|
struct pmt_langdb_general en = {
|
||||||
// other translations
|
// other translations
|
||||||
.missing_operand = "missing operand",
|
.missing_operand = "missing operand",
|
||||||
@@ -57,29 +57,31 @@ On this page, I will tell you how to add languages to pmt. This is not a difficu
|
|||||||
}
|
}
|
||||||
|
|
||||||
// pmt code functions [ logging ]
|
// pmt code functions [ logging ]
|
||||||
LOGE("%s\n%s `%s --help' %s.\n, missing_operand, try_h, argv[0], for_more); // LOGE is error logger (pmt). argv[0] = execution name
|
LOGE("%s\n%s `%s --help' %s.\n, missing_operand, try_h, args[0], for_more); // LOGE is error logger (pmt). args[0] = execution name
|
||||||
```
|
```
|
||||||
|
|
||||||
In short, there are variables for texts. And I made these dynamic by using [struct](https://chatgpt.com/share/a798b57c-7e29-4b17-8887-f230414e57bd) method in C. You just need to add translation :)
|
In short, there are variables for texts. And I made these dynamic by using [struct](https://chatgpt.com/share/a798b57c-7e29-4b17-8887-f230414e57bd) method in C (but C++ is being used. And, it didn't change much about that). You just need to add translation :)
|
||||||
|
|
||||||
##### Translating main program texts (relevant part)
|
##### Translating main program texts (relevant part)
|
||||||
|
|
||||||
- Let's open our jni/languages.c source file.
|
- Let's open our jni/Languages.cpp source file.
|
||||||
- Now, let's create the translation with the ready-made struct structure (see jni/include/StringKeys.h for the structure).
|
- Now, let's create the translation with the ready-made struct structure (see include/pmt/StringKeys.h for the structure).
|
||||||
```
|
```
|
||||||
// Main
|
// Main
|
||||||
struct pmt_langdb_general <LANGUAGE_PREFIX> = { // LANGUAGE_PREFIX must be the corresponding abbreviation of the language in English. For example, it's like en in English.
|
struct langdb_general Lang<LANGUAGE_PREFIX> = { // LANGUAGE_PREFIX must be the corresponding abbreviation of the language in English. For example, it's like En in English.
|
||||||
// translations
|
// translations
|
||||||
}
|
}
|
||||||
|
|
||||||
// Example
|
// Example
|
||||||
struct pmt_langdb_general en = {
|
struct langdb_general LangEn = {
|
||||||
// translation
|
// translation
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
- We need to add some information about the language.
|
- We need to add some information about the language.
|
||||||
```
|
```
|
||||||
struct pmt_langdb_general <LANGUAGE_PREFIX> = {
|
VERY IMPORTANT NOTE: You should do your translations from within the function called WCHAR_T!
|
||||||
|
|
||||||
|
struct langdb_general Lang<LANGUAGE_PREFIX> = {
|
||||||
.lang_by_s = // Names of those who made the translation. It's up to you. Do you use & between more than one person?
|
.lang_by_s = // Names of those who made the translation. It's up to you. Do you use & between more than one person?
|
||||||
.language = // Language name. For example English
|
.language = // Language name. For example English
|
||||||
.lang_prefix = // Language prefix. For example en
|
.lang_prefix = // Language prefix. For example en
|
||||||
@@ -87,12 +89,12 @@ In short, there are variables for texts. And I made these dynamic by using [stru
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Example
|
// Example
|
||||||
struct pmt_langdb_general en = {
|
struct langdb_general LangEn = {
|
||||||
.lang_by_s = "YZBruh & r0manas",
|
.lang_by_s = WCHAR_T("YZBruh & r0manas"),
|
||||||
.language = "English",
|
.language = WCHAR_T("English"),
|
||||||
.lang_prefix = "en",
|
.lang_prefix = WCHAR_T("en"),
|
||||||
// other translations
|
// other translations
|
||||||
.by_str = "By" // Example for end translate
|
.by_str = WCHAR_T("By") // Example for end translate
|
||||||
}
|
}
|
||||||
|
|
||||||
// CRITIC WARNING: Do not add ',' to the end of the last translation text. But others always...
|
// CRITIC WARNING: Do not add ',' to the end of the last translation text. But others always...
|
||||||
@@ -102,15 +104,15 @@ In short, there are variables for texts. And I made these dynamic by using [stru
|
|||||||
|
|
||||||
##### Document texts translation (relevant part)
|
##### Document texts translation (relevant part)
|
||||||
|
|
||||||
- Let's open our jni/languages.c source file.
|
- Let's open our jni/Languages.cpp source file.
|
||||||
- Now, let's create the translation with the ready-made struct structure (see jni/include/StringKeys.h for the structure).
|
- Now, let's create the translation with the ready-made struct structure (see include/pmt/StringKeys.h for the structure).
|
||||||
```
|
```
|
||||||
struct pmt_langdb_docs <LANGUAGE_PREFIX>_docs = {
|
struct langdb_docs LangDoc<LANGUAGE_PREFIX> = {
|
||||||
// translations
|
// translations
|
||||||
}
|
}
|
||||||
|
|
||||||
// Example
|
// Example
|
||||||
struct pmt_langdb_docs en_docs = {
|
struct pmt_langdb_docs LangDocEn = {
|
||||||
// translations
|
// translations
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,22 +122,21 @@ In short, there are variables for texts. And I made these dynamic by using [stru
|
|||||||
|
|
||||||
##### General things to do in translation
|
##### General things to do in translation
|
||||||
|
|
||||||
- Open jni/languages.c
|
- Open jni/LanguageTools.cpp
|
||||||
- Go down a bit...
|
|
||||||
```
|
```
|
||||||
struct pmt_langdb_langs lang[] = {
|
string supp_langs[] = {
|
||||||
{"en"},
|
"en",
|
||||||
{"tr"},
|
"tr",
|
||||||
// language prefix. {"<LANGUAGE_PREFIX>"},
|
// language prefix. "<LANGUAGE_PREFIX>",
|
||||||
{NULL} // PLEASE DO NOT ADD IT UNDER 'NULL'!
|
"" // PLEASE DO NOT ADD IT UNDER `""`!
|
||||||
};
|
};
|
||||||
|
|
||||||
// Example
|
// Example
|
||||||
struct pmt_langdb_langs lang[] = {
|
string supp_langs[] = {
|
||||||
{"en"},
|
"en",
|
||||||
{"tr"},
|
"tr",
|
||||||
{"az"},
|
"az",
|
||||||
{NULL}
|
""
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add the language you are translating into these existing language prefixes. I will fix the errors here (if there is an error)
|
// Add the language you are translating into these existing language prefixes. I will fix the errors here (if there is an error)
|
||||||
|
|||||||
17
CHANGELOG.md
17
CHANGELOG.md
@@ -1,10 +1,15 @@
|
|||||||
### Version 2.7.0 Changelog
|
### Version 2.8.0 Changelog
|
||||||
|
|
||||||
- Operation support with pipe (|) operator has been added.
|
- Base switched to C++
|
||||||
- Build system has been made dynamic.
|
- Static libraries deprecated
|
||||||
- Minor changes were made to the layout of bash scripts.
|
- A certain size-change replacement failure problem has been fixed
|
||||||
- Header names have been changed.
|
- Flash problem corrected in sizes under 1KB
|
||||||
|
- Unrelated ones were filtered while logical sections list
|
||||||
|
- Some memory leaks were fixed
|
||||||
|
- More properly code
|
||||||
|
- Some small fixes
|
||||||
|
- Some tiny additions
|
||||||
|
|
||||||
```
|
```
|
||||||
END OF 2.7.0 UPDATE CHANGELOG
|
END OF 2.8.0 UPDATE CHANGELOG
|
||||||
```
|
```
|
||||||
|
|||||||
15
Makefile.inc
15
Makefile.inc
@@ -15,8 +15,8 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
# speficy
|
# speficy
|
||||||
VERSION := 2.7.0
|
VERSION := 2.8.0
|
||||||
VERSION_CODE := 270
|
VERSION_CODE := 280
|
||||||
TARGET := pmt
|
TARGET := pmt
|
||||||
|
|
||||||
# device arch info
|
# device arch info
|
||||||
@@ -51,7 +51,6 @@ endif
|
|||||||
|
|
||||||
BINARY_DIR := $(OUT_DIR)/binary
|
BINARY_DIR := $(OUT_DIR)/binary
|
||||||
PACKAGE_DIR := $(OUT_DIR)/package
|
PACKAGE_DIR := $(OUT_DIR)/package
|
||||||
STATICLIB_DIR := $(OUT_DIR)/static_libs
|
|
||||||
DEB_DIR := $(OUT_DIR)/debpackage
|
DEB_DIR := $(OUT_DIR)/debpackage
|
||||||
TOOLS := $(BUILD)/tools
|
TOOLS := $(BUILD)/tools
|
||||||
UTILS := $(BUILD)/util
|
UTILS := $(BUILD)/util
|
||||||
@@ -79,14 +78,8 @@ ifneq ($(shell basename $(OUT_DIR)),$(OUT_DIRNAME))
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
# sources
|
# sources
|
||||||
SRCS := $(wildcard $(SOURCE_DIR)/*.c)
|
SRCS := $(wildcard $(SOURCE_DIR)/*.cpp)
|
||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.cpp=.o)
|
||||||
|
|
||||||
STATIC_LIBS := \
|
|
||||||
$(TARGET)_root \
|
|
||||||
$(TARGET)_debug \
|
|
||||||
$(TARGET)_listpart \
|
|
||||||
$(TARGET)_partitiontool
|
|
||||||
|
|
||||||
# other directories in the out directory
|
# other directories in the out directory
|
||||||
IN_OUT_DIR := \
|
IN_OUT_DIR := \
|
||||||
|
|||||||
69
README.md
69
README.md
@@ -2,14 +2,14 @@
|
|||||||
|
|
||||||
[](https://github.com/ShawkTeam/pmt/actions/workflows/check_commits.yml)
|
[](https://github.com/ShawkTeam/pmt/actions/workflows/check_commits.yml)
|
||||||
|
|
||||||
This binary, written in C, is for writing/reading and formatting on Android partitions.
|
This binary, written with C++, is for writing/reading and formatting on Android partitions.
|
||||||
|
|
||||||
#### Presented arguments (options)
|
#### Presented arguments (options)
|
||||||
|
|
||||||
```
|
```
|
||||||
Usage: pmt backup PARTITION [OUTPUT] [OPTIONS]...
|
Usage: pmt [OPTIONS] backup PARTITION [OUTPUT] [OPTIONS]...
|
||||||
or: pmt flash PARTITION FILE [OPTIONS]...
|
or: pmt [OPTIONS] flash PARTITION FILE [OPTIONS]...
|
||||||
or: pmt format PARTITION FILE_SYSTEM[ext/2/3/4] [OPTIONS]...
|
or: pmt [OPTIONS] format PARTITION FILE_SYSTEM[ext/2/3/4] [OPTIONS]...
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-l, --logical It is meant to determine whether the target partition is logical.
|
-l, --logical It is meant to determine whether the target partition is logical.
|
||||||
@@ -17,6 +17,7 @@ Options:
|
|||||||
-p, --list List partitions.
|
-p, --list List partitions.
|
||||||
-s, --silent Information and warning messages are silenced in normal work.
|
-s, --silent Information and warning messages are silenced in normal work.
|
||||||
-f, --force Force mode. Some things are ignored.
|
-f, --force Force mode. Some things are ignored.
|
||||||
|
-V, --verbose Verbose mode. Print detailed informations etc.
|
||||||
-S, --set-lang Set current language.
|
-S, --set-lang Set current language.
|
||||||
-v, --version See version.
|
-v, --version See version.
|
||||||
--help See this help message.
|
--help See this help message.
|
||||||
@@ -27,17 +28,17 @@ Examples:
|
|||||||
pmt format system_a ext4 --logical
|
pmt format system_a ext4 --logical
|
||||||
pmt -c /dev/block/platform/bootdevice/by-name --list
|
pmt -c /dev/block/platform/bootdevice/by-name --list
|
||||||
|
|
||||||
Report bugs to <t.me/ShawkTeam | Topics | pmt>
|
Report bugs and suggestions to <t.me/ShawkTeam | Topics | pmt>
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Some notes
|
#### Some notes
|
||||||
|
|
||||||
- pmt supports multiple languages. [See languages.](https://github.com/ShawkTeam/pmt/blob/2.7.0/LANGUAGES.md)
|
- pmt supports multiple languages. [See languages.](https://github.com/ShawkTeam/pmt/blob/2.8.0/LANGUAGES.md)
|
||||||
- [Add language.](https://github.com/ShawkTeam/pmt/blob/2.7.0/ADD-LANGUAGES.md)
|
- [Add language.](https://github.com/ShawkTeam/pmt/blob/2.8.0/ADD-LANGUAGES.md)
|
||||||
- Feel free to ask any questions you want.
|
- Feel free to ask any questions you want.
|
||||||
- Packages are available in publications.
|
- Packages are available in publications.
|
||||||
- If the logical partition flag is not used, a classic partition is tried to be processing by default.
|
- If the logical partition flag is not used, a classic partition is tried to be processing by default.
|
||||||
- [Click to see special version changes.](https://github.com/ShawkTeam/pmt/blob/2.7.0/CHANGELOG.md)
|
- [Click to see special version changes.](https://github.com/ShawkTeam/pmt/blob/2.8.0/CHANGELOG.md)
|
||||||
- We are always open to your suggestions and support (developing)!
|
- We are always open to your suggestions and support (developing)!
|
||||||
|
|
||||||
### How is it built?
|
### How is it built?
|
||||||
@@ -47,13 +48,13 @@ Make or Android NDK is required to build.
|
|||||||
- [Download Android NDK](https://developer.android.com/ndk/downloads) and extract the NDK package.
|
- [Download Android NDK](https://developer.android.com/ndk/downloads) and extract the NDK package.
|
||||||
- Clone this repository. And get access to it.
|
- Clone this repository. And get access to it.
|
||||||
```
|
```
|
||||||
git clone https://github.com/ShawkTeam/pmt -b 2.7.0
|
git clone https://github.com/ShawkTeam/pmt -b 2.8.0
|
||||||
cd pmt
|
cd pmt
|
||||||
```
|
```
|
||||||
- Set the NDK working directory variable.
|
- Set the NDK working directory variable.
|
||||||
```
|
```
|
||||||
make gen-ndk-makefiles
|
make gen-ndk-makefiles
|
||||||
# If you fail the audit, etc., use FORCE_GEN.
|
# If you fail the audit etc, use FORCE_GEN.
|
||||||
# Example:
|
# Example:
|
||||||
make gen-ndk-makefiles FORCE_GEN=true
|
make gen-ndk-makefiles FORCE_GEN=true
|
||||||
|
|
||||||
@@ -89,15 +90,39 @@ cd "${NDK_PROJECT_PATH}" \
|
|||||||
##### Build with Makefiles
|
##### Build with Makefiles
|
||||||
|
|
||||||
```
|
```
|
||||||
|
# Setup environment
|
||||||
|
pkg update \
|
||||||
|
&& pkg upgrade -y \
|
||||||
|
&& pkg install make clang binutils xz-utils -y
|
||||||
|
|
||||||
|
# Start build
|
||||||
make
|
make
|
||||||
|
|
||||||
# To specify clang, just use CC=<clang> next to the command (and same logic in AR)
|
# To specify clang, just use PMT_CXX=<clang++> next to the command (and same logic in AR)
|
||||||
# Example:
|
# Example:
|
||||||
make CC=${PWD}/../toolchain/bin/clang-18
|
make PMT_CXX=${PWD}/../toolchain/bin/clang-18
|
||||||
make AR=${PWD}/../toolchain/bin/ar
|
make PMT_AR=${PWD}/../toolchain/bin/ar
|
||||||
make CC=${PWD}/../toolchain/bin/clang-18 AR=${PWD}/../toolchain/bin/ar
|
make PMT_CXX=${PWD}/../toolchain/bin/clang-18 PMT_AR=${PWD}/../toolchain/bin/ar
|
||||||
|
|
||||||
|
# Speficying extra compiler flags on cmd. Example:
|
||||||
|
make PMT_EXTRA_CXXFLAGS="-O2"
|
||||||
|
|
||||||
# Use termux :D
|
# Use termux :D
|
||||||
|
|
||||||
|
# Cleaning working directory
|
||||||
|
make clean
|
||||||
|
|
||||||
|
# Rebuild
|
||||||
|
make rebuild
|
||||||
|
|
||||||
|
# Install
|
||||||
|
make install
|
||||||
|
|
||||||
|
# Uninstall
|
||||||
|
make uninstall
|
||||||
|
|
||||||
|
# Re-install (install & uninstall)
|
||||||
|
make reinstall
|
||||||
```
|
```
|
||||||
- For the make installable debian package:
|
- For the make installable debian package:
|
||||||
|
|
||||||
@@ -109,6 +134,22 @@ make deb <ARCH_NUM>
|
|||||||
make deb FOR_THIS=32
|
make deb FOR_THIS=32
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### How to use
|
||||||
|
```
|
||||||
|
# Run
|
||||||
|
/system/bin/su
|
||||||
|
```
|
||||||
|
|
||||||
|
- If you have installed the deb package of pmt, installed it with a makefile, or installed it to `$PATH` using any path, just the name of the pmt is enough (or the file name if you did it manually)
|
||||||
|
```
|
||||||
|
pmt <...>
|
||||||
|
```
|
||||||
|
|
||||||
|
- If you have not done this type of institution, pmt is in the directory where you are present you can run with `./`.
|
||||||
|
```
|
||||||
|
./pmt <...> # or whatever the file name is
|
||||||
|
```
|
||||||
|
|
||||||
### Notes
|
### Notes
|
||||||
If you want to change something, take a look at the configuration. You can change him.
|
If you want to change something, take a look at the configuration. You can change him.
|
||||||
it is located in the `build/config` folder. His name is `env.mk`. I gave the information in the file. You can ask more.
|
it is located in the `build/config` folder. His name is `env.mk`. I gave the information in the file. You can ask more.
|
||||||
|
|||||||
@@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
function abort()
|
function abort()
|
||||||
{
|
{
|
||||||
[ -n "${1}" ] \
|
[ -n "${@}" ] \
|
||||||
&& echo -e " - ${RED}${BOLD}Error:${BOLD_RESET}${RESET} ${1}"
|
&& echo -e " - ${RED}${BOLD}Error:${BOLD_RESET}${RESET} ${@}"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,4 +34,4 @@ function gen()
|
|||||||
touch "${1}" || abort "failed to generate: ${1}"
|
touch "${1}" || abort "failed to generate: ${1}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function print() { echo -e "${1}"; }
|
function print() { echo -e "${@}"; }
|
||||||
|
|||||||
@@ -22,13 +22,8 @@
|
|||||||
&& echo "Please set NDK_PROJECT_PATH variable!" \
|
&& echo "Please set NDK_PROJECT_PATH variable!" \
|
||||||
&& exit 1
|
&& exit 1
|
||||||
|
|
||||||
CC_IS="${NDK_ROOT_DIR}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang"
|
CXX_IS="${NDK_ROOT_DIR}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang++"
|
||||||
CC_VERS=$(${CC_IS} --version | head -n 1)
|
CXX_VERS=$(${CXX_IS} --version | head -n 1)
|
||||||
HEADER="${NDK_PROJECT_PATH}/include/pmt/generated/clang-version.h
|
|
||||||
|
|
||||||
mkdir -p "${NDK_PROJECT_PATH}/include/pmt/generated"
|
mkdir -p ${NDK_PROJECT_PATH}/include/pmt/generated
|
||||||
touch "${HEADER}"
|
echo -e "#define __NDK_CXX_VERSION__ \"${CXX_VERS}\"" > ${NDK_PROJECT_PATH}/include/pmt/generated/clang-version.h
|
||||||
echo "/*" >> "${HEADER}"
|
|
||||||
cat "${NDK_PROJECT_PATH}/NOTICE" >> "${HEADER}"
|
|
||||||
echo -e "\n *\n*/" >> "${HEADER}"
|
|
||||||
echo -e "\n\n#define __NDK_CC_VERSION__ \"${CC_VERS}\"" >> "${HEADER}"
|
|
||||||
|
|||||||
@@ -24,29 +24,43 @@ include env.mk
|
|||||||
# #
|
# #
|
||||||
#########################################
|
#########################################
|
||||||
|
|
||||||
CC = clang
|
CXX = clang++
|
||||||
CFLAGS ?= "-O3 -I../include -std=c11 -pedantic -Wall -Wextra -Werror -Wno-nullability-extension -Wno-gnu-zero-variadic-macro-arguments $(PMT_EXTRA_CFLAGS)"
|
AR = ar
|
||||||
|
CXXFLAGS ?= \
|
||||||
|
-O3 \
|
||||||
|
-I../include \
|
||||||
|
-std=c++20 \
|
||||||
|
-Wall \
|
||||||
|
-Wextra \
|
||||||
|
-Werror \
|
||||||
|
-Wno-vla-cxx-extension \
|
||||||
|
-Wno-nullability-completeness \
|
||||||
|
-Wno-writable-strings \
|
||||||
|
-Wno-unused-parameter \
|
||||||
|
-Wno-unused-command-line-argument \
|
||||||
|
-Wno-nullability-extension \
|
||||||
|
-Wno-reorder-init-list \
|
||||||
|
-Wno-gnu-zero-variadic-macro-arguments \
|
||||||
|
$(PMT_EXTRA_CXXFLAGS)
|
||||||
|
|
||||||
# set compiler setting (clang-gcc and ar)
|
# set compiler setting (clang and ar)
|
||||||
ifneq ($(PMT_CC),)
|
ifneq ($(PMT_CXX),)
|
||||||
CC ?= $(PMT_CC)
|
CXX ?= $(PMT_CXX)
|
||||||
else
|
|
||||||
CC ?= clang
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq ($(PMT_AR),)
|
ifneq ($(PMT_AR),)
|
||||||
AR ?= $(PMT_AR)
|
AR ?= $(PMT_AR)
|
||||||
else
|
|
||||||
AR ?= ar
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# compiler flags settings
|
# compiler flags settings
|
||||||
ifneq ($(PMT_ENABLE_DEBUG),)
|
ifeq ($(PMT_ENABLE_DEBUG),true)
|
||||||
CFLAGS += -gdwarf-5 -fsanitize=address
|
CXXFLAGS += \
|
||||||
|
-gdwarf-5 \
|
||||||
|
-fsanitize=address
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# write current env configuration to oldenv.mk
|
# write current env configuration to oldenv.mk
|
||||||
all:
|
all:
|
||||||
@ echo "CC := $(CC)" > oldenv.mk
|
@ echo "CXX := $(CXX)" > oldenv.mk
|
||||||
@ echo "AR := $(AR)" >> oldenv.mk
|
@ echo "AR := $(AR)" >> oldenv.mk
|
||||||
@ echo "CFLAGS := $(CFLAGS)" >> oldenv.mk
|
@ echo "CXXFLAGS := $(CXXFLAGS)" >> oldenv.mk
|
||||||
|
|||||||
@@ -22,17 +22,17 @@
|
|||||||
# #
|
# #
|
||||||
#########################################
|
#########################################
|
||||||
|
|
||||||
# speficy c compiler (cc)
|
# speficy c++ compiler (cxx)
|
||||||
PMT_CC ?=
|
PMT_CXX ?=
|
||||||
|
|
||||||
# speficy ar
|
# speficy ar
|
||||||
PMT_AR ?=
|
PMT_AR ?=
|
||||||
|
|
||||||
# addionital compiler flags
|
# addionital compiler flags
|
||||||
PMT_EXTRA_CFLAGS ?=
|
PMT_EXTRA_CXXFLAGS ?=
|
||||||
|
|
||||||
# debugging mode (binary). it's enabling address sanitizer and source level debug information with dwarf version 5
|
# debugging mode (binary). it's enabling address sanitizer and source level debug information with dwarf version 5
|
||||||
PMT_ENABLE_DEBUG ?=
|
PMT_ENABLE_DEBUG ?= true
|
||||||
|
|
||||||
#########################################
|
#########################################
|
||||||
#########################################
|
#########################################
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
Source: pmt
|
Source: pmt
|
||||||
Package: pmt
|
Package: pmt
|
||||||
Version: 2.6.0
|
Version: 2.8.0
|
||||||
Architecture: arm
|
Architecture: arm
|
||||||
Description: pmt is for reading, writing and formatting partitions of android devices
|
Description: pmt is for reading, writing and formatting partitions of android devices
|
||||||
Section: misc
|
Section: misc
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
Source: pmt
|
Source: pmt
|
||||||
Package: pmt
|
Package: pmt
|
||||||
Version: 2.6.0
|
Version: 2.8.0
|
||||||
Architecture: aarch64
|
Architecture: aarch64
|
||||||
Description: pmt is for reading, writing and formatting partitions of android devices
|
Description: pmt is for reading, writing and formatting partitions of android devices
|
||||||
Section: misc
|
Section: misc
|
||||||
|
|||||||
@@ -62,8 +62,8 @@ prepare:
|
|||||||
@ mkdir $(TEMP_DIR)/DEBIAN
|
@ mkdir $(TEMP_DIR)/DEBIAN
|
||||||
|
|
||||||
check_binary:
|
check_binary:
|
||||||
@ if [ ! -f "$(BINARY_DIR)/pmt" ]; then \
|
@ if [ ! -f "$(BINARY_DIR)/$(TARGET)" ]; then \
|
||||||
$(E_NS) " - pmt not builded! Please build and retry."; \
|
$(E_NS) " - $(TARGET) not builded! Please build and retry."; \
|
||||||
exit 1; \
|
exit 1; \
|
||||||
fi
|
fi
|
||||||
$(E) " - Generating template directory..."
|
$(E) " - Generating template directory..."
|
||||||
|
|||||||
Binary file not shown.
@@ -15,12 +15,25 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
UPDATE_MAKEFILES = false
|
UPDATE_MAKEFILES = false
|
||||||
CLS_ADTS := rm -f $(BUILD)/bash/additional-vars
|
CLS_ADTS := "rm -f $(BUILD)/bash/additional-vars"
|
||||||
|
|
||||||
all:
|
all: getvars
|
||||||
$(MAKE_HIDE) $(SILENT) -C $(BUILD)/config || exit 1
|
$(MAKE_HIDE) $(SILENT) -C $(BUILD)/config $$(cat $(BUILD)/goals.txt) || exit 1
|
||||||
|
@ rm -f $(BUILD)/goals.txt
|
||||||
$(MAKE_HIDE) $(SILENT) -C $(SOURCE_DIRNAME) INC_OLDENV=true || exit 1
|
$(MAKE_HIDE) $(SILENT) -C $(SOURCE_DIRNAME) INC_OLDENV=true || exit 1
|
||||||
|
|
||||||
|
getvars:
|
||||||
|
@ touch $(BUILD)/goals.txt
|
||||||
|
@ $(foreach var,$(sort $(.VARIABLES)),\
|
||||||
|
$(if $(filter command line,$(origin $(var))), \
|
||||||
|
echo "$(var)=$($(var))" >> goals.txt;))
|
||||||
|
|
||||||
|
.PHONY: rebuild
|
||||||
|
rebuild:
|
||||||
|
$(MAKE_HIDE) $(SILENT) clean
|
||||||
|
$(E)
|
||||||
|
$(MAKE_HIDE) $(SILENT)
|
||||||
|
|
||||||
# cleaner functions
|
# cleaner functions
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
@@ -31,9 +44,6 @@ clean:
|
|||||||
@ if [ -d $(PACKAGE_DIR) ]; then \
|
@ if [ -d $(PACKAGE_DIR) ]; then \
|
||||||
$(E_NS) "==> $(OUT_DIRNAME)/`basename $(PACKAGE_DIR)`"; \
|
$(E_NS) "==> $(OUT_DIRNAME)/`basename $(PACKAGE_DIR)`"; \
|
||||||
fi
|
fi
|
||||||
@ if [ -d $(STATICLIB_DIR) ]; then \
|
|
||||||
$(E_NS) "==> $(OUT_DIRNAME)/`basename $(STATICLIB_DIR)`"; \
|
|
||||||
fi
|
|
||||||
@ if [ -d $(DEB_DIR) ]; then \
|
@ if [ -d $(DEB_DIR) ]; then \
|
||||||
$(E_NS) "==> $(OUT_DIRNAME)/`basename $(DEB_DIR)`"; \
|
$(E_NS) "==> $(OUT_DIRNAME)/`basename $(DEB_DIR)`"; \
|
||||||
fi
|
fi
|
||||||
@@ -53,8 +63,10 @@ help:
|
|||||||
$(E) " $(MAKE) ==> Build Partition Manager."
|
$(E) " $(MAKE) ==> Build Partition Manager."
|
||||||
$(E) " $(MAKE) deb ==> Generate debian package for termux."
|
$(E) " $(MAKE) deb ==> Generate debian package for termux."
|
||||||
$(E) " $(MAKE) clean ==> Clear builded binary."
|
$(E) " $(MAKE) clean ==> Clear builded binary."
|
||||||
|
$(E) " $(MAKE) rebuild ==> Re-build Partition Manager (clean and make)."
|
||||||
$(E) " $(MAKE) install ==> It installs $(TARGET) into termux."
|
$(E) " $(MAKE) install ==> It installs $(TARGET) into termux."
|
||||||
$(E) " $(MAKE) uninstall ==> It uninstalls $(TARGET) into termux."
|
$(E) " $(MAKE) uninstall ==> It uninstalls $(TARGET) into termux."
|
||||||
|
$(E) " $(MAKE) reinstall ==> It uninstall and reinstalls $(TARGET)."
|
||||||
$(E) " $(MAKE) gen-makefiles ==> Generate makefiles for build."
|
$(E) " $(MAKE) gen-makefiles ==> Generate makefiles for build."
|
||||||
$(E) " $(MAKE) gen-ndk-makefiles ==> Generate NDK makefiles for build."
|
$(E) " $(MAKE) gen-ndk-makefiles ==> Generate NDK makefiles for build."
|
||||||
$(E) " $(MAKE) clean-makefiles ==> Cleanup makefiles."
|
$(E) " $(MAKE) clean-makefiles ==> Cleanup makefiles."
|
||||||
@@ -67,7 +79,7 @@ help:
|
|||||||
.PHONY: deb
|
.PHONY: deb
|
||||||
deb:
|
deb:
|
||||||
$(MAKE_HIDE) $(SILENT) -C $(DEBUTILS_DIR) -f deb.mk FOR_THIS=$(FOR_THIS) || exit 1
|
$(MAKE_HIDE) $(SILENT) -C $(DEBUTILS_DIR) -f deb.mk FOR_THIS=$(FOR_THIS) || exit 1
|
||||||
$(P) ""
|
@ $(P) ""
|
||||||
|
|
||||||
# install pmt in to termux
|
# install pmt in to termux
|
||||||
.PHONY: install
|
.PHONY: install
|
||||||
@@ -81,6 +93,11 @@ uninstall:
|
|||||||
$(eval PROG := $@)
|
$(eval PROG := $@)
|
||||||
$(MAKE_HIDE) $(SILENT) -C $(OUT_DIRNAME) uninstall PROG=$(PROG) || exit 1
|
$(MAKE_HIDE) $(SILENT) -C $(OUT_DIRNAME) uninstall PROG=$(PROG) || exit 1
|
||||||
|
|
||||||
|
.PHONY: reinstall
|
||||||
|
reinstall:
|
||||||
|
$(MAKE_HIDE) $(SILENT) uninstall
|
||||||
|
$(MAKE_HIDE) $(SILENT) install
|
||||||
|
|
||||||
# clean ndk makefiles
|
# clean ndk makefiles
|
||||||
.PHONY: gen-ndk-makefiles
|
.PHONY: gen-ndk-makefiles
|
||||||
gen-ndk-makefiles:
|
gen-ndk-makefiles:
|
||||||
|
|||||||
@@ -15,84 +15,50 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
########
|
########
|
||||||
# 2.7.0
|
# 2.8.0
|
||||||
########
|
########
|
||||||
|
|
||||||
LOCAL_PATH := $(call my-dir)
|
LOCAL_PATH := $(call my-dir)
|
||||||
|
|
||||||
include $(LOCAL_PATH)/../build/config/env.mk
|
include $(LOCAL_PATH)/../build/config/env.mk
|
||||||
|
|
||||||
PMT_CFLAGS = \
|
PMT_CXXFLAGS = \
|
||||||
-O3 \
|
-O3 \
|
||||||
-std=c11 \
|
-std=c++20 \
|
||||||
-pedantic \
|
|
||||||
-Wall \
|
-Wall \
|
||||||
-Wextra \
|
-Wextra \
|
||||||
-Werror \
|
-Werror \
|
||||||
|
-Wno-vla-cxx-extension \
|
||||||
|
-Wno-nullability-completeness \
|
||||||
|
-Wno-writable-strings \
|
||||||
|
-Wno-unused-parameter \
|
||||||
|
-Wno-unused-command-line-argument \
|
||||||
-Wno-nullability-extension \
|
-Wno-nullability-extension \
|
||||||
|
-Wno-reorder-init-list \
|
||||||
-Wno-gnu-zero-variadic-macro-arguments \
|
-Wno-gnu-zero-variadic-macro-arguments \
|
||||||
-D__NDK_BUILD \
|
-D__NDK_BUILD \
|
||||||
$(EXTRA_COMPILER_FLAGS)
|
$(PMT_EXTRA_CXXFLAGS)
|
||||||
|
|
||||||
ifneq ($(PMT_ENABLE_DEBUG),)
|
ifneq ($(PMT_ENABLE_DEBUG),)
|
||||||
PMT_CFLAGS += -gdwarf-5 -fsanitize=address -fsanitize=undefined
|
PMT_CXXFLAGS += -gdwarf-5 -fsanitize=address
|
||||||
endif
|
endif
|
||||||
|
|
||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
|
|
||||||
LOCAL_MODULE := libpmt_root
|
|
||||||
LOCAL_SRC_FILES := root.c
|
|
||||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include
|
|
||||||
LOCAL_CFLAGS := $(PMT_CFLAGS)
|
|
||||||
|
|
||||||
include $(BUILD_STATIC_LIBRARY)
|
|
||||||
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
LOCAL_MODULE := libpmt_debug
|
|
||||||
LOCAL_SRC_FILES := debug.c
|
|
||||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include
|
|
||||||
LOCAL_CFLAGS := $(PMT_CFLAGS)
|
|
||||||
|
|
||||||
include $(BUILD_STATIC_LIBRARY)
|
|
||||||
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
LOCAL_MODULE := libpmt_partitiontool
|
|
||||||
LOCAL_SRC_FILES := partitiontool.c
|
|
||||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include
|
|
||||||
LOCAL_CFLAGS := $(PMT_CFLAGS)
|
|
||||||
|
|
||||||
include $(BUILD_STATIC_LIBRARY)
|
|
||||||
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
LOCAL_MODULE := libpmt_list
|
|
||||||
LOCAL_SRC_FILES := listpart.c
|
|
||||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include
|
|
||||||
LOCAL_CFLAGS := $(PMT_CFLAGS)
|
|
||||||
|
|
||||||
include $(BUILD_STATIC_LIBRARY)
|
|
||||||
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
LOCAL_MODULE := pmt
|
LOCAL_MODULE := pmt
|
||||||
LOCAL_SRC_FILES := \
|
LOCAL_SRC_FILES := \
|
||||||
pmt.c \
|
Debug.cpp \
|
||||||
version.c \
|
Root.cpp \
|
||||||
get_stat.c \
|
PartitionManager.cpp \
|
||||||
tools.c \
|
PartitionTool.cpp \
|
||||||
lang_tools.c \
|
ListPartitions.cpp \
|
||||||
languages.c \
|
Version.cpp \
|
||||||
help.c
|
GetState.cpp \
|
||||||
|
Tools.cpp \
|
||||||
|
LanguageTools.cpp \
|
||||||
|
Languages.cpp \
|
||||||
|
Help.cpp
|
||||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include
|
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include
|
||||||
LOCAL_STATIC_LIBRARIES := \
|
LOCAL_CFLAGS := $(PMT_CXXFLAGS)
|
||||||
libpmt_root \
|
|
||||||
libpmt_debug \
|
|
||||||
libpmt_partitiontool \
|
|
||||||
libpmt_list
|
|
||||||
LOCAL_CFLAGS := $(PMT_CFLAGS)
|
|
||||||
|
|
||||||
include $(BUILD_EXECUTABLE)
|
include $(BUILD_EXECUTABLE)
|
||||||
|
|
||||||
# end
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
########
|
########
|
||||||
# 2.7.0
|
# 2.8.0
|
||||||
########
|
########
|
||||||
|
|
||||||
# architecture
|
# architecture
|
||||||
|
|||||||
@@ -68,7 +68,8 @@ install_binary:
|
|||||||
fi; \
|
fi; \
|
||||||
$(P) " - Success.\n\n"; \
|
$(P) " - Success.\n\n"; \
|
||||||
$(E_NS) "INSTALL_SUCCESS := true" > $(BUILD)/config/INS_STAT.mk; \
|
$(E_NS) "INSTALL_SUCCESS := true" > $(BUILD)/config/INS_STAT.mk; \
|
||||||
$(E_NS) "UNINSTALLED_SUCCESS := " > $(BUILD)/config/UNINS_STAT.mk; \
|
$(E_NS) "UNINSTALLED_SUCCESS := " > $(BUILD)/config/UNINS_STAT.mk
|
||||||
|
@ exit 0
|
||||||
|
|
||||||
uninstall_$(TARGET):
|
uninstall_$(TARGET):
|
||||||
if [ -f $(TERMUX_USR)/share/man/man8/$(TARGET).8.gz ]; then \
|
if [ -f $(TERMUX_USR)/share/man/man8/$(TARGET).8.gz ]; then \
|
||||||
|
|||||||
@@ -31,34 +31,33 @@ PMT_INCDIR := $(INCLUDE_DIR)/pmt
|
|||||||
|
|
||||||
# the presence of all source files that are on this list will be checked
|
# the presence of all source files that are on this list will be checked
|
||||||
SRCS_REQ := \
|
SRCS_REQ := \
|
||||||
place-holder/debug.c \
|
place-holder/Debug.cpp \
|
||||||
place-holder/help.c \
|
place-holder/Help.cpp \
|
||||||
place-holder/get_stat.c \
|
place-holder/GetState.cpp \
|
||||||
place-holder/lang_tools.c \
|
place-holder/LanguageTools.cpp \
|
||||||
place-holder/languages.c \
|
place-holder/Languages.cpp \
|
||||||
place-holder/partitiontool.c \
|
place-holder/PartitionTool.cpp \
|
||||||
place-holder/pmt.c \
|
place-holder/PartitionManager.cpp \
|
||||||
place-holder/root.c \
|
place-holder/Root.cpp \
|
||||||
place-holder/tools.c \
|
place-holder/Tools.cpp \
|
||||||
place-holder/version.c
|
place-holder/Version.cpp
|
||||||
|
|
||||||
# objects to be used when executable file is created
|
# objects to be used when executable file is created
|
||||||
OBJS_EXEC := \
|
OBJS_EXEC := \
|
||||||
$(SOURCE_DIR)/$(TARGET).o \
|
$(SOURCE_DIR)/PartitionManager.o \
|
||||||
$(SOURCE_DIR)/help.o \
|
$(SOURCE_DIR)/Help.o \
|
||||||
$(SOURCE_DIR)/version.o \
|
$(SOURCE_DIR)/Version.o \
|
||||||
$(SOURCE_DIR)/get_stat.o \
|
$(SOURCE_DIR)/GetState.o \
|
||||||
$(SOURCE_DIR)/tools.o \
|
$(SOURCE_DIR)/Tools.o \
|
||||||
$(SOURCE_DIR)/lang_tools.o \
|
$(SOURCE_DIR)/Languages.o \
|
||||||
$(SOURCE_DIR)/languages.o
|
$(SOURCE_DIR)/LanguageTools.o
|
||||||
|
|
||||||
HEADERS_REQ := \
|
HEADERS_REQ := \
|
||||||
$(PMT_INCDIR)/pmt/ExternC.h \
|
$(PMT_INCDIR)/PartitionManager/Deprecates.h \
|
||||||
$(PMT_INCDIR)/pmt/Deprecates.h \
|
$(PMT_INCDIR)/PartitionManager/HelpFn.h \
|
||||||
$(PMT_INCDIR)/pmt/HelpMessages.h \
|
$(PMT_INCDIR)/PartitionManager/PartitionManager.h \
|
||||||
$(PMT_INCDIR)/pmt/pmt.h \
|
$(PMT_INCDIR)/PartitionManager/StringKeys.h \
|
||||||
$(PMT_INCDIR)/pmt/StringKeys.h \
|
$(PMT_INCDIR)/PartitionManager/VersionFnVars.h
|
||||||
$(PMT_INCDIR)/pmt/VersionVars.h
|
|
||||||
|
|
||||||
PROGRESS_LIST := \
|
PROGRESS_LIST := \
|
||||||
welcome \
|
welcome \
|
||||||
@@ -74,12 +73,6 @@ PROGRESS_LIST := \
|
|||||||
wait \
|
wait \
|
||||||
end_progress
|
end_progress
|
||||||
|
|
||||||
define check_hf
|
|
||||||
@ [ ! -f "$1" ] \
|
|
||||||
&& $(E_NS) " ==> Couldn't found required header file: include/pmt/`basename $1`" \
|
|
||||||
&& exit 1
|
|
||||||
endef
|
|
||||||
|
|
||||||
# all target for building
|
# all target for building
|
||||||
all: $(PROGRESS_LIST)
|
all: $(PROGRESS_LIST)
|
||||||
|
|
||||||
@@ -92,11 +85,6 @@ welcome:
|
|||||||
&& $(E_NS)
|
&& $(E_NS)
|
||||||
$(E) " -------------------------------- " \
|
$(E) " -------------------------------- " \
|
||||||
&& $(E_NS)
|
&& $(E_NS)
|
||||||
@ if [ -f $(SOURCE_DIR)/debug.o ]; then \
|
|
||||||
$(E_NS) " - Please clean up before you build it." && echo; \
|
|
||||||
$(E_NS) " ----------------------------------- "; \
|
|
||||||
exit 1; \
|
|
||||||
fi
|
|
||||||
$(E) " - Checking required source files..."
|
$(E) " - Checking required source files..."
|
||||||
|
|
||||||
pr_obj:
|
pr_obj:
|
||||||
@@ -110,11 +98,11 @@ wait:
|
|||||||
|
|
||||||
make_outdirs:
|
make_outdirs:
|
||||||
@ rm -rf $(IN_OUT_DIR)
|
@ rm -rf $(IN_OUT_DIR)
|
||||||
@ mkdir $(BINARY_DIR)
|
@ mkdir -p $(BINARY_DIR)
|
||||||
@ mkdir $(PACKAGE_DIR)
|
@ mkdir -p $(PACKAGE_DIR)
|
||||||
@ mkdir $(STATICLIB_DIR)
|
@ mkdir -p $(STATICLIB_DIR)
|
||||||
|
|
||||||
place-holder/%.c:
|
place-holder/%.cpp:
|
||||||
$(E) " CHK $(SOURCE_DIRNAME)/`basename $@`"
|
$(E) " CHK $(SOURCE_DIRNAME)/`basename $@`"
|
||||||
@ if [ ! -f "$(SOURCE_DIR)/`basename $@`" ]; then \
|
@ if [ ! -f "$(SOURCE_DIR)/`basename $@`" ]; then \
|
||||||
$(E_NS) " ==> Couldn't found required source file: $(SOURCE_DIRNAME)/`basename $@`"; \
|
$(E_NS) " ==> Couldn't found required source file: $(SOURCE_DIRNAME)/`basename $@`"; \
|
||||||
@@ -122,24 +110,36 @@ place-holder/%.c:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
$(PMT_INCDIR)/%.h:
|
$(PMT_INCDIR)/%.h:
|
||||||
$(E) " CHK include/pmt/`basename $@`"
|
$(E) " CHK include/PartitionManager/`basename $@`"
|
||||||
@ if [ ! -f "$(INCLUDE_DIR)/pmt/`basename $@`" ]; then \
|
@ if [ ! -f "$(INCLUDE_DIR)/PartitionManager/`basename $@`" ]; then \
|
||||||
$(E_NS) " ==> Couldn't found required header file: include/pmt/`basename $@`"; \
|
$(E_NS) " ==> Couldn't found required header file: include/PartitionManager/`basename $@`"; \
|
||||||
exit 1; \
|
exit 1; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$(SOURCE_DIR)/%.o: $(SOURCE_DIR)/%.c
|
$(SOURCE_DIR)/%.o: $(SOURCE_DIR)/%.cpp
|
||||||
$(E) " CC $(SOURCE_DIRNAME)/`basename $@`"
|
$(E) " CXX $(SOURCE_DIRNAME)/`basename $@`"
|
||||||
@ $(CC) $(CFLAGS) -c "$<" || exit 1
|
@ $(CXX) -x c++ $(CXXFLAGS) -c "$<" || exit 1
|
||||||
|
|
||||||
$(TARGET)_%:
|
pmt_root:
|
||||||
$(E) " AR lib$@.a"
|
$(E) " AR lib$@.a"
|
||||||
@ $(AR) rcs "lib$@.a" "$(SOURCE_DIR)/$$(echo "$@" | cut -d'_' -f2).o"
|
@ $(AR) rcs "lib$@.a" "$(SOURCE_DIR)/Root.o"
|
||||||
|
|
||||||
|
pmt_debug:
|
||||||
|
$(E) " AR lib$@.a"
|
||||||
|
@ $(AR) rcs "lib$@.a" "$(SOURCE_DIR)/Debug.o"
|
||||||
|
|
||||||
|
pmt_listpartitions:
|
||||||
|
$(E) " AR lib$@.a"
|
||||||
|
@ $(AR) rcs "lib$@.a" "$(SOURCE_DIR)/ListPartitions.o"
|
||||||
|
|
||||||
|
pmt_partitiontool:
|
||||||
|
$(E) " AR lib$@.a"
|
||||||
|
@ $(AR) rcs "lib$@.a" "$(SOURCE_DIR)/PartitionTool.o"
|
||||||
|
|
||||||
make_executable:
|
make_executable:
|
||||||
$(E) " - Making executable file..."
|
$(E) " - Making executable file..."
|
||||||
$(E) " LD $(TARGET)"
|
$(E) " LD $(TARGET)"
|
||||||
@ $(CC) $(CFLAGS) -L$(SOURCE_DIR) $(foreach st,$(STATIC_LIBS),$(shell echo -n -l$(st) )) -o $(TARGET) $(OBJS_EXEC) || exit 1
|
@ $(CXX) $(CXXFLAGS) -L$(SOURCE_DIR) $(foreach st,$(STATIC_LIBS),$(shell echo -n -l$(st) )) -o $(TARGET) $(OBJS_EXEC) || exit 1
|
||||||
|
|
||||||
end_progress:
|
end_progress:
|
||||||
@ abort_build() { \
|
@ abort_build() { \
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
export PMT_VERSION="2.7.0"
|
export PMT_VERSION="2.8.0"
|
||||||
export PMT_VERSION_CODE=270
|
export PMT_VERSION_CODE=280
|
||||||
export NDK_LINK="https://dl.google.com/android/repository/android-ndk-r27-linux.zip"
|
export NDK_VERSION="r27"
|
||||||
export NDK_VERSION="r27"
|
|
||||||
export NDK_IS="android-ndk"
|
|
||||||
@@ -16,18 +16,14 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __PMT_DEPRECATED_H
|
#ifndef __PMT_DEPRECATES_H
|
||||||
#define __PMT_DEPRECATED_H
|
#define __PMT_DEPRECATES_H
|
||||||
|
|
||||||
#include <pmt/ExternC.h>
|
|
||||||
|
|
||||||
PMT_EXTERN_C_BEGIN
|
|
||||||
|
|
||||||
#define deprecated_opt 1
|
#define deprecated_opt 1
|
||||||
#define changed_opt 2
|
#define changed_opt 2
|
||||||
#define end_depr_pointer 0
|
#define end_depr_pointer 0
|
||||||
#define not_changed 0
|
#define not_changed 0
|
||||||
#define not_changed_long NULL
|
#define not_changed_long nullptr
|
||||||
|
|
||||||
/* versions */
|
/* versions */
|
||||||
#define v150 "1.5.0"
|
#define v150 "1.5.0"
|
||||||
@@ -43,6 +39,7 @@ PMT_EXTERN_C_BEGIN
|
|||||||
#define v250 "2.5.0"
|
#define v250 "2.5.0"
|
||||||
#define v260 "2.6.0"
|
#define v260 "2.6.0"
|
||||||
#define v270 "2.7.0"
|
#define v270 "2.7.0"
|
||||||
|
#define v280 "2.8.0"
|
||||||
#define vUNK NULL
|
#define vUNK NULL
|
||||||
|
|
||||||
struct pmt_deprecates {
|
struct pmt_deprecates {
|
||||||
@@ -54,38 +51,44 @@ struct pmt_deprecates {
|
|||||||
const char* depr_version;
|
const char* depr_version;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static struct pmt_deprecates depr_table[] = {
|
||||||
|
{deprecated_opt, 'b', not_changed, "backup", not_changed_long, v210},
|
||||||
|
{deprecated_opt, 'F', not_changed, "flash", not_changed_long, v210},
|
||||||
|
{deprecated_opt, 'r', not_changed, "format", not_changed_long, v210},
|
||||||
|
{deprecated_opt, 'L', not_changed, "license", not_changed_long, v250},
|
||||||
|
{changed_opt, 'D', 'p', "list", not_changed_long, v210},
|
||||||
|
{end_depr_pointer, not_changed, not_changed, not_changed_long, not_changed_long, vUNK}
|
||||||
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
__deprecated_opt_handle(int opt, const char* opt_long, const char* depr_msg)
|
__deprecated_opt_handle(int opt, const string opt_long, const char* depr_msg)
|
||||||
{
|
{
|
||||||
static char long_e_msg[250];
|
static string long_e_msg;
|
||||||
|
|
||||||
static struct pmt_deprecates depr_table[] = {
|
if (opt_long == "")
|
||||||
{deprecated_opt, 'b', not_changed, "backup", not_changed_long, v210},
|
long_e_msg = PartitionManager::Display::UsingDispString->not_changed_opt;
|
||||||
{deprecated_opt, 'F', not_changed, "flash", not_changed_long, v210},
|
|
||||||
{deprecated_opt, 'r', not_changed, "format", not_changed_long, v210},
|
|
||||||
{deprecated_opt, 'L', not_changed, "license", not_changed_long, v250},
|
|
||||||
{changed_opt, 'D', 'p', "list", not_changed_long, v210},
|
|
||||||
{end_depr_pointer, not_changed, not_changed, not_changed_long, not_changed_long, vUNK}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (opt_long == NULL)
|
|
||||||
sprintf(long_e_msg, "%s", current->not_changed_opt);
|
|
||||||
else
|
else
|
||||||
sprintf(long_e_msg, "%s", opt_long);
|
long_e_msg = opt_long;
|
||||||
|
|
||||||
for (int optctrl = 0; depr_table[optctrl].depr_type != 0; optctrl++)
|
for (int optctrl = 0; depr_table[optctrl].depr_type != 0; optctrl++)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (depr_table[optctrl].depr_type == 1)
|
if (depr_table[optctrl].depr_type == 1)
|
||||||
{
|
{
|
||||||
if (opt == depr_table[optctrl].option || strcmp(opt_long, depr_table[optctrl].option_long) == 0)
|
if (opt == depr_table[optctrl].option || strcmp(opt_long.c_str(), depr_table[optctrl].option_long) == 0)
|
||||||
LOGD("%s [%s]: -%c (%s): %s\n", current->depr_opt_str, depr_table[optctrl].depr_version, (char)depr_table[optctrl].option, depr_table[optctrl].option_long, depr_msg);
|
{
|
||||||
|
LOGD("%s [%s]: -%c (%s): %s\n", PartitionManager::Display::UsingDispString->depr_opt_str, depr_table[optctrl].depr_version, (char)depr_table[optctrl].option, depr_table[optctrl].option_long, depr_msg);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (depr_table[optctrl].depr_type == 2)
|
else if (depr_table[optctrl].depr_type == 2)
|
||||||
{
|
{
|
||||||
if (opt == depr_table[optctrl].option || strcmp(opt_long, depr_table[optctrl].option_long) == 0)
|
if (opt == depr_table[optctrl].option || strcmp(opt_long.c_str(), depr_table[optctrl].option_long) == 0)
|
||||||
LOGD("%s [%s]: -%c (%s): %s\n", current->switched_opt_str, depr_table[optctrl].depr_version, (char)depr_table[optctrl].option, long_e_msg, depr_msg);
|
{
|
||||||
|
LOGD("%s [%s]: -%c (%s): %s\n", PartitionManager::Display::UsingDispString->switched_opt_str, depr_table[optctrl].depr_version, (char)depr_table[optctrl].option, long_e_msg.c_str(), depr_msg);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,8 +97,6 @@ __deprecated_opt_handle(int opt, const char* opt_long, const char* depr_msg)
|
|||||||
|
|
||||||
#define DEPR_HANDLE(x, y, z) __deprecated_opt_handle(x, y, z)
|
#define DEPR_HANDLE(x, y, z) __deprecated_opt_handle(x, y, z)
|
||||||
|
|
||||||
PMT_EXTERN_C_END
|
#endif /* __PMT_DEPRECATES_H */
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* end of code */
|
/* end of code */
|
||||||
@@ -19,13 +19,11 @@
|
|||||||
#ifndef __PMT_HELP_MSGS_H
|
#ifndef __PMT_HELP_MSGS_H
|
||||||
#define __PMT_HELP_MSGS_H
|
#define __PMT_HELP_MSGS_H
|
||||||
|
|
||||||
#include <pmt/ExternC.h>
|
namespace PartitionManager {
|
||||||
|
namespace Functions {
|
||||||
PMT_EXTERN_C_BEGIN
|
void DisplayHelp(void);
|
||||||
|
}
|
||||||
void help(void);
|
}
|
||||||
|
|
||||||
PMT_EXTERN_C_END
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
149
include/PartitionManager/PartitionManager.h
Executable file
149
include/PartitionManager/PartitionManager.h
Executable file
@@ -0,0 +1,149 @@
|
|||||||
|
/* By YZBruh */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright 2024 Partition Manager
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if !defined(__clang__) && !defined(__NDK_BUILD)
|
||||||
|
#error "Your compiler is NOT clang. Please build with LLVM clang."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __PMT_H_
|
||||||
|
#define __PMT_H_
|
||||||
|
|
||||||
|
#ifdef INC_MAIN_LIBS
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <string>
|
||||||
|
#include <cstring>
|
||||||
|
#include <cstdarg>
|
||||||
|
#include <clocale>
|
||||||
|
|
||||||
|
#if !defined(HELP) || !defined(VERSIONING)
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <fstream>
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#ifdef INC_STRINGKEYS
|
||||||
|
#include <PartitionManager/StringKeys.h>
|
||||||
|
#endif
|
||||||
|
#ifdef INC_DIRENT
|
||||||
|
#include <dirent.h>
|
||||||
|
#endif
|
||||||
|
#ifdef INC_STAT
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#endif
|
||||||
|
#ifdef INC_DEBUGERS
|
||||||
|
#include <cerrno>
|
||||||
|
#endif
|
||||||
|
#ifdef INC_TOOLS_REQS
|
||||||
|
#include <sys/statvfs.h>
|
||||||
|
#endif
|
||||||
|
#ifdef INC_LIBGEN
|
||||||
|
#include <libgen.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
/* logging levels */
|
||||||
|
typedef enum {
|
||||||
|
LOG_LEVEL_FATAL,
|
||||||
|
LOG_LEVEL_ERROR,
|
||||||
|
LOG_LEVEL_WARN,
|
||||||
|
LOG_LEVEL_DEBUG
|
||||||
|
} LogLevel;
|
||||||
|
|
||||||
|
/* fast error processing without errno entry
|
||||||
|
* but errno can be given in the entrance
|
||||||
|
*/
|
||||||
|
char* strqerror(int errno_macro = errno);
|
||||||
|
|
||||||
|
/* create a special namespace */
|
||||||
|
namespace PartitionManager {
|
||||||
|
namespace Strings {
|
||||||
|
extern string OutputName;
|
||||||
|
extern string CustomContext;
|
||||||
|
extern string TargetPartition;
|
||||||
|
extern string TargetFlashFile;
|
||||||
|
extern string TargetFormatFS;
|
||||||
|
extern string PartitionType;
|
||||||
|
extern string ExecutingName;
|
||||||
|
extern string CurrentLanguage;
|
||||||
|
} /* namespace Strings */
|
||||||
|
|
||||||
|
namespace Booleans {
|
||||||
|
extern bool UseLogical;
|
||||||
|
extern bool UseCustomContext;
|
||||||
|
extern bool UsesSlots;
|
||||||
|
extern bool UsesLogical;
|
||||||
|
extern bool SilentEnabled;
|
||||||
|
extern bool FlashMode;
|
||||||
|
extern bool BackupMode;
|
||||||
|
extern bool FormatMode;
|
||||||
|
extern bool ForceMode;
|
||||||
|
extern bool VerboseMode;
|
||||||
|
extern bool InstalledOnTermux;
|
||||||
|
extern bool ActivateRoot;
|
||||||
|
} /* namespace Booleans */
|
||||||
|
|
||||||
|
namespace Display {
|
||||||
|
extern struct langdb_general* UsingDispString;
|
||||||
|
extern struct langdb_docs* UsingDocDispString;
|
||||||
|
extern struct langdb_general LangEn;
|
||||||
|
extern struct langdb_general LangTr;
|
||||||
|
extern struct langdb_docs LangDocEn;
|
||||||
|
extern struct langdb_docs LangDocTr;
|
||||||
|
} /* namespace Display */
|
||||||
|
|
||||||
|
namespace Functions {
|
||||||
|
int ListPartitions(void);
|
||||||
|
int GetState(const string& filepath, const string& stype = "file");
|
||||||
|
int Start(unsigned short progress_code);
|
||||||
|
void SetLanguage(const string& lang, unsigned short null_conf_stat);
|
||||||
|
void DisplayLog(LogLevel status, const char* fmt, ...);
|
||||||
|
void DisplayVerboseLog(LogLevel status, const char* fmt, ...);
|
||||||
|
void CheckDevPoint(void);
|
||||||
|
void CheckRoot(void);
|
||||||
|
bool CleanSWPoint(void);
|
||||||
|
bool LoadLanguage(void);
|
||||||
|
} /* namespace Functions */
|
||||||
|
|
||||||
|
} /* namespace PartitionManager */
|
||||||
|
|
||||||
|
/* logging macros */
|
||||||
|
#define LOGF(fmt, ...) \
|
||||||
|
PartitionManager::Functions::DisplayLog(LOG_LEVEL_FATAL, fmt, ##__VA_ARGS__)
|
||||||
|
#define LOGE(fmt, ...) \
|
||||||
|
PartitionManager::Functions::DisplayLog(LOG_LEVEL_ERROR, fmt, ##__VA_ARGS__)
|
||||||
|
#define LOGW(fmt, ...) \
|
||||||
|
PartitionManager::Functions::DisplayLog(LOG_LEVEL_WARN, fmt, ##__VA_ARGS__)
|
||||||
|
#define LOGD(fmt, ...) \
|
||||||
|
PartitionManager::Functions::DisplayLog(LOG_LEVEL_DEBUG, fmt, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
#define VLOGF(fmt, ...) \
|
||||||
|
PartitionManager::Functions::DisplayVerboseLog(LOG_LEVEL_FATAL, fmt, ##__VA_ARGS__)
|
||||||
|
#define VLOGE(fmt, ...) \
|
||||||
|
PartitionManager::Functions::DisplayVerboseLog(LOG_LEVEL_ERROR, fmt, ##__VA_ARGS__)
|
||||||
|
#define VLOGW(fmt, ...) \
|
||||||
|
PartitionManager::Functions::DisplayVerboseLog(LOG_LEVEL_WARN, fmt, ##__VA_ARGS__)
|
||||||
|
#define VLOGD(fmt, ...) \
|
||||||
|
PartitionManager::Functions::DisplayVerboseLog(LOG_LEVEL_DEBUG, fmt, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* end of code */
|
||||||
@@ -19,12 +19,8 @@
|
|||||||
#ifndef __PMT_STRINGKEYS_
|
#ifndef __PMT_STRINGKEYS_
|
||||||
#define __PMT_STRINGKEYS_
|
#define __PMT_STRINGKEYS_
|
||||||
|
|
||||||
#include <pmt/ExternC.h>
|
|
||||||
|
|
||||||
PMT_EXTERN_C_BEGIN
|
|
||||||
|
|
||||||
/* The struct is a very good option for setting the languages of texts etc. */
|
/* The struct is a very good option for setting the languages of texts etc. */
|
||||||
struct pmt_langdb_general {
|
struct langdb_general {
|
||||||
const char* _Nonnull lang_by_s;
|
const char* _Nonnull lang_by_s;
|
||||||
const char* _Nonnull language;
|
const char* _Nonnull language;
|
||||||
const char* _Nonnull lang_prefix;
|
const char* _Nonnull lang_prefix;
|
||||||
@@ -39,7 +35,6 @@ struct pmt_langdb_general {
|
|||||||
const char* _Nonnull not_write;
|
const char* _Nonnull not_write;
|
||||||
const char* _Nonnull not_gen;
|
const char* _Nonnull not_gen;
|
||||||
const char* _Nonnull no_root;
|
const char* _Nonnull no_root;
|
||||||
const char* _Nonnull no_target;
|
|
||||||
const char* _Nonnull expected_backup_arg;
|
const char* _Nonnull expected_backup_arg;
|
||||||
const char* _Nonnull expected_flash_arg;
|
const char* _Nonnull expected_flash_arg;
|
||||||
const char* _Nonnull expected_format_arg;
|
const char* _Nonnull expected_format_arg;
|
||||||
@@ -59,6 +54,7 @@ struct pmt_langdb_general {
|
|||||||
const char* _Nonnull depr_Vlicense_opt;
|
const char* _Nonnull depr_Vlicense_opt;
|
||||||
const char* _Nonnull depr_ch_list_opt;
|
const char* _Nonnull depr_ch_list_opt;
|
||||||
const char* _Nonnull not_spec_opt;
|
const char* _Nonnull not_spec_opt;
|
||||||
|
const char* _Nonnull some_spec;
|
||||||
const char* _Nonnull logical_warn;
|
const char* _Nonnull logical_warn;
|
||||||
const char* _Nonnull ab_warn;
|
const char* _Nonnull ab_warn;
|
||||||
const char* _Nonnull out_not_spec;
|
const char* _Nonnull out_not_spec;
|
||||||
@@ -68,15 +64,22 @@ struct pmt_langdb_general {
|
|||||||
const char* _Nonnull part_disk_sz_fail;
|
const char* _Nonnull part_disk_sz_fail;
|
||||||
const char* _Nonnull flash_file_sz_fail;
|
const char* _Nonnull flash_file_sz_fail;
|
||||||
const char* _Nonnull unknown_opr;
|
const char* _Nonnull unknown_opr;
|
||||||
const char* _Nonnull list_of_dir;
|
const char* _Nonnull req_an_arg;
|
||||||
|
const char* _Nonnull list_of_general;
|
||||||
|
const char* _Nonnull list_of_logc;
|
||||||
const char* _Nonnull success_backup;
|
const char* _Nonnull success_backup;
|
||||||
const char* _Nonnull success_flash;
|
const char* _Nonnull success_flash;
|
||||||
|
const char* _Nonnull success_format;
|
||||||
|
const char* _Nonnull formatting;
|
||||||
const char* _Nonnull warn;
|
const char* _Nonnull warn;
|
||||||
const char* _Nonnull fatal;
|
const char* _Nonnull fatal;
|
||||||
|
const char* _Nonnull is_requires_arg;
|
||||||
|
const char* _Nonnull unknw_arg;
|
||||||
const char* _Nonnull switching_lang;
|
const char* _Nonnull switching_lang;
|
||||||
const char* _Nonnull welcome;
|
const char* _Nonnull welcome;
|
||||||
const char* _Nullable welcome_;
|
const char* _Nullable welcome_;
|
||||||
const char* _Nonnull for_more;
|
const char* _Nonnull for_more;
|
||||||
|
const char* _Nonnull s_and_v;
|
||||||
const char* _Nonnull try_h;
|
const char* _Nonnull try_h;
|
||||||
const char* _Nonnull usage_head;
|
const char* _Nonnull usage_head;
|
||||||
const char* _Nonnull depr_opt_str;
|
const char* _Nonnull depr_opt_str;
|
||||||
@@ -85,12 +88,13 @@ struct pmt_langdb_general {
|
|||||||
const char* _Nonnull compiler_str;
|
const char* _Nonnull compiler_str;
|
||||||
const char* _Nonnull version_str;
|
const char* _Nonnull version_str;
|
||||||
const char* _Nonnull bin_str;
|
const char* _Nonnull bin_str;
|
||||||
|
const char* _Nonnull fs_str;
|
||||||
const char* _Nonnull unknw_str;
|
const char* _Nonnull unknw_str;
|
||||||
const char* _Nonnull by_str;
|
const char* _Nonnull by_str;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* docs etc. */
|
/* docs etc. */
|
||||||
struct pmt_langdb_docs {
|
struct langdb_docs {
|
||||||
const char* _Nonnull docs_strs_l1;
|
const char* _Nonnull docs_strs_l1;
|
||||||
const char* _Nonnull docs_strs_l2;
|
const char* _Nonnull docs_strs_l2;
|
||||||
const char* _Nonnull docs_strs_l3;
|
const char* _Nonnull docs_strs_l3;
|
||||||
@@ -105,17 +109,11 @@ struct pmt_langdb_docs {
|
|||||||
const char* _Nonnull docs_strs_l12;
|
const char* _Nonnull docs_strs_l12;
|
||||||
const char* _Nonnull docs_strs_l13;
|
const char* _Nonnull docs_strs_l13;
|
||||||
const char* _Nonnull docs_strs_l14;
|
const char* _Nonnull docs_strs_l14;
|
||||||
|
const char* _Nonnull docs_strs_l15;
|
||||||
const char* _Nonnull or_str;
|
const char* _Nonnull or_str;
|
||||||
const char* _Nonnull usage_docstr;
|
const char* _Nonnull usage_docstr;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* for checks etc */
|
|
||||||
struct pmt_langdb_langs {
|
|
||||||
const char* _Nullable lang_pr;
|
|
||||||
};
|
|
||||||
|
|
||||||
PMT_EXTERN_C_END
|
|
||||||
|
|
||||||
#endif /* __PMT_STRINGKEYS_ */
|
#endif /* __PMT_STRINGKEYS_ */
|
||||||
|
|
||||||
/* end of code */
|
/* end of code */
|
||||||
@@ -19,21 +19,21 @@
|
|||||||
#ifndef __PMT_VERSIONING_H
|
#ifndef __PMT_VERSIONING_H
|
||||||
#define __PMT_VERSIONING_H
|
#define __PMT_VERSIONING_H
|
||||||
|
|
||||||
#include <pmt/ExternC.h>
|
|
||||||
|
|
||||||
PMT_EXTERN_C_BEGIN
|
|
||||||
|
|
||||||
#ifdef __NDK_BUILD
|
#ifdef __NDK_BUILD
|
||||||
#include <android/ndk-version.h>
|
#include <android/ndk-version.h>
|
||||||
#include <pmt/generated/clang-version.h>
|
#include <PartitionManager/generated/clang-version.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* versioning */
|
/* versioning */
|
||||||
#define PMT_MAJOR 2
|
#define PMT_MAJOR 2
|
||||||
#define PMT_MINOR 7
|
#define PMT_MINOR 8
|
||||||
#define PMT_PATCHLEVEL 0
|
#define PMT_PATCHLEVEL 0
|
||||||
|
|
||||||
PMT_EXTERN_C_END
|
namespace PartitionManager {
|
||||||
|
namespace Functions {
|
||||||
|
void DisplayVersion(void);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
/* By YZBruh */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copyright 2024 Partition Manager
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __PMT_EXTERN_C_H_
|
|
||||||
#define __PMT_EXTERN_C_H_
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#define PMT_EXTERN_C_BEGIN extern "C" {
|
|
||||||
#define PMT_EXTERN_C_END }
|
|
||||||
#else
|
|
||||||
#define PMT_EXTERN_C_BEGIN
|
|
||||||
#define PMT_EXTERN_C_END
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
/* By YZBruh */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copyright 2024 Partition Manager
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if !defined(__clang__) && !defined(__NDK_BUILD)
|
|
||||||
#error "Your compiler is NOT clang. Please build with LLVM clang."
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <pmt/ExternC.h>
|
|
||||||
|
|
||||||
PMT_EXTERN_C_BEGIN
|
|
||||||
|
|
||||||
#ifndef __PMT_H_
|
|
||||||
#define __PMT_H_
|
|
||||||
|
|
||||||
#ifdef INC_MAIN_LIBS
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#if !defined(HELP) || !defined(VERSIONING)
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef INC_GETOPT
|
|
||||||
#include <getopt.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef INC_DIRENT
|
|
||||||
#include <dirent.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef INC_STAT
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef INC_DEBUGERS
|
|
||||||
#include <errno.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef INC_TOOLS_REQS
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <sys/statvfs.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* variable definations */
|
|
||||||
extern char* _Nullable out;
|
|
||||||
extern char* _Nullable cust_cxt;
|
|
||||||
extern char* _Nullable target_partition;
|
|
||||||
extern char* _Nullable target_flash_file;
|
|
||||||
extern char* _Nullable format_fs;
|
|
||||||
extern char* _Nullable partition_type;
|
|
||||||
extern char* _Nullable bin_name;
|
|
||||||
extern bool pmt_use_logical;
|
|
||||||
extern bool pmt_use_cust_cxt;
|
|
||||||
extern bool pmt_ab;
|
|
||||||
extern bool pmt_logical;
|
|
||||||
extern bool pmt_silent;
|
|
||||||
extern bool pmt_flash;
|
|
||||||
extern bool pmt_backup;
|
|
||||||
extern bool pmt_format;
|
|
||||||
extern bool pmt_force_mode;
|
|
||||||
extern bool pmt_inst_on_termux;
|
|
||||||
|
|
||||||
/* language struces configurations */
|
|
||||||
extern struct pmt_langdb_general* _Nullable current;
|
|
||||||
extern struct pmt_langdb_docs* _Nullable curr_docs;
|
|
||||||
extern struct pmt_langdb_general en;
|
|
||||||
extern struct pmt_langdb_general tr;
|
|
||||||
extern struct pmt_langdb_docs en_docs;
|
|
||||||
extern struct pmt_langdb_docs tr_docs;
|
|
||||||
|
|
||||||
/* logging levels */
|
|
||||||
typedef enum {
|
|
||||||
LOG_LEVEL_FATAL,
|
|
||||||
LOG_LEVEL_ERR,
|
|
||||||
LOG_LEVEL_WARN,
|
|
||||||
LOG_LEVEL_DEBUG
|
|
||||||
} LogLevel;
|
|
||||||
|
|
||||||
/* function definations */
|
|
||||||
int listpart(void);
|
|
||||||
void check_dev_point(void);
|
|
||||||
void check_root(void);
|
|
||||||
int pmt(unsigned short progress_code);
|
|
||||||
void version(void);
|
|
||||||
void setlang(const char* _Nonnull lang, int null_conf_stat);
|
|
||||||
int search_sls(void);
|
|
||||||
int loadlang(void);
|
|
||||||
int get_stat(const char* _Nonnull filepath, const char* _Nonnull stype);
|
|
||||||
void debug(LogLevel status, const char* _Nullable fmt, ...);
|
|
||||||
|
|
||||||
/* logging macros */
|
|
||||||
#define LOGF(fmt, ...) debug(LOG_LEVEL_FATAL, fmt, ##__VA_ARGS__)
|
|
||||||
#define LOGE(fmt, ...) debug(LOG_LEVEL_ERR, fmt, ##__VA_ARGS__)
|
|
||||||
#define LOGW(fmt, ...) debug(LOG_LEVEL_WARN, fmt, ##__VA_ARGS__)
|
|
||||||
#define LOGD(fmt, ...) debug(LOG_LEVEL_DEBUG, fmt, ##__VA_ARGS__)
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
PMT_EXTERN_C_END
|
|
||||||
|
|
||||||
/* end of code */
|
|
||||||
114
jni/Debug.cpp
Executable file
114
jni/Debug.cpp
Executable file
@@ -0,0 +1,114 @@
|
|||||||
|
/* By YZBruh */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright 2024 Partition Manager
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define INC_MAIN_LIBS
|
||||||
|
#define INC_STRINGKEYS
|
||||||
|
|
||||||
|
#include <PartitionManager/PartitionManager.h>
|
||||||
|
|
||||||
|
using namespace PartitionManager;
|
||||||
|
|
||||||
|
/* it's prints standart logs */
|
||||||
|
void Functions::DisplayLog(LogLevel status, const char* _Nullable fmt, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
|
||||||
|
switch (status)
|
||||||
|
{
|
||||||
|
case LOG_LEVEL_ERROR:
|
||||||
|
if (!Booleans::SilentEnabled)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: ", Strings::ExecutingName.c_str());
|
||||||
|
vfprintf(stderr, fmt, args);
|
||||||
|
}
|
||||||
|
exit(1);
|
||||||
|
break;
|
||||||
|
case LOG_LEVEL_WARN:
|
||||||
|
if (!Booleans::SilentEnabled)
|
||||||
|
{
|
||||||
|
fprintf(stdout, "%s: ", Display::UsingDispString->warn);
|
||||||
|
vfprintf(stdout, fmt, args);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case LOG_LEVEL_FATAL:
|
||||||
|
if (!Booleans::SilentEnabled)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: ", Display::UsingDispString->fatal);
|
||||||
|
vfprintf(stderr, fmt, args);
|
||||||
|
}
|
||||||
|
abort();
|
||||||
|
break;
|
||||||
|
case LOG_LEVEL_DEBUG:
|
||||||
|
if (!Booleans::SilentEnabled)
|
||||||
|
vfprintf(stdout, fmt, args);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* it's prints verbose logs */
|
||||||
|
void Functions::DisplayVerboseLog(LogLevel status, const char* fmt, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
|
||||||
|
switch (status)
|
||||||
|
{
|
||||||
|
case LOG_LEVEL_ERROR:
|
||||||
|
if (Booleans::VerboseMode)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "E:[stderr]: ");
|
||||||
|
vfprintf(stderr, fmt, args);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case LOG_LEVEL_WARN:
|
||||||
|
if (Booleans::VerboseMode)
|
||||||
|
{
|
||||||
|
fprintf(stdout, "W:[stdout]: ");
|
||||||
|
vfprintf(stdout, fmt, args);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case LOG_LEVEL_FATAL:
|
||||||
|
if (Booleans::VerboseMode)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "F:[stderr]: ");
|
||||||
|
vfprintf(stderr, fmt, args);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case LOG_LEVEL_DEBUG:
|
||||||
|
if (Booleans::VerboseMode)
|
||||||
|
{
|
||||||
|
fprintf(stdout, "D:[stdout]: ");
|
||||||
|
vfprintf(stdout, fmt, args);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Last error is taken from strerror by taking
|
||||||
|
* the contents of errno or taking a special entry
|
||||||
|
*/
|
||||||
|
char* strqerror(int errno_macro) { return strerror(errno_macro); }
|
||||||
|
|
||||||
|
/* end of code */
|
||||||
@@ -16,15 +16,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define INC_MAIN_LIBS
|
#define INC_MAIN_LIBS
|
||||||
#define INC_STAT
|
#define INC_STAT
|
||||||
|
|
||||||
#include <pmt/PartitionManager.h>
|
#include <PartitionManager/PartitionManager.h>
|
||||||
#include <pmt/StringKeys.h>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The target file is controlled by the stat function.
|
* The target file is controlled by the stat function.
|
||||||
@@ -32,48 +27,28 @@ extern "C" {
|
|||||||
* If it is never found, it returns 1 value.
|
* If it is never found, it returns 1 value.
|
||||||
* If he finds 0 value is returned.
|
* If he finds 0 value is returned.
|
||||||
* If the desired type is not in -1 value is returned.
|
* If the desired type is not in -1 value is returned.
|
||||||
|
* If the search type is unknown, 3 value is returned
|
||||||
*/
|
*/
|
||||||
int get_stat(const char* _Nonnull filepath, const char* _Nonnull stype)
|
int PartitionManager::Functions::GetState(const string& filepath, const string& stype)
|
||||||
{
|
{
|
||||||
static struct stat get_stat;
|
static struct stat GetStat;
|
||||||
|
|
||||||
if (stat(filepath, &get_stat) != 0)
|
VLOGD("GetStat: checking `%s' with 'stat <sys/stat.h>'...\n", filepath.c_str());
|
||||||
|
if (stat(filepath.c_str(), &GetStat) != 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (strcmp(stype, "dir") == 0)
|
if (stype == "dir")
|
||||||
{
|
return (S_ISDIR(GetStat.st_mode)) ? 0 : -1;
|
||||||
if (S_ISDIR(get_stat.st_mode))
|
else if (stype == "file")
|
||||||
return 0;
|
return (S_ISREG(GetStat.st_mode)) ? 0 : -1;
|
||||||
else
|
else if (stype == "blk")
|
||||||
return -1;
|
return (S_ISBLK(GetStat.st_mode)) ? 0 : -1;
|
||||||
}
|
else if (stype == "link")
|
||||||
else if (strcmp(stype, "file") == 0)
|
return (S_ISLNK(GetStat.st_mode)) ? 0 : -1;
|
||||||
{
|
else
|
||||||
if (S_ISREG(get_stat.st_mode))
|
return 3;
|
||||||
return 0;
|
|
||||||
else
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
else if (strcmp(stype, "blk") == 0)
|
|
||||||
{
|
|
||||||
if (S_ISBLK(get_stat.st_mode))
|
|
||||||
return 0;
|
|
||||||
else
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
else if (strcmp(stype, "link") == 0)
|
|
||||||
{
|
|
||||||
if (S_ISLNK(get_stat.st_mode))
|
|
||||||
return 0;
|
|
||||||
else
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* end of code */
|
/* end of code */
|
||||||
65
jni/Help.cpp
Executable file
65
jni/Help.cpp
Executable file
@@ -0,0 +1,65 @@
|
|||||||
|
/* By YZBruh */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2024 Partition Manager
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define INC_MAIN_LIBS
|
||||||
|
#define INC_STRINGKEYS
|
||||||
|
#define HELP
|
||||||
|
|
||||||
|
#include <PartitionManager/PartitionManager.h>
|
||||||
|
#include <PartitionManager/HelpFn.h>
|
||||||
|
|
||||||
|
using namespace PartitionManager;
|
||||||
|
|
||||||
|
struct langdb_docs* Display::UsingDocDispString = nullptr;
|
||||||
|
|
||||||
|
static void
|
||||||
|
prepare_langconf_docs(void)
|
||||||
|
{
|
||||||
|
if (Strings::CurrentLanguage == "en")
|
||||||
|
Display::UsingDocDispString = &Display::LangDocEn;
|
||||||
|
else if (Strings::CurrentLanguage == "tr")
|
||||||
|
Display::UsingDocDispString = &Display::LangDocTr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Functions::DisplayHelp(void)
|
||||||
|
{
|
||||||
|
VLOGD("DisplayHelp: Loading language for help messages... Calling prepare_langconf_docs() <local function>...\n");
|
||||||
|
prepare_langconf_docs();
|
||||||
|
VLOGD("DisplayHelp: Printing...\n");
|
||||||
|
LOGD("%s: %s %s\n", Display::UsingDocDispString->usage_docstr, Strings::ExecutingName.c_str(), Display::UsingDocDispString->docs_strs_l1);
|
||||||
|
LOGD(" %s: %s %s\n", Display::UsingDocDispString->or_str, Strings::ExecutingName.c_str(), Display::UsingDocDispString->docs_strs_l2);
|
||||||
|
LOGD(" %s: %s %s\n\n", Display::UsingDocDispString->or_str, Strings::ExecutingName.c_str(), Display::UsingDocDispString->docs_strs_l3);
|
||||||
|
LOGD("%s: \n", Display::UsingDocDispString->docs_strs_l4);
|
||||||
|
LOGD(" -l, --logical %s\n", Display::UsingDocDispString->docs_strs_l5);
|
||||||
|
LOGD(" -c, --context %s\n", Display::UsingDocDispString->docs_strs_l6);
|
||||||
|
LOGD(" -p, --list %s\n", Display::UsingDocDispString->docs_strs_l7);
|
||||||
|
LOGD(" -s, --silent %s\n", Display::UsingDocDispString->docs_strs_l8);
|
||||||
|
LOGD(" -f, --force %s\n", Display::UsingDocDispString->docs_strs_l9);
|
||||||
|
LOGD(" -V, --verbose %s\n", Display::UsingDocDispString->docs_strs_l10);
|
||||||
|
LOGD(" -S, --set-lang %s\n", Display::UsingDocDispString->docs_strs_l11);
|
||||||
|
LOGD(" -v, --version %s\n", Display::UsingDocDispString->docs_strs_l12);
|
||||||
|
LOGD(" --help %s\n\n", Display::UsingDocDispString->docs_strs_l13);
|
||||||
|
LOGD("%s:\n", Display::UsingDocDispString->docs_strs_l14);
|
||||||
|
LOGD(" %s backup boot_a -c /dev/block/platform/bootdevice/by-name\n", Strings::ExecutingName.c_str());
|
||||||
|
LOGD(" %s flash boot_a /sdcard/twrp/boot.img -c /dev/block/platform/bootdevice/by-name\n", Strings::ExecutingName.c_str());
|
||||||
|
LOGD(" %s format system_a ext4 --logical\n", Strings::ExecutingName.c_str());
|
||||||
|
LOGD(" %s -c /dev/block/platform/bootdevice/by-name --list\n\n", Strings::ExecutingName.c_str());
|
||||||
|
LOGD("%s <t.me/ShawkTeam | Topics | pmt>\n", Display::UsingDocDispString->docs_strs_l15);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* end of code */
|
||||||
170
jni/LanguageTools.cpp
Executable file
170
jni/LanguageTools.cpp
Executable file
@@ -0,0 +1,170 @@
|
|||||||
|
/* By YZBruh */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright 2024 Partition Manager
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define INC_MAIN_LIBS
|
||||||
|
#define INC_DEBUGERS
|
||||||
|
#define INC_STAT
|
||||||
|
#define INC_STRINGKEYS
|
||||||
|
|
||||||
|
#include <PartitionManager/PartitionManager.h>
|
||||||
|
|
||||||
|
using namespace PartitionManager;
|
||||||
|
|
||||||
|
/* pmt's man doc file path on termux */
|
||||||
|
#define TERMUX_PMT_MANDOC "/data/data/com.termux/files/usr/share/man/man8/pmt.8.gz"
|
||||||
|
#define PMTLANG_CONF "/sdcard/.pmtlang.conf"
|
||||||
|
#define PMT_SW_POINT "/sdcard/.pmtlangsw"
|
||||||
|
|
||||||
|
struct langdb_general* Display::UsingDispString = nullptr;
|
||||||
|
|
||||||
|
static fstream langconf;
|
||||||
|
|
||||||
|
string supp_langs[] = {
|
||||||
|
"en",
|
||||||
|
"tr",
|
||||||
|
""
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool
|
||||||
|
LangControl(const string lang)
|
||||||
|
{
|
||||||
|
for (int i = 0; !supp_langs[i].empty(); i++)
|
||||||
|
{
|
||||||
|
if (lang == supp_langs[i])
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Functions::LoadLanguage(void)
|
||||||
|
{
|
||||||
|
string lang_fpr = "en";
|
||||||
|
langconf.close();
|
||||||
|
|
||||||
|
VLOGD("LoadLanguage: checking install type...\n");
|
||||||
|
if (Functions::GetState(TERMUX_PMT_MANDOC) == 0)
|
||||||
|
Booleans::InstalledOnTermux = true;
|
||||||
|
|
||||||
|
VLOGD("LoadLanguage: trying to open `%s' with 'open <fstream>'\n", PMTLANG_CONF);
|
||||||
|
langconf.open(PMTLANG_CONF, ios::in | ios::out);
|
||||||
|
|
||||||
|
VLOGD("LoadLanguage: checking status: `%s'...\n", PMTLANG_CONF);
|
||||||
|
if (!langconf.is_open())
|
||||||
|
{
|
||||||
|
langconf.open(PMTLANG_CONF, ios::out | ios::trunc);
|
||||||
|
|
||||||
|
VLOGD("LoadLanguage: calling SetLanguage()...\n");
|
||||||
|
Functions::SetLanguage("en", 1);
|
||||||
|
Display::UsingDispString = &Display::LangEn;
|
||||||
|
Strings::CurrentLanguage = "en";
|
||||||
|
|
||||||
|
if (langconf.is_open())
|
||||||
|
langconf.close();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
VLOGD("LoadLanguage: reading `%s'\n", PMTLANG_CONF);
|
||||||
|
while (getline(langconf, lang_fpr))
|
||||||
|
{
|
||||||
|
if (lang_fpr == "en")
|
||||||
|
goto SetEn;
|
||||||
|
else if (lang_fpr == "tr")
|
||||||
|
goto SetTr;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
VLOGD("LoadLanguage: calling SetLanguage()\n");
|
||||||
|
Functions::SetLanguage("en", 1);
|
||||||
|
VLOGD("LoadLanguage: re-calling LoadLanguage()\n");
|
||||||
|
Functions::LoadLanguage();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!getline(langconf, lang_fpr))
|
||||||
|
{
|
||||||
|
VLOGD("LoadLanguage: calling SetLanguage()\n");
|
||||||
|
Functions::SetLanguage("en", 1);
|
||||||
|
VLOGD("LoadLanguage: re-calling LoadLanguage()\n");
|
||||||
|
Functions::LoadLanguage();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SetEn:
|
||||||
|
langconf.close();
|
||||||
|
Display::UsingDispString = &Display::LangEn;
|
||||||
|
Strings::CurrentLanguage = "en";
|
||||||
|
VLOGD("LoadLanguage: loaded \"en\"\n");
|
||||||
|
return true;
|
||||||
|
|
||||||
|
SetTr:
|
||||||
|
langconf.close();
|
||||||
|
Display::UsingDispString = &Display::LangTr;
|
||||||
|
Strings::CurrentLanguage = "tr";
|
||||||
|
VLOGD("LoadLanguage: loaded \"tr\"\n");
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Functions::SetLanguage(const string& lang, unsigned short null_conf_stat)
|
||||||
|
{
|
||||||
|
VLOGD("SetLanguage: checking speficed language (from input).\n");
|
||||||
|
if (!LangControl(lang.c_str()))
|
||||||
|
LOGE("Unknown language: %s.\n", lang.c_str());
|
||||||
|
|
||||||
|
langconf.close();
|
||||||
|
|
||||||
|
VLOGD("SetLanguage: trying to open `%s' with 'open <fstream>'\n", PMTLANG_CONF);
|
||||||
|
langconf.open(PMTLANG_CONF, ios::out | ios::trunc);
|
||||||
|
|
||||||
|
if (!langconf.is_open())
|
||||||
|
LOGE("Failed!!! Cannot open/write config file.\n");
|
||||||
|
|
||||||
|
VLOGD("SetLanguage: write \"%s\" to `%s' with 'std <iostream>'\n", lang.c_str(), PMTLANG_CONF);
|
||||||
|
langconf << lang;
|
||||||
|
if (!langconf)
|
||||||
|
LOGE("Failed!!! Couldn't write config!\n");
|
||||||
|
else
|
||||||
|
langconf.close();
|
||||||
|
|
||||||
|
if (null_conf_stat != 1)
|
||||||
|
{
|
||||||
|
VLOGD("SetLanguage: generating dummy file `%s' with 'ofstream <fstream>'\n", PMT_SW_POINT);
|
||||||
|
ofstream sw_point(PMT_SW_POINT, ios::trunc);
|
||||||
|
if (sw_point.is_open())
|
||||||
|
sw_point.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Functions::CleanSWPoint(void)
|
||||||
|
{
|
||||||
|
if (Functions::GetState(PMT_SW_POINT) == 0)
|
||||||
|
{
|
||||||
|
VLOGD("CleanSWPoint: removing (force) `%s' with 'remove <unistd.h>'\n", PMT_SW_POINT);
|
||||||
|
remove(PMT_SW_POINT);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* end of code */
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright 2024 Partition Manager
|
* Copyright 2024 Partition Manager
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License";
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
@@ -16,16 +16,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define INC_MAIN_LIBS
|
#define INC_MAIN_LIBS
|
||||||
|
#define INC_STRINGKEYS
|
||||||
|
|
||||||
#include <pmt/PartitionManager.h>
|
#include <PartitionManager/PartitionManager.h>
|
||||||
#include <pmt/StringKeys.h>
|
|
||||||
|
|
||||||
struct pmt_langdb_general en = {
|
namespace PartitionManager {
|
||||||
|
namespace Display {
|
||||||
|
|
||||||
|
struct langdb_general LangEn = {
|
||||||
.lang_by_s = "YZBruh & r0manas",
|
.lang_by_s = "YZBruh & r0manas",
|
||||||
.language = "English",
|
.language = "English",
|
||||||
.lang_prefix = "en",
|
.lang_prefix = "en",
|
||||||
@@ -34,13 +33,12 @@ struct pmt_langdb_general en = {
|
|||||||
.not_dir = "is not a directory.",
|
.not_dir = "is not a directory.",
|
||||||
.not_in_dev = "Nothing found in /dev. Use force mode to avoid this error.",
|
.not_in_dev = "Nothing found in /dev. Use force mode to avoid this error.",
|
||||||
.not_open = "Couldn't open",
|
.not_open = "Couldn't open",
|
||||||
.not_block = "The specified partition is not recognized as a block device.",
|
.not_block = "The specified partition is not recognized as a block device. Use force mode to avoid this error.",
|
||||||
.not_read = "Couldn't read",
|
.not_read = "Couldn't read",
|
||||||
.not_readdir = "Couldn't read directory",
|
.not_readdir = "Couldn't read directory",
|
||||||
.not_write = "Couldn't write",
|
.not_write = "Couldn't write",
|
||||||
.not_gen = "Couldn't generate",
|
.not_gen = "Couldn't generate",
|
||||||
.no_root = "Root access could not be detected! Please run this with root permissions.",
|
.no_root = "Root access could not be detected! Please run this with root permissions.",
|
||||||
.no_target = "No target specified (backup, flash, or format)",
|
|
||||||
.expected_backup_arg = "Expected backup argument 2 (1 of them are not mandatory), retrieved",
|
.expected_backup_arg = "Expected backup argument 2 (1 of them are not mandatory), retrieved",
|
||||||
.expected_flash_arg = "Expected flash argument 2, retrieved",
|
.expected_flash_arg = "Expected flash argument 2, retrieved",
|
||||||
.expected_format_arg = "Expected format argument 2, retrieved",
|
.expected_format_arg = "Expected format argument 2, retrieved",
|
||||||
@@ -48,10 +46,10 @@ struct pmt_langdb_general en = {
|
|||||||
.multiple_wiewers = "Multiple viewers can't be used on the same line.",
|
.multiple_wiewers = "Multiple viewers can't be used on the same line.",
|
||||||
.common_symbol_rule = "When specifying arguments for an option, ensure they do not begin with '-'. Each argument must correspond correctly to its respective option.",
|
.common_symbol_rule = "When specifying arguments for an option, ensure they do not begin with '-'. Each argument must correspond correctly to its respective option.",
|
||||||
.req_part_name = "Partition name required.",
|
.req_part_name = "Partition name required.",
|
||||||
.part_not_found = "Partition not found!",
|
.part_not_found = "Partition not found! Maybe a logical partition?",
|
||||||
.unsupported_fs = "Formatter: unsupported filesystem",
|
.unsupported_fs = "Formatter: unsupported filesystem",
|
||||||
.cannot_stat = "Can't retrieve file status",
|
.cannot_stat = "Can't retrieve file status",
|
||||||
.ffile_more_part = "Flash file size exceeds partition capacity.",
|
.ffile_more_part = "Flash file size exceeds partition capacity. Use force mode to avoid this error (not recommended, riscy!).",
|
||||||
.cannot_get_bsz = "Failed to retrieve partition block size.",
|
.cannot_get_bsz = "Failed to retrieve partition block size.",
|
||||||
.format_fail = "Formatting failed! There is a possibility of data damage.",
|
.format_fail = "Formatting failed! There is a possibility of data damage.",
|
||||||
.depr_backup_opt = "These options for the backup are unavailable.",
|
.depr_backup_opt = "These options for the backup are unavailable.",
|
||||||
@@ -60,24 +58,32 @@ struct pmt_langdb_general en = {
|
|||||||
.depr_Vlicense_opt = "No memory for unnecessary options!",
|
.depr_Vlicense_opt = "No memory for unnecessary options!",
|
||||||
.depr_ch_list_opt = "Use -p argument for listing partitions.",
|
.depr_ch_list_opt = "Use -p argument for listing partitions.",
|
||||||
.not_spec_opt = "Specify the necessary arguments, not option",
|
.not_spec_opt = "Specify the necessary arguments, not option",
|
||||||
|
.some_spec = "You may have indicated options, but they don't work much unless you speficy a main transaction",
|
||||||
.logical_warn = "This device uses logical partitions.",
|
.logical_warn = "This device uses logical partitions.",
|
||||||
.ab_warn = "This device uses A/B partition style.",
|
.ab_warn = "This device uses A/B partition style.",
|
||||||
.out_not_spec = "Output file name not specified. Using default name",
|
.out_not_spec = "Output file name not specified. Using created name",
|
||||||
.please_rerun = "Please rerun the command.",
|
.please_rerun = "Please rerun the command.",
|
||||||
.part_disk_sz = "Partition disk size",
|
.part_disk_sz = "Partition (backup) size",
|
||||||
.flash_file_sz = "Flash file size",
|
.flash_file_sz = "Flash file size",
|
||||||
.part_disk_sz_fail = "Failed to retrieve partition disk size.",
|
.part_disk_sz_fail = "Failed to retrieve partition disk size.",
|
||||||
.flash_file_sz_fail = "Failed to retrieve flash file size.",
|
.flash_file_sz_fail = "Failed to retrieve flash file size.",
|
||||||
.unknown_opr = "Unknown operand",
|
.unknown_opr = "Unknown operand",
|
||||||
.list_of_dir = "Directory listing",
|
.req_an_arg = "option requires an argument",
|
||||||
|
.list_of_general = "List of general partitions",
|
||||||
|
.list_of_logc = "List of logical partitions",
|
||||||
.success_backup = "Backup successful. Output",
|
.success_backup = "Backup successful. Output",
|
||||||
.success_flash = "Flash successful",
|
.success_flash = "Flash successful",
|
||||||
|
.success_format = "Format successful",
|
||||||
|
.formatting = "Formatting",
|
||||||
.warn = "WARNING",
|
.warn = "WARNING",
|
||||||
.fatal = "FATAL ERROR",
|
.fatal = "FATAL ERROR",
|
||||||
|
.is_requires_arg = "requires an argument",
|
||||||
|
.unknw_arg = "unknown option",
|
||||||
.switching_lang = "Switching language...",
|
.switching_lang = "Switching language...",
|
||||||
.welcome = "language!",
|
.welcome = "language!",
|
||||||
.welcome_ = "Welcome to ",
|
.welcome_ = "Welcome to ",
|
||||||
.for_more = "for more information",
|
.for_more = "for more information",
|
||||||
|
.s_and_v = "Silent and verbose mode cannot be used together!",
|
||||||
.try_h = "Try",
|
.try_h = "Try",
|
||||||
.usage_head = "Usage",
|
.usage_head = "Usage",
|
||||||
.depr_opt_str = "DEPRECATED OPTION",
|
.depr_opt_str = "DEPRECATED OPTION",
|
||||||
@@ -86,26 +92,26 @@ struct pmt_langdb_general en = {
|
|||||||
.compiler_str = "Compiler",
|
.compiler_str = "Compiler",
|
||||||
.version_str = "version",
|
.version_str = "version",
|
||||||
.bin_str = "binary",
|
.bin_str = "binary",
|
||||||
|
.fs_str = "Filesystem",
|
||||||
.unknw_str = "unknown",
|
.unknw_str = "unknown",
|
||||||
.by_str = "By"
|
.by_str = "By"
|
||||||
};
|
};
|
||||||
|
|
||||||
struct pmt_langdb_general tr = {
|
struct langdb_general LangTr = {
|
||||||
.lang_by_s = "YZBruh",
|
.lang_by_s = "YZBruh",
|
||||||
.language = "Türkçe",
|
.language = "Türkçe",
|
||||||
.lang_prefix = "tr",
|
.lang_prefix = "tr",
|
||||||
.not_logical = "Bu cihaz mantıksal (logical) bölümlere sahip değil!",
|
.not_logical = "Bu cihaz mantıksal (logical) bölümlere sahip değil!",
|
||||||
.not_file = "Bu bir dosya değil",
|
.not_file = "Bu bir dosya değil",
|
||||||
.not_dir = "Bu bir dizin değil",
|
.not_dir = "Bu bir dizin değil",
|
||||||
.not_in_dev = "Bu bir şakamı? Bunun /dev dizini ile bi r ilgisi yok (içermiyor). Bu hatayla karşılaşmak istemiyorsanız zorlama (force) modu kullanın.",
|
.not_in_dev = "Bu bir şakamı? Bunun /dev dizini ile bir ilgisi yok (içermiyor). Bu hatayla karşılaşmak istemiyorsanız zorlama (force) modu kullanın.",
|
||||||
.not_open = "Açılamıyor",
|
.not_open = "Açılamıyor",
|
||||||
.not_block = "Belirtilen bölüm bir blok değil. Yani aslında bu bir bölüm bile değil (disk). Bu hatayı almak için şanslı olmak gerek..!",
|
.not_block = "Belirtilen bölüm bir blok değil. Yani aslında bu bir bölüm bile değil (disk). Bu hatayı almak için şanslı olmak gerek..! Bu hatayla karşılaşmak istemiyorsanız zorlama (force) modu kullanın.",
|
||||||
.not_read = "Veri okunamıyor",
|
.not_read = "Veri okunamıyor",
|
||||||
.not_readdir = "Dizin verisi okunamıyor",
|
.not_readdir = "Dizin verisi okunamıyor",
|
||||||
.not_write = "Veri yazılamıyor",
|
.not_write = "Veri yazılamıyor",
|
||||||
.not_gen = "Oluşturulamıyor",
|
.not_gen = "Oluşturulamıyor",
|
||||||
.no_root = "Root erişimi tespit edilemedi! Lütfen root erişimi ile çalıştırın.",
|
.no_root = "Root erişimi tespit edilemedi! Lütfen root erişimi ile çalıştırın.",
|
||||||
.no_target = "Hedef işlem yok (yedek, flaş veya format).",
|
|
||||||
.expected_backup_arg = "Beklenen yedekleme argümanı 2 (bir tanesi zorunlu değil), alınan",
|
.expected_backup_arg = "Beklenen yedekleme argümanı 2 (bir tanesi zorunlu değil), alınan",
|
||||||
.expected_flash_arg = "Beklenen flaş argümanı 2, alınan",
|
.expected_flash_arg = "Beklenen flaş argümanı 2, alınan",
|
||||||
.expected_format_arg = "Beklenen format argümanı 2, alınan",
|
.expected_format_arg = "Beklenen format argümanı 2, alınan",
|
||||||
@@ -113,10 +119,10 @@ struct pmt_langdb_general tr = {
|
|||||||
.multiple_wiewers = "Birden fazla görüntüleme işlemi yapan fonksiyonlar bir arada kullanılamaz. Aynı anda sadece bir tanesi kullanılabilir.",
|
.multiple_wiewers = "Birden fazla görüntüleme işlemi yapan fonksiyonlar bir arada kullanılamaz. Aynı anda sadece bir tanesi kullanılabilir.",
|
||||||
.common_symbol_rule = "Bir seçeneğin argümanını verirken argüman önüne '-' sembolü getirilemez. Sembolü kaldırın ve tekrar deneyin.",
|
.common_symbol_rule = "Bir seçeneğin argümanını verirken argüman önüne '-' sembolü getirilemez. Sembolü kaldırın ve tekrar deneyin.",
|
||||||
.req_part_name = "Bölüm adı gereklidir.",
|
.req_part_name = "Bölüm adı gereklidir.",
|
||||||
.part_not_found = "Bölüm bulunamadı!",
|
.part_not_found = "Bölüm bulunamadı! Belki mantıksal (logical) bir bölümdür?",
|
||||||
.unsupported_fs = "Formatlayıcı: desteklenmeyen dosya sistemi:",
|
.unsupported_fs = "Formatlayıcı: desteklenmeyen dosya sistemi:",
|
||||||
.cannot_stat = "Durumu tespit edilemedi",
|
.cannot_stat = "Durumu tespit edilemedi",
|
||||||
.ffile_more_part = "Flaşlanacak dosyanın boyutu mevcut bölüm boyutundan fazla.",
|
.ffile_more_part = "Flaşlanacak dosyanın boyutu mevcut bölüm boyutundan fazla. Bu hatayla karşılaşmak istemiyorsanız zorlama (force) modu kullanın (bunu yapmanız asla önerilmez).",
|
||||||
.cannot_get_bsz = "Bölüm blok boyutu tespit edilemedi!",
|
.cannot_get_bsz = "Bölüm blok boyutu tespit edilemedi!",
|
||||||
.format_fail = "Formatlama başarısız oldu. Bazı şeyler zarar görmüş olabilir!",
|
.format_fail = "Formatlama başarısız oldu. Bazı şeyler zarar görmüş olabilir!",
|
||||||
.depr_backup_opt = "Yedek için artık bu seçeneği kullanamazsınız.",
|
.depr_backup_opt = "Yedek için artık bu seçeneği kullanamazsınız.",
|
||||||
@@ -124,25 +130,33 @@ struct pmt_langdb_general tr = {
|
|||||||
.depr_format_opt = "Formatlama için artıi bu seçeneği kullanamazsınız.",
|
.depr_format_opt = "Formatlama için artıi bu seçeneği kullanamazsınız.",
|
||||||
.depr_Vlicense_opt = "Gereksiz seçeneklere bellek yok!",
|
.depr_Vlicense_opt = "Gereksiz seçeneklere bellek yok!",
|
||||||
.depr_ch_list_opt = "Listeleme için -p seçeneğini kullanabilirsiniz.",
|
.depr_ch_list_opt = "Listeleme için -p seçeneğini kullanabilirsiniz.",
|
||||||
.logical_warn = "Uyarı: bu cihaz mantıksal (logical) bölümlere sahip.",
|
.logical_warn = "Bu cihaz mantıksal (logical) bölümlere sahip.",
|
||||||
.not_spec_opt = "Seçenek değil, gerekli argümanları belirtin",
|
.not_spec_opt = "Seçenek değil, gerekli argümanları verin",
|
||||||
.ab_warn = "Uyarı: bu cihazın bazı bölümleri A/B kullanıyor.",
|
.some_spec = "Seçenek belirtmiş olabilirsiniz fakat, ana işlem belirtmedikçe pek işe yaramazlar",
|
||||||
.out_not_spec = "Uyarı: çıktı dosya belirtilmedi. Çıktı dosya adı bölüm adına göre belirlenecek.",
|
.ab_warn = "Bu cihazın bazı bölümleri A/B kullanıyor.",
|
||||||
|
.out_not_spec = "Çıktı dosya adı belirtilmedi. Oluşturulan çıktı adı",
|
||||||
.please_rerun = "Lütfen yeniden çalıştırın",
|
.please_rerun = "Lütfen yeniden çalıştırın",
|
||||||
.part_disk_sz = "Bölümün disk boyutu",
|
.part_disk_sz = "Bölümün (yedek) boyutu",
|
||||||
.flash_file_sz = "Flaşlanacak dosyanın boyutu",
|
.flash_file_sz = "Flaşlanacak dosyanın boyutu",
|
||||||
.flash_file_sz_fail = "Uyarı: flaşlanacak dosyanın boyutu tespit edilemedi.",
|
.flash_file_sz_fail = "Uyarı: flaşlanacak dosyanın boyutu tespit edilemedi.",
|
||||||
.part_disk_sz_fail = "Uyarı: bölüm boyutunun boyutu tespit edilemedi.",
|
.part_disk_sz_fail = "Uyarı: bölüm boyutunun boyutu tespit edilemedi.",
|
||||||
.unknown_opr = "Bilinmeyen işlem",
|
.unknown_opr = "Bilinmeyen işlem",
|
||||||
.list_of_dir = "Dizin içeriğinin listesi",
|
.req_an_arg = "bu seçenek argüman gerektirir",
|
||||||
|
.list_of_general = "Genel bölümlerin listesi",
|
||||||
|
.list_of_logc = "Mantıksal (logical) bölümlerin listesi",
|
||||||
.success_backup = "Başarılı. Çıktı",
|
.success_backup = "Başarılı. Çıktı",
|
||||||
.success_flash = "Başarılı.",
|
.success_flash = "Başarılı.",
|
||||||
|
.success_format = "Formatlama başarılı",
|
||||||
|
.formatting = "Formatlanıyor",
|
||||||
.warn = "UYARI",
|
.warn = "UYARI",
|
||||||
.fatal = "KRİTİK HATA",
|
.fatal = "KRİTİK HATA",
|
||||||
|
.is_requires_arg = "bir argüman gereklidir",
|
||||||
|
.unknw_arg = "bilinmeyen seçenek",
|
||||||
.switching_lang = "Dil değiştiriliyor...",
|
.switching_lang = "Dil değiştiriliyor...",
|
||||||
.welcome = "diline hoş geldiniz!",
|
.welcome = "diline hoş geldiniz!",
|
||||||
.welcome_ = NULL,
|
.welcome_ = NULL,
|
||||||
.for_more = "komutunu kullanabilirsiniz",
|
.for_more = "komutunu kullanabilirsiniz",
|
||||||
|
.s_and_v = "Sessiz ve ayrıntılı günlüklenme aynı anda kullanılamaz!",
|
||||||
.try_h = "Daha fazla bilgi",
|
.try_h = "Daha fazla bilgi",
|
||||||
.usage_head = "Kullanımı",
|
.usage_head = "Kullanımı",
|
||||||
.depr_opt_str = "KALDIRILMIŞ SEÇENEK",
|
.depr_opt_str = "KALDIRILMIŞ SEÇENEK",
|
||||||
@@ -151,56 +165,52 @@ struct pmt_langdb_general tr = {
|
|||||||
.compiler_str = "Derleyici",
|
.compiler_str = "Derleyici",
|
||||||
.version_str = "versiyon",
|
.version_str = "versiyon",
|
||||||
.bin_str = "yapı",
|
.bin_str = "yapı",
|
||||||
|
.fs_str = "Dosya sistemi",
|
||||||
.unknw_str = "bilinmeyen",
|
.unknw_str = "bilinmeyen",
|
||||||
.by_str = "Çeviriyi yapan(lar):"
|
.by_str = "Çeviriyi yapan(lar):"
|
||||||
};
|
};
|
||||||
|
|
||||||
struct pmt_langdb_docs en_docs = {
|
struct langdb_docs LangDocEn = {
|
||||||
.docs_strs_l1 = "backup PARTITION [OUTPUT] [OPTIONS]...",
|
.docs_strs_l1 = "[OPTIONS] backup PARTITION [OUTPUT] [OPTIONS]...",
|
||||||
.docs_strs_l2 = "flash PARTITION FILE [OPTIONS]...",
|
.docs_strs_l2 = "[OPTIONS] flash PARTITION FILE [OPTIONS]...",
|
||||||
.docs_strs_l3 = "format PARTITION FILE_SYSTEM[ext/2/3/4] [OPTIONS]...",
|
.docs_strs_l3 = "[OPTIONS] format PARTITION FILE_SYSTEM[ext/2/3/4] [OPTIONS]...",
|
||||||
.docs_strs_l4 = "Options",
|
.docs_strs_l4 = "Options",
|
||||||
.docs_strs_l5 = "It is meant to determine whether the target partition is logical.",
|
.docs_strs_l5 = "It is meant to determine whether the target partition is logical.",
|
||||||
.docs_strs_l6 = "It is meant to specify a custom /dev context. Only classic partitions (default: /dev/block/by-name).",
|
.docs_strs_l6 = "It is meant to specify a custom /dev context. Only normal partitions (default: /dev/block/by-name).",
|
||||||
.docs_strs_l7 = "List partitions.",
|
.docs_strs_l7 = "List partitions.",
|
||||||
.docs_strs_l8 = "Information and warning messages are silenced in normal work.",
|
.docs_strs_l8 = "Information and warning messages are silenced in normal work.",
|
||||||
.docs_strs_l9 = "Force mode. Some things are ignored.",
|
.docs_strs_l9 = "Force mode. Some things are ignored.",
|
||||||
.docs_strs_l10 = "Set current language.",
|
.docs_strs_l10 = "Verbose mode. Print detailed informations etc.",
|
||||||
.docs_strs_l11 = "See version.",
|
.docs_strs_l11 = "Set current language.",
|
||||||
.docs_strs_l12 = "See this help message.",
|
.docs_strs_l12 = "See version.",
|
||||||
.docs_strs_l13 = "Examples",
|
.docs_strs_l13 = "See this help message.",
|
||||||
.docs_strs_l14 = "Report bugs to",
|
.docs_strs_l14 = "Examples",
|
||||||
|
.docs_strs_l15 = "Report bugs and suggestions to",
|
||||||
.or_str = "or",
|
.or_str = "or",
|
||||||
.usage_docstr = "Usage"
|
.usage_docstr = "Usage"
|
||||||
};
|
};
|
||||||
|
|
||||||
struct pmt_langdb_docs tr_docs = {
|
struct langdb_docs LangDocTr = {
|
||||||
.docs_strs_l1 = "backup BÖLÜM [ÇIKTI] [SEÇENEKLER]...",
|
.docs_strs_l1 = "[SEÇENEKLER] backup BÖLÜM [ÇIKTI] [SEÇENEKLER]...",
|
||||||
.docs_strs_l2 = "flash BÖLÜM DOSYA [SEÇENEKLER]...",
|
.docs_strs_l2 = "[SEÇENEKLER] flash BÖLÜM DOSYA [SEÇENEKLER]...",
|
||||||
.docs_strs_l3 = "format BÖLÜM DOSYA_SİSTEMİ[ext/2/3/4] [SEÇENEKLER]...",
|
.docs_strs_l3 = "[SEÇENEKLER] format BÖLÜM DOSYA_SİSTEMİ[ext/2/3/4] [SEÇENEKLER]...",
|
||||||
.docs_strs_l4 = "Seçenekler",
|
.docs_strs_l4 = "Seçenekler",
|
||||||
.docs_strs_l5 = "Mantıksal (logical) bölüm ile işlem yapın.",
|
.docs_strs_l5 = "Mantıksal (logical) bölüm ile işlem yapın.",
|
||||||
.docs_strs_l6 = "Özel /dev bağlamı belirtin. Sadece normal bölümler içindir (Varsayılan: /dev/block/by-name).",
|
.docs_strs_l6 = "Özel /dev bağlamı belirtin. Sadece normal bölümler içindir (Varsayılan: /dev/block/by-name).",
|
||||||
.docs_strs_l7 = "Bölümler listelenir.",
|
.docs_strs_l7 = "Bölümler listelenir.",
|
||||||
.docs_strs_l8 = "Bilgi ve uyarı mesajları susturulur.",
|
.docs_strs_l8 = "Bilgi ve uyarı mesajları susturulur.",
|
||||||
.docs_strs_l9 = "Zorlama modu. Bazı şeyler göz ardı edilir.",
|
.docs_strs_l9 = "Zorlama modu. Bazı şeyler göz ardı edilir.",
|
||||||
.docs_strs_l10 = "Mevcut dili ayarlayın.",
|
.docs_strs_l10 = "Ayrıntılı bilgi modu. Daha fazla bilgi mesajı verilir.",
|
||||||
.docs_strs_l11 = "Sürümü görüntüleyin.",
|
.docs_strs_l11 = "Mevcut dili ayarlayın.",
|
||||||
.docs_strs_l12 = "Bu yardım mesajını görüntüleyin.",
|
.docs_strs_l12 = "Sürümü görüntüleyin.",
|
||||||
.docs_strs_l13 = "Örnekler",
|
.docs_strs_l13 = "Bu yardım mesajını görüntüleyin.",
|
||||||
.docs_strs_l14 = "Sorunları şu adrese bildirin:",
|
.docs_strs_l14 = "Örnekler",
|
||||||
|
.docs_strs_l15 = "Sorunları ve önerileri şuraya bildirin:",
|
||||||
.or_str = "yada",
|
.or_str = "yada",
|
||||||
.usage_docstr = "Kullanımı"
|
.usage_docstr = "Kullanımı"
|
||||||
};
|
};
|
||||||
|
|
||||||
struct pmt_langdb_langs lang[] = {
|
} /* namespace Display */
|
||||||
{"en"},
|
} /* namespace PartitionManager */
|
||||||
{"tr"},
|
|
||||||
{NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* end of code */
|
/* end of code */
|
||||||
131
jni/ListPartitions.cpp
Executable file
131
jni/ListPartitions.cpp
Executable file
@@ -0,0 +1,131 @@
|
|||||||
|
/* By YZBruh */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright 2024 Partition Manager
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define INC_MAIN_LIBS
|
||||||
|
#define INC_DEBUGERS
|
||||||
|
#define INC_DIRENT
|
||||||
|
#define INC_STRINGKEYS
|
||||||
|
|
||||||
|
#include <PartitionManager/PartitionManager.h>
|
||||||
|
|
||||||
|
using namespace PartitionManager;
|
||||||
|
|
||||||
|
#define CUR_DEV_CNTX "/dev/block/by-name"
|
||||||
|
#define LGC_DEV_CNTX "/dev/block/mapper"
|
||||||
|
|
||||||
|
static DIR *dir;
|
||||||
|
|
||||||
|
static int
|
||||||
|
list(const string& operation, const char* target_dir)
|
||||||
|
{
|
||||||
|
static int count;
|
||||||
|
struct dirent **list;
|
||||||
|
bool list_parts = (operation == "print") ? true : false;
|
||||||
|
|
||||||
|
dir = nullptr;
|
||||||
|
dir = opendir(target_dir);
|
||||||
|
|
||||||
|
if (list_parts)
|
||||||
|
{
|
||||||
|
count = scandir(target_dir, &list, nullptr, alphasort);
|
||||||
|
|
||||||
|
if (count < 0)
|
||||||
|
LOGE("%s: `%s': %s\n", Display::UsingDispString->not_readdir, target_dir, strqerror());
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
if (list[i]->d_name[0] != '.' \
|
||||||
|
&& strncmp(list[i]->d_name, "com.", 4) != 0 \
|
||||||
|
&& strcmp(list[i]->d_name, "by-uuid") != 0 \
|
||||||
|
&& strcmp(list[i]->d_name, "userdata") != 0)
|
||||||
|
LOGD(" - [ %-16s ]\n", list[i]->d_name);
|
||||||
|
|
||||||
|
free(list[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(list);
|
||||||
|
list = nullptr;
|
||||||
|
|
||||||
|
goto directory;
|
||||||
|
}
|
||||||
|
|
||||||
|
directory:
|
||||||
|
if (dir != nullptr)
|
||||||
|
{
|
||||||
|
closedir(dir);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* list existing partitions */
|
||||||
|
int Functions::ListPartitions(void)
|
||||||
|
{
|
||||||
|
VLOGD("ListPartitions: selecting context...\n");
|
||||||
|
string acc_cxt = (Booleans::UseCustomContext) ? Strings::CustomContext : CUR_DEV_CNTX;
|
||||||
|
|
||||||
|
VLOGD("ListPartitions: trying to access `%s'...\n", acc_cxt.c_str());
|
||||||
|
if (list("access", acc_cxt.c_str()) != 0)
|
||||||
|
{
|
||||||
|
if (!Booleans::ForceMode)
|
||||||
|
LOGE("%s: `%s': %s\n", Display::UsingDispString->not_open, acc_cxt.c_str(), strqerror());
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOGD("%s:\n", Display::UsingDispString->list_of_general);
|
||||||
|
list("print", acc_cxt.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Booleans::UsesLogical)
|
||||||
|
{
|
||||||
|
VLOGD("ListPartitions: checking for listing `%s'...\n", LGC_DEV_CNTX);
|
||||||
|
|
||||||
|
if (list("access", LGC_DEV_CNTX) != 0)
|
||||||
|
LOGE("%s: `%s': %s\n", Display::UsingDispString->not_open, LGC_DEV_CNTX, strqerror());
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOGD("\n%s:\n", Display::UsingDispString->list_of_logc);
|
||||||
|
list("print", LGC_DEV_CNTX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VLOGD("ListPartitions: (if have) warnings are printed...\n");
|
||||||
|
|
||||||
|
if (Booleans::UsesLogical)
|
||||||
|
{
|
||||||
|
LOGD("\n");
|
||||||
|
LOGW("%s\n", Display::UsingDispString->logical_warn);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Booleans::UsesSlots)
|
||||||
|
{
|
||||||
|
if (!Booleans::UsesSlots)
|
||||||
|
LOGD("\n");
|
||||||
|
|
||||||
|
LOGW("%s\n", Display::UsingDispString->ab_warn);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* end of code */
|
||||||
97
jni/Makefile
97
jni/Makefile
@@ -31,34 +31,37 @@ PMT_INCDIR := $(INCLUDE_DIR)/pmt
|
|||||||
|
|
||||||
# the presence of all source files that are on this list will be checked
|
# the presence of all source files that are on this list will be checked
|
||||||
SRCS_REQ := \
|
SRCS_REQ := \
|
||||||
place-holder/debug.c \
|
place-holder/Debug.cpp \
|
||||||
place-holder/help.c \
|
place-holder/Help.cpp \
|
||||||
place-holder/get_stat.c \
|
place-holder/GetState.cpp \
|
||||||
place-holder/lang_tools.c \
|
place-holder/LanguageTools.cpp \
|
||||||
place-holder/languages.c \
|
place-holder/Languages.cpp \
|
||||||
place-holder/partitiontool.c \
|
place-holder/PartitionTool.cpp \
|
||||||
place-holder/pmt.c \
|
place-holder/PartitionManager.cpp \
|
||||||
place-holder/root.c \
|
place-holder/Root.cpp \
|
||||||
place-holder/tools.c \
|
place-holder/Tools.cpp \
|
||||||
place-holder/version.c
|
place-holder/Version.cpp
|
||||||
|
|
||||||
# objects to be used when executable file is created
|
# objects to be used when executable file is created
|
||||||
OBJS_EXEC := \
|
OBJS_EXEC := \
|
||||||
$(SOURCE_DIR)/$(TARGET).o \
|
$(SOURCE_DIR)/Debug.o \
|
||||||
$(SOURCE_DIR)/help.o \
|
$(SOURCE_DIR)/Root.o \
|
||||||
$(SOURCE_DIR)/version.o \
|
$(SOURCE_DIR)/PartitionManager.o \
|
||||||
$(SOURCE_DIR)/get_stat.o \
|
$(SOURCE_DIR)/PartitionTool.o \
|
||||||
$(SOURCE_DIR)/tools.o \
|
$(SOURCE_DIR)/ListPartitions.o \
|
||||||
$(SOURCE_DIR)/lang_tools.o \
|
$(SOURCE_DIR)/Help.o \
|
||||||
$(SOURCE_DIR)/languages.o
|
$(SOURCE_DIR)/Version.o \
|
||||||
|
$(SOURCE_DIR)/GetState.o \
|
||||||
|
$(SOURCE_DIR)/Tools.o \
|
||||||
|
$(SOURCE_DIR)/Languages.o \
|
||||||
|
$(SOURCE_DIR)/LanguageTools.o
|
||||||
|
|
||||||
HEADERS_REQ := \
|
HEADERS_REQ := \
|
||||||
$(PMT_INCDIR)/pmt/ExternC.h \
|
$(PMT_INCDIR)/PartitionManager/Deprecates.h \
|
||||||
$(PMT_INCDIR)/pmt/Deprecates.h \
|
$(PMT_INCDIR)/PartitionManager/HelpFn.h \
|
||||||
$(PMT_INCDIR)/pmt/HelpMessages.h \
|
$(PMT_INCDIR)/PartitionManager/PartitionManager.h \
|
||||||
$(PMT_INCDIR)/pmt/PartitionManager.h \
|
$(PMT_INCDIR)/PartitionManager/StringKeys.h \
|
||||||
$(PMT_INCDIR)/pmt/StringKeys.h \
|
$(PMT_INCDIR)/PartitionManager/VersionFnVars.h
|
||||||
$(PMT_INCDIR)/pmt/VersionVars.h
|
|
||||||
|
|
||||||
PROGRESS_LIST := \
|
PROGRESS_LIST := \
|
||||||
welcome \
|
welcome \
|
||||||
@@ -68,18 +71,10 @@ PROGRESS_LIST := \
|
|||||||
pr_obj \
|
pr_obj \
|
||||||
$(OBJS) \
|
$(OBJS) \
|
||||||
make_outdirs \
|
make_outdirs \
|
||||||
pr_sts \
|
|
||||||
$(STATIC_LIBS) \
|
|
||||||
make_executable \
|
make_executable \
|
||||||
wait \
|
wait \
|
||||||
end_progress
|
end_progress
|
||||||
|
|
||||||
define check_hf
|
|
||||||
@ [ ! -f "$1" ] \
|
|
||||||
&& $(E_NS) " ==> Couldn't found required header file: include/pmt/`basename $1`" \
|
|
||||||
&& exit 1
|
|
||||||
endef
|
|
||||||
|
|
||||||
# all target for building
|
# all target for building
|
||||||
all: $(PROGRESS_LIST)
|
all: $(PROGRESS_LIST)
|
||||||
|
|
||||||
@@ -92,29 +87,20 @@ welcome:
|
|||||||
&& $(E_NS)
|
&& $(E_NS)
|
||||||
$(E) " -------------------------------- " \
|
$(E) " -------------------------------- " \
|
||||||
&& $(E_NS)
|
&& $(E_NS)
|
||||||
@ if [ -f $(SOURCE_DIR)/debug.o ]; then \
|
|
||||||
$(E_NS) " - Please clean up before you build it." && echo; \
|
|
||||||
$(E_NS) " ----------------------------------- "; \
|
|
||||||
exit 1; \
|
|
||||||
fi
|
|
||||||
$(E) " - Checking required source files..."
|
$(E) " - Checking required source files..."
|
||||||
|
|
||||||
pr_obj:
|
pr_obj:
|
||||||
$(E) " - Building objects..."
|
$(E) " - Building objects..."
|
||||||
|
|
||||||
pr_sts:
|
|
||||||
$(E) " - Making static libraries..."
|
|
||||||
|
|
||||||
wait:
|
wait:
|
||||||
@ sleep 2
|
@ sleep 2
|
||||||
|
|
||||||
make_outdirs:
|
make_outdirs:
|
||||||
@ rm -rf $(IN_OUT_DIR)
|
@ rm -rf $(IN_OUT_DIR)
|
||||||
@ mkdir $(BINARY_DIR)
|
@ mkdir -p $(BINARY_DIR)
|
||||||
@ mkdir $(PACKAGE_DIR)
|
@ mkdir -p $(PACKAGE_DIR)
|
||||||
@ mkdir $(STATICLIB_DIR)
|
|
||||||
|
|
||||||
place-holder/%.c:
|
place-holder/%.cpp:
|
||||||
$(E) " CHK $(SOURCE_DIRNAME)/`basename $@`"
|
$(E) " CHK $(SOURCE_DIRNAME)/`basename $@`"
|
||||||
@ if [ ! -f "$(SOURCE_DIR)/`basename $@`" ]; then \
|
@ if [ ! -f "$(SOURCE_DIR)/`basename $@`" ]; then \
|
||||||
$(E_NS) " ==> Couldn't found required source file: $(SOURCE_DIRNAME)/`basename $@`"; \
|
$(E_NS) " ==> Couldn't found required source file: $(SOURCE_DIRNAME)/`basename $@`"; \
|
||||||
@@ -122,24 +108,20 @@ place-holder/%.c:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
$(PMT_INCDIR)/%.h:
|
$(PMT_INCDIR)/%.h:
|
||||||
$(E) " CHK include/pmt/`basename $@`"
|
$(E) " CHK include/PartitionManager/`basename $@`"
|
||||||
@ if [ ! -f "$(INCLUDE_DIR)/pmt/`basename $@`" ]; then \
|
@ if [ ! -f "$(INCLUDE_DIR)/PartitionManager/`basename $@`" ]; then \
|
||||||
$(E_NS) " ==> Couldn't found required header file: include/pmt/`basename $@`"; \
|
$(E_NS) " ==> Couldn't found required header file: include/PartitionManager/`basename $@`"; \
|
||||||
exit 1; \
|
exit 1; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$(SOURCE_DIR)/%.o: $(SOURCE_DIR)/%.c
|
$(SOURCE_DIR)/%.o: $(SOURCE_DIR)/%.cpp
|
||||||
$(E) " CC $(SOURCE_DIRNAME)/`basename $@`"
|
$(E) " CXX $(SOURCE_DIRNAME)/`basename $@`"
|
||||||
@ $(CC) $(CFLAGS) -c "$<" || exit 1
|
@ $(CXX) -x c++ $(CXXFLAGS) -c "$<" || exit 1
|
||||||
|
|
||||||
$(TARGET)_%:
|
|
||||||
$(E) " AR lib$@.a"
|
|
||||||
@ $(AR) rcs "lib$@.a" "$(SOURCE_DIR)/$$(echo "$@" | cut -d'_' -f2).o"
|
|
||||||
|
|
||||||
make_executable:
|
make_executable:
|
||||||
$(E) " - Making executable file..."
|
$(E) " - Making executable file..."
|
||||||
$(E) " LD $(TARGET)"
|
$(E) " LD $(TARGET)"
|
||||||
@ $(CC) $(CFLAGS) -L$(SOURCE_DIR) $(foreach st,$(STATIC_LIBS),$(shell echo -n -l$(st) )) -o $(TARGET) $(OBJS_EXEC) || exit 1
|
@ $(CXX) $(CXXFLAGS) -o $(TARGET) $(OBJS_EXEC) || exit 1
|
||||||
|
|
||||||
end_progress:
|
end_progress:
|
||||||
@ abort_build() { \
|
@ abort_build() { \
|
||||||
@@ -152,7 +134,6 @@ end_progress:
|
|||||||
exit 1; \
|
exit 1; \
|
||||||
}; \
|
}; \
|
||||||
mv $(TARGET) $(BINARY_DIR) || abort_build; \
|
mv $(TARGET) $(BINARY_DIR) || abort_build; \
|
||||||
mv *.a $(STATICLIB_DIR) || abort_build; \
|
|
||||||
$(E_NS) " - Generating package..."; \
|
$(E_NS) " - Generating package..."; \
|
||||||
cp $(BINARY_DIR)/$(TARGET) $(PACKAGE_DIR) || abort_build; \
|
cp $(BINARY_DIR)/$(TARGET) $(PACKAGE_DIR) || abort_build; \
|
||||||
$(E_NS) " XZ $(OUT_DIRNAME)/package/$(TARGET)-`date +%Y%m%d`.xz"
|
$(E_NS) " XZ $(OUT_DIRNAME)/package/$(TARGET)-`date +%Y%m%d`.xz"
|
||||||
@@ -165,7 +146,6 @@ end_progress:
|
|||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
$(eval STATICLIBS = $(wildcard $(SOURCE_DIR)/*.a))
|
|
||||||
$(eval OBJS = $(wildcard $(SOURCE_DIR)/*.o))
|
$(eval OBJS = $(wildcard $(SOURCE_DIR)/*.o))
|
||||||
$(info Cleaning files...)
|
$(info Cleaning files...)
|
||||||
$(foreach obj, \
|
$(foreach obj, \
|
||||||
@@ -173,10 +153,5 @@ clean:
|
|||||||
$(call m_stat_nn,$(SOURCE_DIRNAME)/$(shell basename $(obj))) \
|
$(call m_stat_nn,$(SOURCE_DIRNAME)/$(shell basename $(obj))) \
|
||||||
$(call erase,$(obj)) \
|
$(call erase,$(obj)) \
|
||||||
)
|
)
|
||||||
$(foreach lib, \
|
|
||||||
$(STATICLIBS), \
|
|
||||||
$(call m_stat_nn,$(SOURCE_DIRNAME)/$(shell basename $(lib))) \
|
|
||||||
$(call erase,$(lib)) \
|
|
||||||
)
|
|
||||||
|
|
||||||
# end
|
# end
|
||||||
703
jni/PartitionManager.cpp
Executable file
703
jni/PartitionManager.cpp
Executable file
@@ -0,0 +1,703 @@
|
|||||||
|
/* By YZBruh */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright 2024 Partition Manager
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define INC_MAIN_LIBS
|
||||||
|
#define INC_DEBUGERS
|
||||||
|
#define INC_STAT
|
||||||
|
#define INC_LIBGEN
|
||||||
|
#define INC_STRINGKEYS
|
||||||
|
|
||||||
|
#include <PartitionManager/PartitionManager.h>
|
||||||
|
#include <PartitionManager/Deprecates.h>
|
||||||
|
#include <PartitionManager/HelpFn.h>
|
||||||
|
#include <PartitionManager/VersionFnVars.h>
|
||||||
|
|
||||||
|
/* add value to variables that are added globally and are not worth */
|
||||||
|
namespace PartitionManager {
|
||||||
|
namespace Strings {
|
||||||
|
string OutputName = "";
|
||||||
|
string CustomContext = "";
|
||||||
|
string TargetPartition = "";
|
||||||
|
string TargetFlashFile = "";
|
||||||
|
string TargetFormatFS = "";
|
||||||
|
string PartitionType = "";
|
||||||
|
string ExecutingName = "";
|
||||||
|
string CurrentLanguage = "";
|
||||||
|
} /* namespace Strings */
|
||||||
|
|
||||||
|
namespace Booleans {
|
||||||
|
bool UseLogical = false;
|
||||||
|
bool UseCustomContext = false;
|
||||||
|
bool UsesSlots = false;
|
||||||
|
bool UsesLogical = false;
|
||||||
|
bool SilentEnabled = false;
|
||||||
|
bool FlashMode = false;
|
||||||
|
bool BackupMode = false;
|
||||||
|
bool FormatMode = false;
|
||||||
|
bool ForceMode = false;
|
||||||
|
bool VerboseMode = false;
|
||||||
|
bool InstalledOnTermux = false;
|
||||||
|
bool ActivateRoot = false;
|
||||||
|
} /* namespace Booleans */
|
||||||
|
} /* namespace PartitionManager */
|
||||||
|
|
||||||
|
/* variable for use in control of '-' expression */
|
||||||
|
static string common_symbol_rule;
|
||||||
|
|
||||||
|
namespace PartitionManager {
|
||||||
|
namespace Functions {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* He controls whether the '-' sign at
|
||||||
|
* the beginning of the given word
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
CheckOptSymbol(const string symbol)
|
||||||
|
{
|
||||||
|
if (!symbol.empty())
|
||||||
|
{
|
||||||
|
if (strncmp(symbol.c_str(), "-", 1) == 0)
|
||||||
|
LOGE("%s\n", common_symbol_rule.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
ControlArg(const char* argv_holder)
|
||||||
|
{
|
||||||
|
if (argv_holder[0] != '-')
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* namespace Functions */
|
||||||
|
} /* namespace PartitionManager */
|
||||||
|
|
||||||
|
static void
|
||||||
|
deprecated(const char opt, const char* deprecation_message, const char* opt_long = "ISNULL")
|
||||||
|
{
|
||||||
|
VLOGE("Deprecated Option: -%c (--%s). Printing error...\n", opt, opt_long);
|
||||||
|
DEPR_HANDLE(opt, opt_long, deprecation_message);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
PrContextInput(const string& context)
|
||||||
|
{
|
||||||
|
PartitionManager::Booleans::UseCustomContext = true;
|
||||||
|
PartitionManager::Strings::CustomContext = context;
|
||||||
|
PartitionManager::Functions::CheckOptSymbol(PartitionManager::Strings::CustomContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
using namespace PartitionManager;
|
||||||
|
|
||||||
|
class PartitionManagerBase {
|
||||||
|
protected:
|
||||||
|
char* BaseFunctionName = nullptr;
|
||||||
|
int StartCode = -1;
|
||||||
|
bool IsRequiredOnlyOneArg = false;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void CallTargetBaseFunction(void)
|
||||||
|
{
|
||||||
|
VLOGD("CallTargetBaseFunction [class]: Start(%d)\n", StartCode);
|
||||||
|
Functions::Start(StartCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GenericNumericalController(int searchOn, int total, const char* MissingArgMessage)
|
||||||
|
{
|
||||||
|
if (total <= searchOn)
|
||||||
|
{
|
||||||
|
VLOGE("ArgumentProcessor [class]: Missing argument total (for %s function).\n", BaseFunctionName);
|
||||||
|
LOGE("%s 0.\n", MissingArgMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!IsRequiredOnlyOneArg)
|
||||||
|
{
|
||||||
|
if (total <= (searchOn + 1))
|
||||||
|
{
|
||||||
|
VLOGE("ArgumentProcessor [class]: Missing argument total (for %s function).\n", BaseFunctionName);
|
||||||
|
LOGE("%s 1.\n", MissingArgMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void ArgumentProcessor(int searchOn, int total, char** arguments) { /* dummy, it's place holder */ }
|
||||||
|
};
|
||||||
|
|
||||||
|
class PartitionManagerBackup : public PartitionManagerBase {
|
||||||
|
public:
|
||||||
|
void ArgumentProcessor(int searchOn, int total, char** arguments) override
|
||||||
|
{
|
||||||
|
BaseFunctionName = "backup";
|
||||||
|
StartCode = 1;
|
||||||
|
IsRequiredOnlyOneArg = true;
|
||||||
|
|
||||||
|
GenericNumericalController(searchOn, total, Display::UsingDispString->expected_backup_arg);
|
||||||
|
|
||||||
|
if (Functions::ControlArg(arguments[searchOn]))
|
||||||
|
Strings::TargetPartition = arguments[searchOn];
|
||||||
|
else
|
||||||
|
LOGE("%s.\n", Display::UsingDispString->not_spec_opt);
|
||||||
|
|
||||||
|
Strings::OutputName = Strings::TargetPartition;
|
||||||
|
|
||||||
|
if (total > (searchOn + 1) && Functions::ControlArg(arguments[(searchOn + 1)]))
|
||||||
|
{
|
||||||
|
VLOGD("ArgumentProcessor [class]: Non-mandatory argument was detected and retrieved (for %s function).\n", BaseFunctionName);
|
||||||
|
Strings::OutputName = arguments[(searchOn + 1)];
|
||||||
|
}
|
||||||
|
|
||||||
|
Functions::CheckOptSymbol(Strings::TargetPartition);
|
||||||
|
Functions::CheckOptSymbol(Strings::OutputName);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class PartitionManagerFlash : public PartitionManagerBase {
|
||||||
|
public:
|
||||||
|
void ArgumentProcessor(int searchOn, int total, char** arguments) override
|
||||||
|
{
|
||||||
|
BaseFunctionName = "flash";
|
||||||
|
StartCode = 2;
|
||||||
|
IsRequiredOnlyOneArg = false;
|
||||||
|
|
||||||
|
GenericNumericalController(searchOn, total, Display::UsingDispString->expected_flash_arg);
|
||||||
|
|
||||||
|
if (Functions::ControlArg(arguments[searchOn]))
|
||||||
|
Strings::TargetPartition = arguments[searchOn ];
|
||||||
|
else
|
||||||
|
LOGE("%s.\n", Display::UsingDispString->not_spec_opt);
|
||||||
|
|
||||||
|
if (Functions::ControlArg(arguments[(searchOn + 1)]))
|
||||||
|
Strings::TargetFlashFile = arguments[(searchOn + 1)];
|
||||||
|
else
|
||||||
|
LOGE("%s.\n", Display::UsingDispString->not_spec_opt);
|
||||||
|
|
||||||
|
Functions::CheckOptSymbol(Strings::TargetFlashFile);
|
||||||
|
Functions::CheckOptSymbol(Strings::TargetPartition);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class PartitionManagerFormat : public PartitionManagerBase {
|
||||||
|
public:
|
||||||
|
void ArgumentProcessor(int searchOn, int total, char** arguments) override
|
||||||
|
{
|
||||||
|
BaseFunctionName = "format";
|
||||||
|
StartCode = 3;
|
||||||
|
IsRequiredOnlyOneArg = false;
|
||||||
|
|
||||||
|
GenericNumericalController(searchOn, total, Display::UsingDispString->expected_format_arg);
|
||||||
|
|
||||||
|
if (Functions::ControlArg(arguments[searchOn]))
|
||||||
|
Strings::TargetPartition = arguments[searchOn];
|
||||||
|
else
|
||||||
|
LOGE("%s.\n", Display::UsingDispString->not_spec_opt);
|
||||||
|
|
||||||
|
if (Functions::ControlArg(arguments[(searchOn + 1)]))
|
||||||
|
Strings::TargetFormatFS = arguments[(searchOn + 1)];
|
||||||
|
else
|
||||||
|
LOGE("%s.\n", Display::UsingDispString->not_spec_opt);
|
||||||
|
|
||||||
|
Functions::CheckOptSymbol(Strings::TargetFormatFS);
|
||||||
|
Functions::CheckOptSymbol(Strings::TargetPartition);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
Strings::ExecutingName = basename(argv[0]);
|
||||||
|
|
||||||
|
for (int i = 0; i <= (argc - 1); i++)
|
||||||
|
{
|
||||||
|
if (strncmp(argv[i], "-V", 2) == 0 || strcmp(argv[i], "--verbose") == 0)
|
||||||
|
Booleans::VerboseMode = true;
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Generate classes */
|
||||||
|
VLOGD("Generating classes...\n");
|
||||||
|
PartitionManagerBase* Base;
|
||||||
|
PartitionManagerBase BaseTemplate;
|
||||||
|
PartitionManagerBackup BackupArgProcessorBase;
|
||||||
|
PartitionManagerFlash FlashArgProcessorBase;
|
||||||
|
PartitionManagerFormat FormatArgProcessorBase;
|
||||||
|
|
||||||
|
VLOGD("Main function started. Setting up locale. Calling 'setlocale <clocale>'\n");
|
||||||
|
setlocale(LC_ALL, "");
|
||||||
|
|
||||||
|
int argc_n = argc;
|
||||||
|
char buf[256];
|
||||||
|
char** args = argv;
|
||||||
|
|
||||||
|
VLOGD("Checking stdin status...\n");
|
||||||
|
if (!isatty(fileno(stdin)))
|
||||||
|
{
|
||||||
|
VLOGD("stdin is not empty.\n");
|
||||||
|
VLOGD("Parsing stdin arguments...\n");
|
||||||
|
|
||||||
|
while (fgets(buf, sizeof(buf), stdin) != nullptr)
|
||||||
|
{
|
||||||
|
buf[strcspn(buf, "\n")] = 0;
|
||||||
|
|
||||||
|
args[argc_n] = strdup(buf);
|
||||||
|
argc_n++;
|
||||||
|
}
|
||||||
|
|
||||||
|
VLOGD("Parsing completed.\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
VLOGD("stdin empty.\n");
|
||||||
|
|
||||||
|
/* load language */
|
||||||
|
VLOGD("Loading language... Calling LoadLanguage()...\n");
|
||||||
|
if (!Functions::LoadLanguage())
|
||||||
|
{
|
||||||
|
cout << "LoadLanguage() process failed..!" << endl;
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
common_symbol_rule = Display::UsingDispString->common_symbol_rule;
|
||||||
|
argc = argc_n;
|
||||||
|
int argc_parse = (argc - 1);
|
||||||
|
char** args_ctrl = args;
|
||||||
|
args_ctrl++;
|
||||||
|
|
||||||
|
static bool ViewHelp = false;
|
||||||
|
static bool ViewVersion = false;
|
||||||
|
static bool LogicalSpeficy = false;
|
||||||
|
static bool ListRequired = false;
|
||||||
|
static bool MultipleViewers = false;
|
||||||
|
static bool SetLanguageReq = false;
|
||||||
|
static bool SomeSpec = false;
|
||||||
|
static char* SpeficedLanguagePr;
|
||||||
|
static string Option;
|
||||||
|
static string Target;
|
||||||
|
static int SearchResult = 3;
|
||||||
|
static int SearchOnMainInt = -1;
|
||||||
|
|
||||||
|
VLOGD("Parsing standart arguments...\n");
|
||||||
|
while (argc_parse && args_ctrl[0] != nullptr)
|
||||||
|
{
|
||||||
|
if (args_ctrl[0][0] != '-')
|
||||||
|
{
|
||||||
|
argc_parse--;
|
||||||
|
args_ctrl++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int x = 1; true; x++)
|
||||||
|
{
|
||||||
|
Option = args_ctrl[0];
|
||||||
|
SomeSpec = true;
|
||||||
|
|
||||||
|
switch (args_ctrl[0][x])
|
||||||
|
{
|
||||||
|
case '-':
|
||||||
|
if (Option == "--backup")
|
||||||
|
deprecated('b', Display::UsingDispString->depr_backup_opt, "backup");
|
||||||
|
else if (Option == "--flash")
|
||||||
|
deprecated('F', Display::UsingDispString->depr_flash_opt, "flash");
|
||||||
|
else if (Option == "--format")
|
||||||
|
deprecated('r', Display::UsingDispString->depr_format_opt, "format");
|
||||||
|
else if (Option == "--license")
|
||||||
|
deprecated('L', Display::UsingDispString->depr_Vlicense_opt, "license");
|
||||||
|
else if (Option == "--logical")
|
||||||
|
{
|
||||||
|
VLOGD("Logical partition type specified.\n");
|
||||||
|
LogicalSpeficy = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (Option == "--context")
|
||||||
|
{
|
||||||
|
VLOGD("Custom context specified.\n");
|
||||||
|
if (argc_parse > 1)
|
||||||
|
PrContextInput(args_ctrl[1]);
|
||||||
|
else
|
||||||
|
LOGE("--context: %s.\n%s `%s --help' %s.\n", \
|
||||||
|
Display::UsingDispString->is_requires_arg, \
|
||||||
|
Display::UsingDispString->try_h, \
|
||||||
|
Strings::ExecutingName.c_str(), \
|
||||||
|
Display::UsingDispString->for_more);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (Option == "--list")
|
||||||
|
{
|
||||||
|
VLOGD("It was requested to list the partitions.\n");
|
||||||
|
ListRequired = true;
|
||||||
|
if (ViewVersion || ViewHelp)
|
||||||
|
MultipleViewers = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (Option == "--force")
|
||||||
|
{
|
||||||
|
VLOGD("Force mode speficed.\n");
|
||||||
|
Booleans::ForceMode = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (Option == "--verbose")
|
||||||
|
{
|
||||||
|
VLOGD("Verbose mode speficed.\n");
|
||||||
|
Booleans::VerboseMode = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (Option == "--silent")
|
||||||
|
{
|
||||||
|
VLOGD("Silent mode speficed.\n");
|
||||||
|
Booleans::SilentEnabled = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (Option == "--set-language")
|
||||||
|
{
|
||||||
|
VLOGD("It was requested to adjust the language.\n");
|
||||||
|
if (argc_parse > 1)
|
||||||
|
{
|
||||||
|
VLOGE("Language inputs: getting inputs...\n");
|
||||||
|
SetLanguageReq = true;
|
||||||
|
SpeficedLanguagePr = args_ctrl[1];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LOGE("--set-language: %s.\n%s `%s --help' %s.\n", \
|
||||||
|
Display::UsingDispString->is_requires_arg, \
|
||||||
|
Display::UsingDispString->try_h, \
|
||||||
|
Strings::ExecutingName.c_str(), \
|
||||||
|
Display::UsingDispString->for_more);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (Option == "--version")
|
||||||
|
{
|
||||||
|
VLOGD("The version info was requested to be displayed.\n");
|
||||||
|
ViewVersion = true;
|
||||||
|
if (ListRequired || ViewHelp)
|
||||||
|
MultipleViewers = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (Option == "--help")
|
||||||
|
{
|
||||||
|
VLOGD("The help message was requested to be displayed.\n");
|
||||||
|
ViewHelp = true;
|
||||||
|
if (ViewVersion || ListRequired)
|
||||||
|
MultipleViewers = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
VLOGE("Unknown Option: %s\n", args_ctrl[0]);
|
||||||
|
LOGE("%s: %s.\n%s `%s --help' %s.\n", args_ctrl[0], \
|
||||||
|
Display::UsingDispString->unknw_arg, \
|
||||||
|
Display::UsingDispString->try_h, \
|
||||||
|
Strings::ExecutingName.c_str(), \
|
||||||
|
Display::UsingDispString->for_more);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
deprecated('b', Display::UsingDispString->depr_backup_opt, "backup");
|
||||||
|
break;
|
||||||
|
case 'F':
|
||||||
|
deprecated('F', Display::UsingDispString->depr_flash_opt, "flash");
|
||||||
|
break;
|
||||||
|
case 'r':
|
||||||
|
deprecated('r', Display::UsingDispString->depr_format_opt, "format");
|
||||||
|
break;
|
||||||
|
case 'L':
|
||||||
|
deprecated('L', Display::UsingDispString->depr_Vlicense_opt, "license");
|
||||||
|
break;
|
||||||
|
case 'D':
|
||||||
|
deprecated('D', Display::UsingDispString->depr_ch_list_opt);
|
||||||
|
break;
|
||||||
|
case 'l':
|
||||||
|
VLOGD("Logical partition type specified.\n");
|
||||||
|
LogicalSpeficy = true;
|
||||||
|
continue;
|
||||||
|
case 'c':
|
||||||
|
VLOGD("Custom context speficed.\n");
|
||||||
|
if (argc_parse > 1)
|
||||||
|
{
|
||||||
|
VLOGE("Context inputs: getting inputs...\n");
|
||||||
|
PrContextInput(args_ctrl[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LOGE("-c: %s.\n%s `%s --help' %s.\n", \
|
||||||
|
Display::UsingDispString->is_requires_arg, \
|
||||||
|
Display::UsingDispString->try_h, \
|
||||||
|
Strings::ExecutingName.c_str(), \
|
||||||
|
Display::UsingDispString->for_more);
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
VLOGD("It was requested to list the partitions.\n");
|
||||||
|
ListRequired = true;
|
||||||
|
if (ViewVersion || ViewHelp)
|
||||||
|
MultipleViewers = true;
|
||||||
|
continue;
|
||||||
|
case 'f':
|
||||||
|
VLOGD("Force mode speficed.\n");
|
||||||
|
Booleans::ForceMode = true;
|
||||||
|
continue;
|
||||||
|
case 'V':
|
||||||
|
VLOGD("Verbose mode speficed.\n");
|
||||||
|
Booleans::VerboseMode = true;
|
||||||
|
continue;
|
||||||
|
case 's':
|
||||||
|
VLOGD("Silent mode speficed.\n");
|
||||||
|
Booleans::SilentEnabled = true;
|
||||||
|
continue;
|
||||||
|
case 'S':
|
||||||
|
VLOGD("It was requested to adjust the language.\n");
|
||||||
|
if (argc_parse > 1)
|
||||||
|
{
|
||||||
|
VLOGE("Language inputs: getting inputs...\n");
|
||||||
|
SetLanguageReq = true;
|
||||||
|
SpeficedLanguagePr = args_ctrl[1];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LOGE("-S: %s.\n%s `%s --help' %s.\n", \
|
||||||
|
Display::UsingDispString->is_requires_arg, \
|
||||||
|
Display::UsingDispString->try_h, \
|
||||||
|
Strings::ExecutingName.c_str(), \
|
||||||
|
Display::UsingDispString->for_more);
|
||||||
|
case 'v':
|
||||||
|
VLOGD("The version info was requested to be displayed.\n");
|
||||||
|
ViewVersion = true;
|
||||||
|
if (ListRequired || ViewHelp)
|
||||||
|
MultipleViewers = true;
|
||||||
|
continue;
|
||||||
|
case '\0':
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
VLOGE("Unknown Option: -%c\n", args_ctrl[0][x]);
|
||||||
|
LOGE("-%c: %s.\n%s `%s --help' %s.\n", args_ctrl[0][x], \
|
||||||
|
Display::UsingDispString->unknw_arg, \
|
||||||
|
Display::UsingDispString->try_h, \
|
||||||
|
Strings::ExecutingName.c_str(), \
|
||||||
|
Display::UsingDispString->for_more);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
argc_parse--;
|
||||||
|
args_ctrl++;
|
||||||
|
}
|
||||||
|
|
||||||
|
Base = &BaseTemplate;
|
||||||
|
argc_parse = argc;
|
||||||
|
|
||||||
|
VLOGD("Starting cycle for trapping main options...\n");
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
if ((argc_parse - 1) == 0)
|
||||||
|
{
|
||||||
|
VLOGD("MainFnController: argc - 1 = 0. Breaking...\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args[(argc_parse - 1)][0] == '-')
|
||||||
|
{
|
||||||
|
VLOGD("MainFnController: args[%d] starts with '-'. Continue.\n", (argc_parse - 1));
|
||||||
|
argc_parse--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Target = args[(argc_parse - 1)];
|
||||||
|
SearchOnMainInt = argc_parse;
|
||||||
|
VLOGD("MainFnController: args[%d] = %s\n", (argc_parse - 1), args[(argc_parse - 1)]);
|
||||||
|
VLOGD("MainFnController: variable of \"Target\" (string): %s\n", Target.c_str());
|
||||||
|
|
||||||
|
if (Target == "backup")
|
||||||
|
{
|
||||||
|
Base = &BackupArgProcessorBase;
|
||||||
|
Booleans::BackupMode = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (Target == "flash")
|
||||||
|
{
|
||||||
|
Base = &FlashArgProcessorBase;
|
||||||
|
Booleans::FlashMode = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (Target == "format")
|
||||||
|
{
|
||||||
|
Base = &FormatArgProcessorBase;
|
||||||
|
Booleans::FormatMode = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Target = "";
|
||||||
|
SearchOnMainInt = -1;
|
||||||
|
argc_parse--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Booleans::SilentEnabled && Booleans::VerboseMode)
|
||||||
|
{
|
||||||
|
VLOGE("Silent and verbose mode is one-way.\n");
|
||||||
|
cout << Strings::ExecutingName << ": " << Display::UsingDispString->s_and_v << endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
VLOGD("Checking last language switch status...\n");
|
||||||
|
if (Functions::CleanSWPoint())
|
||||||
|
{
|
||||||
|
VLOGD("Last transactions found that language was changed between.\n");
|
||||||
|
|
||||||
|
if (Display::UsingDispString->welcome_ != nullptr)
|
||||||
|
LOGD("%s", Display::UsingDispString->welcome_);
|
||||||
|
|
||||||
|
LOGD("%s %s %s %s.\n", Display::UsingDispString->language, Display::UsingDispString->welcome, Display::UsingDispString->by_str, Display::UsingDispString->lang_by_s);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check argument total */
|
||||||
|
VLOGD("argc (arguments) total: %d.\n", argc);
|
||||||
|
if (argc < 2)
|
||||||
|
LOGE("%s.\n%s '%s --help' %s.\n", Display::UsingDispString->missing_operand, Display::UsingDispString->try_h, Strings::ExecutingName.c_str(), Display::UsingDispString->for_more);
|
||||||
|
|
||||||
|
/* stop the program if multiple viewer is used */
|
||||||
|
if (MultipleViewers)
|
||||||
|
{
|
||||||
|
VLOGE("Multiple viewer option selected!\n");
|
||||||
|
LOGE("%s\n", Display::UsingDispString->multiple_wiewers);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* controller to handle viewer */
|
||||||
|
if (ViewHelp)
|
||||||
|
{
|
||||||
|
VLOGD("The help message was asked to display. It's displayed... Calling DisplayHelp()\n");
|
||||||
|
Functions::DisplayHelp();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else if (ViewVersion)
|
||||||
|
{
|
||||||
|
VLOGD("The version info message was asked to display. It's displayed... Calling DisplayVersion()\n");
|
||||||
|
Functions::DisplayVersion();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else if (ListRequired)
|
||||||
|
{
|
||||||
|
VLOGD("Partitions were asked to be listed. It's listed... Calling CheckRoot() (root check is required), CheckDevPoint() (for generating warnings etc.) and ListPartitions()\n");
|
||||||
|
Functions::CheckRoot();
|
||||||
|
VLOGD("CheckRoot() completed.\n");
|
||||||
|
Functions::CheckDevPoint();
|
||||||
|
VLOGD("CheckDevPoint() completed.\n");
|
||||||
|
return Functions::ListPartitions();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SetLanguageReq)
|
||||||
|
{
|
||||||
|
VLOGD("The language was asked to adjust. Calling SetLanguage()...\n");
|
||||||
|
LOGD("%s: %s\n", Strings::ExecutingName.c_str(), Display::UsingDispString->switching_lang);
|
||||||
|
Functions::SetLanguage(SpeficedLanguagePr, 0);
|
||||||
|
sleep(2);
|
||||||
|
VLOGD("SetLanguage() completed.\n");
|
||||||
|
LOGD("%s: %s.\n", Strings::ExecutingName.c_str(), Display::UsingDispString->please_rerun);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Target.empty())
|
||||||
|
{
|
||||||
|
VLOGE("There's no job to do.\n");
|
||||||
|
LOGD("%s: %s.\n", Strings::ExecutingName.c_str(), Display::UsingDispString->missing_operand);
|
||||||
|
|
||||||
|
if (SomeSpec)
|
||||||
|
LOGD("%s.\n", Display::UsingDispString->some_spec);
|
||||||
|
|
||||||
|
LOGD("%s '%s --help' %s.\n",Display::UsingDispString->try_h, Strings::ExecutingName.c_str(), Display::UsingDispString->for_more);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Base->ArgumentProcessor(SearchOnMainInt, argc, args);
|
||||||
|
|
||||||
|
if (Booleans::FormatMode)
|
||||||
|
{
|
||||||
|
VLOGD("File system name specified for formatting is being contaminated...\n");
|
||||||
|
if (Strings::TargetFormatFS != "ext4" \
|
||||||
|
&& Strings::TargetFormatFS != "ext3" \
|
||||||
|
&& Strings::TargetFormatFS != "ext2")
|
||||||
|
{
|
||||||
|
VLOGE("Unsupported file system: %s.\n", Strings::TargetFormatFS.c_str());
|
||||||
|
LOGE("%s: %s\n", Display::UsingDispString->unsupported_fs, Strings::TargetFormatFS.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* checks */
|
||||||
|
VLOGD("Checking root status... Calling CheckRoot()...\n");
|
||||||
|
Functions::CheckRoot();
|
||||||
|
VLOGD("Checking A/B and logical device status... Calling CheckDevPoint()...\n");
|
||||||
|
Functions::CheckDevPoint();
|
||||||
|
|
||||||
|
if (LogicalSpeficy)
|
||||||
|
{
|
||||||
|
VLOGD("Logical partition type speficed. Checking partition statust's...\n");
|
||||||
|
if (Booleans::UsesLogical)
|
||||||
|
Booleans::UseLogical = true;
|
||||||
|
else
|
||||||
|
LOGE("%s\n", Display::UsingDispString->not_logical);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Booleans::FlashMode)
|
||||||
|
{
|
||||||
|
VLOGD("The status of the specified file for flashing is being checked...\n");
|
||||||
|
SearchResult = Functions::GetState(Strings::TargetFlashFile);
|
||||||
|
|
||||||
|
if (SearchResult == 1)
|
||||||
|
LOGE("%s: `%s': %s\n", Display::UsingDispString->cannot_stat, Strings::TargetFlashFile.c_str(), strqerror());
|
||||||
|
else if (SearchResult == -1)
|
||||||
|
LOGE("`%s': %s\n", Strings::TargetFlashFile.c_str(), Display::UsingDispString->not_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* custom context checker */
|
||||||
|
if (Booleans::UseCustomContext)
|
||||||
|
{
|
||||||
|
VLOGD("The status of the \"dev\" is controlled in the specified custom /dev context...\n");
|
||||||
|
if (strncmp(Strings::CustomContext.c_str(), "/dev", 4) != 0)
|
||||||
|
{
|
||||||
|
if (!Booleans::ForceMode)
|
||||||
|
LOGE("%s\n", Display::UsingDispString->not_in_dev);
|
||||||
|
}
|
||||||
|
|
||||||
|
VLOGD("The specified custom /dev context is being put in countless...\n");
|
||||||
|
SearchResult = Functions::GetState(Strings::CustomContext, "dir");
|
||||||
|
|
||||||
|
if (SearchResult == 1)
|
||||||
|
LOGE("%s: `%s': %s\n", Display::UsingDispString->cannot_stat, Strings::CustomContext.c_str(), strqerror());
|
||||||
|
else if (SearchResult == -1)
|
||||||
|
LOGE("`%s': %s\n", Strings::CustomContext.c_str(), Display::UsingDispString->not_dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
VLOGD("The partition specification status is controlled...\n");
|
||||||
|
if (Strings::TargetPartition.empty())
|
||||||
|
{
|
||||||
|
if (!Booleans::ForceMode)
|
||||||
|
LOGE("%s\n%s `%s --help' %s\n", Display::UsingDispString->req_part_name, Display::UsingDispString->try_h, Strings::ExecutingName.c_str(), Display::UsingDispString->for_more);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
VLOGD("The call of main operations is being checked in case of the call...\n");
|
||||||
|
if (!Target.empty())
|
||||||
|
Base->CallTargetBaseFunction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* end of code */
|
||||||
52
jni/PartitionTool.cpp
Executable file
52
jni/PartitionTool.cpp
Executable file
@@ -0,0 +1,52 @@
|
|||||||
|
/* By YZBruh */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright 2024 Partition Manager
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define INC_MAIN_LIBS
|
||||||
|
|
||||||
|
#include <PartitionManager/PartitionManager.h>
|
||||||
|
|
||||||
|
using namespace PartitionManager;
|
||||||
|
|
||||||
|
static bool
|
||||||
|
accf(const string fp)
|
||||||
|
{
|
||||||
|
VLOGD("accf <local function>: trying to access `%s' with 'access <unistd.h>'\n", fp.c_str());
|
||||||
|
|
||||||
|
return (access(fp.c_str(), F_OK) == 0) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check parts */
|
||||||
|
void Functions::CheckDevPoint(void)
|
||||||
|
{
|
||||||
|
VLOGD("CheckDevPoint: selecting context...\n");
|
||||||
|
string dpoint = (Booleans::UseCustomContext) ? Strings::CustomContext : "/dev/block/by-name";
|
||||||
|
|
||||||
|
/* true = ab | false = a only */
|
||||||
|
Booleans::UsesSlots = (accf(dpoint + "/boot_a")) ? true : false;
|
||||||
|
|
||||||
|
if (Booleans::UsesSlots)
|
||||||
|
VLOGW("CheckDevPoint: 1 warning generated: A/B status.\n");
|
||||||
|
|
||||||
|
/* true = logical | false = normal */
|
||||||
|
Booleans::UsesLogical = (accf(dpoint + "/super")) ? true : false;
|
||||||
|
|
||||||
|
if (Booleans::UsesLogical)
|
||||||
|
VLOGW("CheckDevPoint: 1 warning generated: logical partitions status.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* end of code */
|
||||||
@@ -16,26 +16,22 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define INC_MAIN_LIBS
|
#define INC_MAIN_LIBS
|
||||||
#define INC_DEBUGERS
|
#define INC_DEBUGERS
|
||||||
|
#define INC_STRINGKEYS
|
||||||
|
|
||||||
#include <pmt/PartitionManager.h>
|
#include <PartitionManager/PartitionManager.h>
|
||||||
#include <pmt/StringKeys.h>
|
|
||||||
|
|
||||||
/* root checker function */
|
/* root checker function */
|
||||||
void check_root(void)
|
void PartitionManager::Functions::CheckRoot(void)
|
||||||
{
|
{
|
||||||
/* a quick, easy method for verifying root */
|
VLOGD("CheckRoot: trying to get UID with 'getuid <unistd.h>'\n");
|
||||||
if (getuid() != 0)
|
|
||||||
LOGE("%s\n", current->no_root);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
if (getuid() != 0)
|
||||||
|
{
|
||||||
|
VLOGE("CheckRoot: cannot get UID. Not executed with root!\n");
|
||||||
|
LOGE("%s\n", PartitionManager::Display::UsingDispString->no_root);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
/* end of code */
|
/* end of code */
|
||||||
243
jni/Tools.cpp
Executable file
243
jni/Tools.cpp
Executable file
@@ -0,0 +1,243 @@
|
|||||||
|
/* By YZBruh */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright 2024 Partition Manager
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define INC_MAIN_LIBS
|
||||||
|
#define INC_STAT
|
||||||
|
#define INC_DEBUGERS
|
||||||
|
#define INC_TOOLS_REQS
|
||||||
|
#define INC_STRINGKEYS
|
||||||
|
|
||||||
|
#include <PartitionManager/PartitionManager.h>
|
||||||
|
|
||||||
|
namespace PartitionManager {
|
||||||
|
namespace Functions {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* it is meant to calculate the size of the quickly given file.
|
||||||
|
* its purpose is for rapid processing
|
||||||
|
*/
|
||||||
|
static double
|
||||||
|
CalculateSizeDouble(const string& fp)
|
||||||
|
{
|
||||||
|
VLOGD("CalculateSizeDouble: calculating file size: `%s'\n", fp.c_str());
|
||||||
|
|
||||||
|
VLOGD("CalculateSizeDouble: reading `%s' with 'ifstream <fstream>'\n", fp.c_str());
|
||||||
|
ifstream target(fp, ios::binary | ios::ate);
|
||||||
|
|
||||||
|
return (!target) ? -1 : static_cast<double>(target.tellg()) / (1024 * 1024);
|
||||||
|
}
|
||||||
|
|
||||||
|
static long long
|
||||||
|
CalculateSizeLongLong(const string& fp)
|
||||||
|
{
|
||||||
|
VLOGD("CalculateSizeLongLong: calculating file size: `%s'\n", fp.c_str());
|
||||||
|
|
||||||
|
VLOGD("CalculateSizeLongLong: reading `%s' with 'ifstream <fstream>'\n", fp.c_str());
|
||||||
|
ifstream target(fp, ios::binary | ios::ate);
|
||||||
|
|
||||||
|
return (!target) ? -1 : static_cast<long long>(target.tellg());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* error that the partition is not found.
|
||||||
|
* It's for quick action.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
PartitionNotFound(const char* p) { LOGE("`%s': %s\n", p, Display::UsingDispString->part_not_found); }
|
||||||
|
|
||||||
|
/* the partitions are meant to quickly find. */
|
||||||
|
static void
|
||||||
|
SearchPartition(const string& fp)
|
||||||
|
{
|
||||||
|
VLOGD("SearchPartition: calling GetState()...\n");
|
||||||
|
static int op = GetState(fp, "blk");
|
||||||
|
|
||||||
|
if (op == 1)
|
||||||
|
PartitionNotFound(fp.c_str());
|
||||||
|
else if (op == -1 && !Booleans::ForceMode)
|
||||||
|
LOGE("%s\n", Display::UsingDispString->not_block);
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* namespace Functions */
|
||||||
|
} /* namespace PartitionNotFound */
|
||||||
|
|
||||||
|
using namespace PartitionManager;
|
||||||
|
|
||||||
|
/* to stop use of function type */
|
||||||
|
#define PartitionNotFound Functions::PartitionNotFound()
|
||||||
|
|
||||||
|
int Functions::Start(unsigned short progress_code)
|
||||||
|
{
|
||||||
|
/* required variables */
|
||||||
|
static fstream sourceF;
|
||||||
|
static fstream targetF;
|
||||||
|
static string accessPrefix;
|
||||||
|
static string opName;
|
||||||
|
static int BFSIZE = 1;
|
||||||
|
static char formatterCmd[200];
|
||||||
|
static long long copiedData = 0;
|
||||||
|
|
||||||
|
if (Booleans::UseLogical)
|
||||||
|
accessPrefix = "/dev/block/mapper/" + Strings::TargetPartition;
|
||||||
|
else
|
||||||
|
accessPrefix = (Booleans::UseCustomContext) ? (Strings::CustomContext) + ("/") + (Strings::TargetPartition) : ("/dev/block/by-name/") + (Strings::TargetPartition);
|
||||||
|
|
||||||
|
VLOGD("PartitionManager: calling SearchPartition() for searching partition (path); `%s'\n", accessPrefix.c_str());
|
||||||
|
Functions::SearchPartition(accessPrefix);
|
||||||
|
|
||||||
|
static long long count = (long long)(CalculateSizeLongLong(accessPrefix) + ((1024 * 1024) * 10));
|
||||||
|
|
||||||
|
BFSIZE = (int)(CalculateSizeLongLong(accessPrefix) / (10240 * 10240));
|
||||||
|
if (BFSIZE < 1)
|
||||||
|
BFSIZE = 1;
|
||||||
|
|
||||||
|
const int bfsize = BFSIZE;
|
||||||
|
char buffer[bfsize];
|
||||||
|
|
||||||
|
VLOGD("PartitionManager: calculating sizes...\n");
|
||||||
|
double partition_size = Functions::CalculateSizeDouble(accessPrefix);
|
||||||
|
double flashfile_size;
|
||||||
|
|
||||||
|
if (!Strings::TargetFlashFile.empty())
|
||||||
|
flashfile_size = Functions::CalculateSizeDouble(Strings::TargetFlashFile);
|
||||||
|
|
||||||
|
if (progress_code < 3)
|
||||||
|
{
|
||||||
|
if (partition_size != -1)
|
||||||
|
LOGD("%s: %.2fM\n", Display::UsingDispString->part_disk_sz, partition_size);
|
||||||
|
else
|
||||||
|
LOGW("%s\n", Display::UsingDispString->part_disk_sz_fail);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (progress_code == 1)
|
||||||
|
{
|
||||||
|
VLOGD("PartitionManager: trying to open `%s' with 'open <fstream>'.\n", accessPrefix.c_str());
|
||||||
|
sourceF.open(accessPrefix, ios::binary | ios::in);
|
||||||
|
if (!sourceF.is_open())
|
||||||
|
LOGE("%s: %s: %s\n", Display::UsingDispString->not_read, accessPrefix.c_str(), strqerror());
|
||||||
|
|
||||||
|
/* determine output */
|
||||||
|
if (Strings::OutputName == Strings::TargetPartition)
|
||||||
|
{
|
||||||
|
opName = Strings::OutputName + ".img";
|
||||||
|
VLOGW("PartitionManager: output not speficed. Selecting automaticly.\n");
|
||||||
|
LOGW("%s: %s\n", Display::UsingDispString->out_not_spec, opName.c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
opName = Strings::OutputName;
|
||||||
|
|
||||||
|
VLOGD("Checking output status...\n");
|
||||||
|
if (GetState(opName) == 0)
|
||||||
|
LOGE("`%s': File exits.\n", opName.c_str());
|
||||||
|
|
||||||
|
VLOGD("PartitionManager: trying to open `%s' with 'open <fstream>'.\n", opName.c_str());
|
||||||
|
targetF.open(opName, ios::binary | ios::out);
|
||||||
|
if (!targetF.is_open())
|
||||||
|
LOGE("%s: %s: %s\n", Display::UsingDispString->not_gen, opName.c_str(), strqerror());
|
||||||
|
|
||||||
|
VLOGD("PartitionManager: read (partition) and write (output) 'read, write <fstream>'\n");
|
||||||
|
/* start writing */
|
||||||
|
while (sourceF.read(buffer, bfsize) && copiedData < count)
|
||||||
|
{
|
||||||
|
streamsize readed_data = sourceF.gcount();
|
||||||
|
targetF.write(buffer, readed_data);
|
||||||
|
|
||||||
|
if (targetF.fail())
|
||||||
|
{
|
||||||
|
if (Functions::GetState(opName) == 0)
|
||||||
|
remove(opName.c_str());
|
||||||
|
LOGF("%s: %s: %s\n", Display::UsingDispString->not_write, opName.c_str(), strqerror());
|
||||||
|
}
|
||||||
|
|
||||||
|
copiedData += readed_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* close files */
|
||||||
|
sourceF.close();
|
||||||
|
targetF.close();
|
||||||
|
|
||||||
|
LOGD("%s: %s\n", Display::UsingDispString->success_backup, opName.c_str());
|
||||||
|
}
|
||||||
|
else if (progress_code == 2)
|
||||||
|
{
|
||||||
|
if (flashfile_size != -1)
|
||||||
|
LOGD("%s: %.2fM\n", Display::UsingDispString->flash_file_sz, flashfile_size);
|
||||||
|
else
|
||||||
|
LOGW("%s\n", Display::UsingDispString->flash_file_sz_fail);
|
||||||
|
|
||||||
|
if (partition_size != -1 && flashfile_size != -1)
|
||||||
|
{
|
||||||
|
if (flashfile_size > partition_size && !Booleans::ForceMode)
|
||||||
|
LOGE("%s\n", Display::UsingDispString->ffile_more_part);
|
||||||
|
}
|
||||||
|
|
||||||
|
VLOGD("PartitionManager: trying to open `%s' with 'open <fstream>'.\n", Strings::TargetFlashFile.c_str());
|
||||||
|
sourceF.open(Strings::TargetFlashFile, ios::binary | ios::in);
|
||||||
|
if (!sourceF.is_open())
|
||||||
|
LOGF("%s: %s: %s\n", Display::UsingDispString->not_read, Strings::TargetFlashFile.c_str(), strqerror());
|
||||||
|
|
||||||
|
VLOGD("PartitionManager: trying to open `%s' with 'open <fstream>'.\n", accessPrefix.c_str());
|
||||||
|
targetF.open(accessPrefix, ios::binary | ios::in | ios::out | ios::trunc);
|
||||||
|
if (!targetF.is_open())
|
||||||
|
LOGF("%s: %s: %s\n", Display::UsingDispString->not_read, accessPrefix.c_str(), strqerror());
|
||||||
|
|
||||||
|
VLOGD("PartitionManager: read (flash file) and write (partition) 'read, write <fstream>'\n");
|
||||||
|
/* start writing */
|
||||||
|
while (sourceF.read(buffer, bfsize) && copiedData < count)
|
||||||
|
{
|
||||||
|
streamsize readed_data = sourceF.gcount();
|
||||||
|
targetF.write(buffer, readed_data);
|
||||||
|
|
||||||
|
if (targetF.fail())
|
||||||
|
LOGF("%s: %s: %s\n", Display::UsingDispString->not_write, accessPrefix.c_str(), strqerror());
|
||||||
|
|
||||||
|
copiedData += readed_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceF.close();
|
||||||
|
targetF.close();
|
||||||
|
|
||||||
|
LOGD("%s.\n", Display::UsingDispString->success_flash);
|
||||||
|
}
|
||||||
|
else if (progress_code == 3)
|
||||||
|
{
|
||||||
|
/* get target partition block size */
|
||||||
|
VLOGD("PartitionManager: getting block size `%s' with 'statvfs <sys/statvfs.h>'\n", accessPrefix.c_str());
|
||||||
|
|
||||||
|
struct statvfs file_sys_inf;
|
||||||
|
if (statvfs(accessPrefix.c_str(), &file_sys_inf) != 0)
|
||||||
|
LOGE("%s\n", Display::UsingDispString->cannot_get_bsz);
|
||||||
|
|
||||||
|
/* generate mke2fs command */
|
||||||
|
VLOGD("PartitionManager: generating command...\n");
|
||||||
|
sprintf(formatterCmd, "/system/bin/mke2fs -Fq -t %s -b %lu %s &>/data/local/tmp/mke2fs", Strings::TargetFormatFS.c_str(), file_sys_inf.f_bsize, accessPrefix.c_str());
|
||||||
|
|
||||||
|
LOGD("%s: `%s'. %s: %s\n", Display::UsingDispString->formatting, accessPrefix.c_str(), Display::UsingDispString->fs_str, Strings::TargetFormatFS.c_str());
|
||||||
|
|
||||||
|
/* run command */
|
||||||
|
VLOGD("PartitionManager: executing command: \"%s\"\n", formatterCmd);
|
||||||
|
if (system(formatterCmd) != 0)
|
||||||
|
LOGF("%s\n", Display::UsingDispString->format_fail);
|
||||||
|
|
||||||
|
LOGD("%s.\n", Display::UsingDispString->success_format);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* end of code */
|
||||||
54
jni/Version.cpp
Executable file
54
jni/Version.cpp
Executable file
@@ -0,0 +1,54 @@
|
|||||||
|
/* By YZBruh */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copyright 2024 Partition Manager
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define INC_MAIN_LIBS
|
||||||
|
#define INC_STRINGKEYS
|
||||||
|
#define VERSIONING
|
||||||
|
|
||||||
|
#include <PartitionManager/PartitionManager.h>
|
||||||
|
#include <PartitionManager/VersionFnVars.h>
|
||||||
|
|
||||||
|
using namespace PartitionManager;
|
||||||
|
|
||||||
|
void Functions::DisplayVersion(void)
|
||||||
|
{
|
||||||
|
VLOGD("DisplayVersion: printing main info...\n");
|
||||||
|
LOGD("%s %s %d.%d.%d (C++) (%d%d%d) ", Strings::ExecutingName.c_str(), Display::UsingDispString->version_str, PMT_MAJOR, PMT_MINOR, PMT_PATCHLEVEL, PMT_MAJOR, PMT_MINOR, PMT_PATCHLEVEL);
|
||||||
|
|
||||||
|
#if __SIZEOF_POINTER__ == 4
|
||||||
|
LOGD("32-bit %s\n", Display::UsingDispString->bin_str);
|
||||||
|
#elif __SIZEOF_POINTER__ == 8
|
||||||
|
LOGD("64-bit %s\n", Display::UsingDispString->bin_str);
|
||||||
|
#else
|
||||||
|
LOGD("<%s> %s\n", Display::UsingDispString->unknw_str, Display::UsingDispString->bin_str);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
VLOGD("DisplayVersion: build type: ");
|
||||||
|
|
||||||
|
#if defined(__clang__) && !defined(__NDK_BUILD)
|
||||||
|
if (Booleans::VerboseMode)
|
||||||
|
printf("clang (manual).\n");
|
||||||
|
LOGD("%s: clang %d.%d.%d\n", Display::UsingDispString->compiler_str, __clang_major__, __clang_minor__, __clang_patchlevel__);
|
||||||
|
#elif defined(__NDK_BUILD)
|
||||||
|
if (Booleans::VerboseMode)
|
||||||
|
printf("NDK.\n");
|
||||||
|
LOGD("%s\n", __NDK_CXX_VERSION__);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* end of code */
|
||||||
71
jni/debug.c
71
jni/debug.c
@@ -1,71 +0,0 @@
|
|||||||
/* By YZBruh */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copyright 2024 Partition Manager
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define INC_MAIN_LIBS
|
|
||||||
|
|
||||||
#include <pmt/PartitionManager.h>
|
|
||||||
#include <pmt/StringKeys.h>
|
|
||||||
|
|
||||||
void debug(LogLevel status, const char* _Nullable fmt, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
va_start(args, fmt);
|
|
||||||
|
|
||||||
switch (status)
|
|
||||||
{
|
|
||||||
case LOG_LEVEL_ERR:
|
|
||||||
if (!pmt_silent)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: ", bin_name);
|
|
||||||
vfprintf(stderr, fmt, args);
|
|
||||||
}
|
|
||||||
exit(1);
|
|
||||||
break;
|
|
||||||
case LOG_LEVEL_WARN:
|
|
||||||
if (!pmt_silent)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: ", current->warn);
|
|
||||||
vfprintf(stderr, fmt, args);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case LOG_LEVEL_FATAL:
|
|
||||||
if (!pmt_silent)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s: ", current->fatal);
|
|
||||||
vfprintf(stderr, fmt, args);
|
|
||||||
}
|
|
||||||
abort();
|
|
||||||
break;
|
|
||||||
case LOG_LEVEL_DEBUG:
|
|
||||||
if (!pmt_silent)
|
|
||||||
vfprintf(stdout, fmt, args);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* end of code */
|
|
||||||
71
jni/help.c
71
jni/help.c
@@ -1,71 +0,0 @@
|
|||||||
/* By YZBruh */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright 2024 Partition Manager
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define INC_MAIN_LIBS
|
|
||||||
#define HELP
|
|
||||||
|
|
||||||
#include <pmt/PartitionManager.h>
|
|
||||||
#include <pmt/StringKeys.h>
|
|
||||||
#include <pmt/HelpMessages.h>
|
|
||||||
|
|
||||||
extern char* bin_name;
|
|
||||||
extern char* curr_lang;
|
|
||||||
|
|
||||||
struct pmt_langdb_docs* curr_docs = NULL;
|
|
||||||
|
|
||||||
static void
|
|
||||||
prepare_langconf_docs(void)
|
|
||||||
{
|
|
||||||
if (strcmp(curr_lang, "en") == 0)
|
|
||||||
curr_docs = &en_docs;
|
|
||||||
else if (strcmp(curr_lang, "tr") == 0)
|
|
||||||
curr_docs = &tr_docs;
|
|
||||||
}
|
|
||||||
|
|
||||||
void help(void)
|
|
||||||
{
|
|
||||||
prepare_langconf_docs();
|
|
||||||
printf("%s: %s %s\n", curr_docs->usage_docstr, bin_name, curr_docs->docs_strs_l1);
|
|
||||||
printf(" %s: %s %s\n", curr_docs->or_str, bin_name, curr_docs->docs_strs_l2);
|
|
||||||
printf(" %s: %s %s\n\n", curr_docs->or_str, bin_name, curr_docs->docs_strs_l3);
|
|
||||||
printf("%s: \n", curr_docs->docs_strs_l4);
|
|
||||||
printf(" -l, --logical %s\n", curr_docs->docs_strs_l5);
|
|
||||||
printf(" -c, --context %s\n", curr_docs->docs_strs_l6);
|
|
||||||
printf(" -p, --list %s\n", curr_docs->docs_strs_l7);
|
|
||||||
printf(" -s, --silent %s\n", curr_docs->docs_strs_l8);
|
|
||||||
printf(" -f, --force %s\n", curr_docs->docs_strs_l9);
|
|
||||||
printf(" -S, --set-lang %s\n", curr_docs->docs_strs_l10);
|
|
||||||
printf(" -v, --version %s\n", curr_docs->docs_strs_l11);
|
|
||||||
printf(" --help %s\n\n", curr_docs->docs_strs_l12);
|
|
||||||
printf("%s:\n", curr_docs->docs_strs_l13);
|
|
||||||
printf(" %s backup boot_a -c /dev/block/platform/bootdevice/by-name\n", bin_name);
|
|
||||||
printf(" %s flash boot_a /sdcard/twrp/boot.img -c /dev/block/platform/bootdevice/by-name\n", bin_name);
|
|
||||||
printf(" %s format system_a ext4 --logical\n", bin_name);
|
|
||||||
printf(" %s -c /dev/block/platform/bootdevice/by-name --list\n\n", bin_name);
|
|
||||||
printf("%s <t.me/ShawkTeam | Topics | pmt>\n", curr_docs->docs_strs_l14);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
/* end of code */
|
|
||||||
165
jni/lang_tools.c
165
jni/lang_tools.c
@@ -1,165 +0,0 @@
|
|||||||
/* By YZBruh */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copyright 2024 Partition Manager
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define INC_MAIN_LIBS
|
|
||||||
#define INC_DEBUGERS
|
|
||||||
#define INC_STAT
|
|
||||||
|
|
||||||
#include <pmt/PartitionManager.h>
|
|
||||||
#include <pmt/StringKeys.h>
|
|
||||||
|
|
||||||
/* pmt's man doc file path on termux */
|
|
||||||
#define TERMUX_PMT_MANDOC "/data/data/com.termux/files/usr/share/man/man8/pmt.8.gz"
|
|
||||||
|
|
||||||
#define PMTLANG_CONF "/sdcard/.pmtlang.conf"
|
|
||||||
|
|
||||||
#define PMT_SW_POINT "/sdcard/.pmtlangsw"
|
|
||||||
|
|
||||||
extern struct pmt_langdb_langs lang[];
|
|
||||||
struct pmt_langdb_general* current = NULL;
|
|
||||||
|
|
||||||
char* curr_lang;
|
|
||||||
static FILE *langconf;
|
|
||||||
|
|
||||||
static const char*
|
|
||||||
langctrl(const char* _Nonnull lang_)
|
|
||||||
{
|
|
||||||
for (int langct = 0; lang[langct].lang_pr != NULL; langct++)
|
|
||||||
{
|
|
||||||
if (strcmp(lang_, lang[langct].lang_pr) == 0)
|
|
||||||
return lang_;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int loadlang(void)
|
|
||||||
{
|
|
||||||
static char lang_fpr[3] = "en";
|
|
||||||
langconf = NULL;
|
|
||||||
|
|
||||||
if (get_stat(TERMUX_PMT_MANDOC, "file") == 0)
|
|
||||||
pmt_inst_on_termux = true;
|
|
||||||
|
|
||||||
|
|
||||||
langconf = fopen(PMTLANG_CONF, "r+");
|
|
||||||
|
|
||||||
if (langconf == NULL)
|
|
||||||
{
|
|
||||||
langconf = fopen(PMTLANG_CONF, "w+");
|
|
||||||
|
|
||||||
if (langconf == NULL || langconf != NULL)
|
|
||||||
{
|
|
||||||
setlang("en", 1);
|
|
||||||
current = &en;
|
|
||||||
curr_lang = "en";
|
|
||||||
|
|
||||||
if (langconf != NULL)
|
|
||||||
fclose(langconf);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
while (fgets(lang_fpr, sizeof(lang_fpr), langconf) != NULL)
|
|
||||||
{
|
|
||||||
if (strcmp(lang_fpr, "en") == 0)
|
|
||||||
{
|
|
||||||
fclose(langconf);
|
|
||||||
current = &en;
|
|
||||||
curr_lang = "en";
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else if (strcmp(lang_fpr, "tr") == 0)
|
|
||||||
{
|
|
||||||
fclose(langconf);
|
|
||||||
current = &tr;
|
|
||||||
curr_lang = "tr";
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fclose(langconf);
|
|
||||||
setlang("en", 0);
|
|
||||||
loadlang();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fgets(lang_fpr, sizeof(lang_fpr), langconf) == NULL)
|
|
||||||
{
|
|
||||||
setlang("en", 1);
|
|
||||||
loadlang();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setlang(const char* _Nonnull lang, int null_conf_stat)
|
|
||||||
{
|
|
||||||
if (langctrl(lang) == NULL)
|
|
||||||
LOGE("Unknown language: %s.\n", lang);
|
|
||||||
|
|
||||||
if (get_stat(PMTLANG_CONF, "file") == 0)
|
|
||||||
remove(PMTLANG_CONF);
|
|
||||||
|
|
||||||
langconf = NULL;
|
|
||||||
langconf = fopen(PMTLANG_CONF, "w");
|
|
||||||
|
|
||||||
if (langconf == NULL)
|
|
||||||
LOGE("Failed!!! Cannot open/write config file.\n");
|
|
||||||
|
|
||||||
if (fprintf(langconf, "%s", lang) < 2)
|
|
||||||
LOGE("Failed!!! Couldn't write config!\n");
|
|
||||||
else
|
|
||||||
fclose(langconf);
|
|
||||||
|
|
||||||
static int status;
|
|
||||||
|
|
||||||
if (null_conf_stat != 1)
|
|
||||||
{
|
|
||||||
status = open(PMT_SW_POINT, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
|
||||||
if (status == 0)
|
|
||||||
close(status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int search_sls(void)
|
|
||||||
{
|
|
||||||
if (get_stat(PMT_SW_POINT, "file") == 0)
|
|
||||||
{
|
|
||||||
remove(PMT_SW_POINT);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* end of code */
|
|
||||||
127
jni/listpart.c
127
jni/listpart.c
@@ -1,127 +0,0 @@
|
|||||||
/* By YZBruh */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copyright 2024 Partition Manager
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define INC_MAIN_LIBS
|
|
||||||
#define INC_DEBUGERS
|
|
||||||
#define INC_DIRENT
|
|
||||||
|
|
||||||
#include <pmt/PartitionManager.h>
|
|
||||||
#include <pmt/StringKeys.h>
|
|
||||||
|
|
||||||
/* current /dev context */
|
|
||||||
#define CUR_DEV_CNTX "/dev/block/by-name"
|
|
||||||
|
|
||||||
/* for logical partitions */
|
|
||||||
#define LGC_DEV_CNTX "/dev/block/mapper"
|
|
||||||
|
|
||||||
static DIR *dir;
|
|
||||||
|
|
||||||
static int
|
|
||||||
list(const char* operation, const char* target_dir)
|
|
||||||
{
|
|
||||||
static bool list = false;
|
|
||||||
static int count;
|
|
||||||
struct dirent **nlist;
|
|
||||||
dir = NULL;
|
|
||||||
|
|
||||||
if (strcmp(operation, "access") == 0)
|
|
||||||
list = false;
|
|
||||||
else if (strcmp(operation, "print") == 0)
|
|
||||||
list = true;
|
|
||||||
else
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
dir = opendir(target_dir);
|
|
||||||
|
|
||||||
if (dir != NULL)
|
|
||||||
{
|
|
||||||
closedir(dir);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (list)
|
|
||||||
{
|
|
||||||
count = scandir(target_dir, &nlist, NULL, alphasort);
|
|
||||||
|
|
||||||
if (count < 0)
|
|
||||||
LOGE("%s: `%s': %s\n", current->not_readdir, target_dir, strerror(errno));
|
|
||||||
|
|
||||||
for (int cont_count = 0; cont_count < count; cont_count++)
|
|
||||||
{
|
|
||||||
if (nlist[cont_count]->d_name[0] != '.')
|
|
||||||
LOGD("%s\n", nlist[cont_count]->d_name);
|
|
||||||
|
|
||||||
free(nlist[cont_count]);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(nlist);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* list existing partitions */
|
|
||||||
int listpart(void)
|
|
||||||
{
|
|
||||||
static char acc_cxt[350];
|
|
||||||
|
|
||||||
if (pmt_use_cust_cxt)
|
|
||||||
sprintf(acc_cxt, "%s", cust_cxt);
|
|
||||||
else
|
|
||||||
sprintf(acc_cxt, "%s", CUR_DEV_CNTX);
|
|
||||||
|
|
||||||
if (list("access", acc_cxt) != 0)
|
|
||||||
{
|
|
||||||
if (!pmt_force_mode)
|
|
||||||
LOGE("%s: `%s': %s\n", current->not_open, acc_cxt, strerror(errno));
|
|
||||||
else
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
list("print", acc_cxt);
|
|
||||||
|
|
||||||
if (pmt_logical)
|
|
||||||
{
|
|
||||||
if (list("access", LGC_DEV_CNTX) != 0)
|
|
||||||
LOGE("%s: `%s': %s\n", current->not_open, LGC_DEV_CNTX, strerror(errno));
|
|
||||||
else
|
|
||||||
list("print", LGC_DEV_CNTX);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pmt_ab)
|
|
||||||
LOGD("%s: %s\n", bin_name, current->ab_warn);
|
|
||||||
|
|
||||||
if (pmt_logical)
|
|
||||||
LOGD("%s: %s\n", bin_name, current->logical_warn);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
/* end of code */
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
/* By YZBruh */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copyright 2024 Partition Manager
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define INC_MAIN_LIBS
|
|
||||||
|
|
||||||
#include <pmt/PartitionManager.h>
|
|
||||||
|
|
||||||
static int
|
|
||||||
accf(const char* _Nonnull target) { return access(target, F_OK); }
|
|
||||||
|
|
||||||
/* check parts */
|
|
||||||
void check_dev_point(void)
|
|
||||||
{
|
|
||||||
/* true = ab | false = a */
|
|
||||||
if (pmt_use_cust_cxt)
|
|
||||||
{
|
|
||||||
static char cust_cxt_ck_path[150];
|
|
||||||
sprintf(cust_cxt_ck_path, "%s/boot_a", cust_cxt);
|
|
||||||
|
|
||||||
if (accf(cust_cxt_ck_path) != 0)
|
|
||||||
pmt_ab = false;
|
|
||||||
else
|
|
||||||
pmt_ab = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (accf("/dev/block/by-name/boot_a") != 0)
|
|
||||||
pmt_ab = false;
|
|
||||||
else
|
|
||||||
pmt_ab = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* true = logical | false = classic */
|
|
||||||
if (pmt_use_cust_cxt)
|
|
||||||
{
|
|
||||||
static char cust_cxt_ckl_path[150];
|
|
||||||
sprintf(cust_cxt_ckl_path, "%s/super", cust_cxt);
|
|
||||||
|
|
||||||
if (accf(cust_cxt_ckl_path) != 0)
|
|
||||||
pmt_logical = false;
|
|
||||||
else
|
|
||||||
pmt_logical = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (accf("/dev/block/by-name/super") != 0)
|
|
||||||
pmt_logical = false;
|
|
||||||
else
|
|
||||||
pmt_logical = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
/* end */
|
|
||||||
407
jni/pmt.c
407
jni/pmt.c
@@ -1,407 +0,0 @@
|
|||||||
/* By YZBruh */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copyright 2024 Partition Manager
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* force use C std (if default is C++) */
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define INC_MAIN_LIBS
|
|
||||||
#define INC_DEBUGERS
|
|
||||||
#define INC_STAT
|
|
||||||
#define INC_GETOPT
|
|
||||||
|
|
||||||
#include <pmt/PartitionManager.h>
|
|
||||||
#include <pmt/StringKeys.h>
|
|
||||||
#include <pmt/Deprecates.h>
|
|
||||||
#include <pmt/HelpMessages.h>
|
|
||||||
|
|
||||||
#define opt_symbol "-"
|
|
||||||
|
|
||||||
/* add value to variables that are added globally and are not worth */
|
|
||||||
char* out = NULL;
|
|
||||||
char* cust_cxt = NULL;
|
|
||||||
char* target_partition = NULL;
|
|
||||||
char* target_flash_file = NULL;
|
|
||||||
char* partition_type = NULL;
|
|
||||||
char* format_fs = NULL;
|
|
||||||
char* bin_name = NULL;
|
|
||||||
bool pmt_use_logical = false;
|
|
||||||
bool pmt_use_cust_cxt = false;
|
|
||||||
bool pmt_ab = false;
|
|
||||||
bool pmt_logical = false;
|
|
||||||
bool pmt_silent = false;
|
|
||||||
bool pmt_flash = false;
|
|
||||||
bool pmt_backup = false;
|
|
||||||
bool pmt_format = false;
|
|
||||||
bool pmt_force_mode = false;
|
|
||||||
bool pmt_inst_on_termux = false;
|
|
||||||
|
|
||||||
/* variable for use in control of '-' expression */
|
|
||||||
static char common_symbol_rule[350];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* He controls whether the '-' sign at
|
|
||||||
* the beginning of the given word
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
check_optsym(const char* _Nullable symbol)
|
|
||||||
{
|
|
||||||
if (symbol != NULL)
|
|
||||||
{
|
|
||||||
if (strncmp(symbol, opt_symbol, 1) == 0)
|
|
||||||
LOGE("%s\n", common_symbol_rule);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool
|
|
||||||
ctrl_arg(const char* _Nullable argv_holder)
|
|
||||||
{
|
|
||||||
if (strcmp(argv_holder, "--logical") != 0 && strcmp(argv_holder, "--context") != 0 && strcmp(argv_holder, "--silent") != 0 && strcmp(argv_holder, "-l") != 0 && strcmp(argv_holder, "-c") != 0 && strcmp(argv_holder, "-s") != 0)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* classic main function (C binary here xd) */
|
|
||||||
int main(int argc, char** argv)
|
|
||||||
{
|
|
||||||
bin_name = argv[0];
|
|
||||||
|
|
||||||
int argc_n = argc;
|
|
||||||
char buf[256];
|
|
||||||
char** args = malloc((argc + 1) * sizeof(char *));
|
|
||||||
|
|
||||||
/* copy original arguments */
|
|
||||||
for (int i = 0; i < argc; i++)
|
|
||||||
args[i] = argv[i];
|
|
||||||
|
|
||||||
if (!isatty(fileno(stdin)))
|
|
||||||
{
|
|
||||||
while (fgets(buf, sizeof(buf), stdin) != NULL)
|
|
||||||
{
|
|
||||||
buf[strcspn(buf, "\n")] = 0;
|
|
||||||
|
|
||||||
args = realloc(args, (argc_n + 1) * sizeof(char *));
|
|
||||||
args[argc_n] = strdup(buf);
|
|
||||||
argc_n++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
argc = argc_n;
|
|
||||||
|
|
||||||
/* load language */
|
|
||||||
if (loadlang() != 0)
|
|
||||||
{
|
|
||||||
printf("loadlang fail\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
sprintf(common_symbol_rule, "%s", current->common_symbol_rule);
|
|
||||||
|
|
||||||
if (search_sls() == 0)
|
|
||||||
{
|
|
||||||
if (current->welcome_ != NULL)
|
|
||||||
LOGD("%s", current->welcome_);
|
|
||||||
|
|
||||||
LOGD("%s %s %s %s.\n", current->language, current->welcome, current->by_str, current->lang_by_s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check argument total */
|
|
||||||
if (argc < 2)
|
|
||||||
LOGE("%s.\n%s `%s --help' %s.\n", current->missing_operand, current->try_h, args[0], current->for_more);
|
|
||||||
|
|
||||||
/* a structure for long arguments */
|
|
||||||
struct option option_table[] = {
|
|
||||||
{"backup", no_argument, 0, 'b'},
|
|
||||||
{"flash", no_argument, 0, 'F'},
|
|
||||||
{"format", no_argument, 0, 'r'},
|
|
||||||
{"is_dummy", no_argument, 0, 'D'},
|
|
||||||
{"logical", no_argument, 0, 'l'},
|
|
||||||
{"context", required_argument, 0, 'c'},
|
|
||||||
{"list", no_argument, 0, 'p'},
|
|
||||||
{"silent", no_argument, 0, 's'},
|
|
||||||
{"force", no_argument, 0, 'f'},
|
|
||||||
{"set-language", required_argument, 0, 'S'},
|
|
||||||
{"version", no_argument, 0, 'v'},
|
|
||||||
{"help", no_argument, 0, 0},
|
|
||||||
{"license", no_argument, 0, 'L'},
|
|
||||||
{0, 0, 0, 0}
|
|
||||||
};
|
|
||||||
|
|
||||||
/* boolean statements (only valid in this file) to distinguish. and pointer from a shortcut for the symbol rule */
|
|
||||||
static bool wiew_help = false;
|
|
||||||
static bool wiew_version = false;
|
|
||||||
static bool logical_spec = false;
|
|
||||||
static bool list_partitions = false;
|
|
||||||
static bool combo_wiewers = false;
|
|
||||||
static bool pmt_setlang = false;
|
|
||||||
static char* langpr;
|
|
||||||
static int search_result = 3;
|
|
||||||
static int opt;
|
|
||||||
|
|
||||||
if (strcmp(args[1], "backup") == 0)
|
|
||||||
{
|
|
||||||
if (argc <= 2)
|
|
||||||
LOGE("%s 0.\n", current->expected_backup_arg);
|
|
||||||
|
|
||||||
if (ctrl_arg(args[2]))
|
|
||||||
target_partition = args[2];
|
|
||||||
else
|
|
||||||
LOGE("%s.\n", current->not_spec_opt);
|
|
||||||
|
|
||||||
out = target_partition;
|
|
||||||
|
|
||||||
if (argc > 3 && ctrl_arg(args[3]))
|
|
||||||
out = args[3];
|
|
||||||
|
|
||||||
check_optsym(target_partition);
|
|
||||||
check_optsym(out);
|
|
||||||
|
|
||||||
pmt_backup = true;
|
|
||||||
}
|
|
||||||
else if (strcmp(args[1], "flash") == 0)
|
|
||||||
{
|
|
||||||
if (argc <= 2)
|
|
||||||
LOGE("%s 0.\n", current->expected_flash_arg);
|
|
||||||
|
|
||||||
if (argc <= 3)
|
|
||||||
LOGE("%s 1.\n", current->expected_flash_arg);
|
|
||||||
|
|
||||||
if (ctrl_arg(args[2]))
|
|
||||||
target_partition = args[2];
|
|
||||||
else
|
|
||||||
LOGE("%s.\n", current->not_spec_opt);
|
|
||||||
|
|
||||||
if (ctrl_arg(args[3]))
|
|
||||||
target_flash_file = args[3];
|
|
||||||
else
|
|
||||||
LOGE("%s.\n", current->not_spec_opt);
|
|
||||||
|
|
||||||
check_optsym(target_flash_file);
|
|
||||||
check_optsym(target_partition);
|
|
||||||
|
|
||||||
pmt_flash = true;
|
|
||||||
}
|
|
||||||
else if (strcmp(args[1], "format") == 0)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (argc <= 2)
|
|
||||||
LOGE("%s 0.\n", current->expected_format_arg);
|
|
||||||
|
|
||||||
if (argc <= 3)
|
|
||||||
LOGE("%s 1.\n", current->expected_format_arg);
|
|
||||||
|
|
||||||
if (ctrl_arg(args[2]))
|
|
||||||
target_partition = args[2];
|
|
||||||
else
|
|
||||||
LOGE("%s.\n", current->not_spec_opt);
|
|
||||||
|
|
||||||
if (ctrl_arg(args[3]))
|
|
||||||
format_fs = args[3];
|
|
||||||
else
|
|
||||||
LOGE("%s.\n", current->not_spec_opt);
|
|
||||||
|
|
||||||
check_optsym(format_fs);
|
|
||||||
check_optsym(target_partition);
|
|
||||||
|
|
||||||
pmt_format = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* control for each argument */
|
|
||||||
while ((opt = getopt_long(argc, args, "bFrDlc:psfS:vL", option_table, NULL)) != -1)
|
|
||||||
{
|
|
||||||
/* process arguments */
|
|
||||||
switch (opt)
|
|
||||||
{
|
|
||||||
/* handle deprecates */
|
|
||||||
case 'b':
|
|
||||||
DEPR_HANDLE('b', "backup", current->depr_backup_opt);
|
|
||||||
exit(1);
|
|
||||||
break;
|
|
||||||
case 'F':
|
|
||||||
DEPR_HANDLE('F', "flash", current->depr_flash_opt);
|
|
||||||
exit(1);
|
|
||||||
break;
|
|
||||||
case 'r':
|
|
||||||
DEPR_HANDLE('r', "format", current->depr_format_opt);
|
|
||||||
exit(1);
|
|
||||||
break;
|
|
||||||
case 'D':
|
|
||||||
DEPR_HANDLE('D', "NULLPTR", current->depr_ch_list_opt);
|
|
||||||
exit(1);
|
|
||||||
break;
|
|
||||||
case 'L':
|
|
||||||
DEPR_HANDLE('L', "license", current->depr_Vlicense_opt);
|
|
||||||
exit(1);
|
|
||||||
break;
|
|
||||||
/* logical partitions option */
|
|
||||||
case 'l':
|
|
||||||
logical_spec = true;
|
|
||||||
break;
|
|
||||||
/* context selector option */
|
|
||||||
case 'c':
|
|
||||||
pmt_use_cust_cxt = true;
|
|
||||||
cust_cxt = strdup(optarg);
|
|
||||||
check_optsym(cust_cxt);
|
|
||||||
break;
|
|
||||||
/* partition lister function */
|
|
||||||
case 'p':
|
|
||||||
list_partitions = true;
|
|
||||||
/* check combo wiewer options and progress */
|
|
||||||
if (wiew_version || wiew_help) combo_wiewers = true;
|
|
||||||
break;
|
|
||||||
/* force mode option */
|
|
||||||
case 'f':
|
|
||||||
pmt_force_mode = true;
|
|
||||||
break;
|
|
||||||
/* silent mode option */
|
|
||||||
case 's':
|
|
||||||
pmt_silent = true;
|
|
||||||
break;
|
|
||||||
/* language setter option */
|
|
||||||
case 'S':
|
|
||||||
pmt_setlang = true;
|
|
||||||
langpr = strdup(optarg);
|
|
||||||
break;
|
|
||||||
/* version info option */
|
|
||||||
case 'v':
|
|
||||||
wiew_version = true;
|
|
||||||
/* check combo wiewer options and progress */
|
|
||||||
if (list_partitions || wiew_help) combo_wiewers = true;
|
|
||||||
break;
|
|
||||||
/* help message opption */
|
|
||||||
case 0:
|
|
||||||
wiew_help = true;
|
|
||||||
/* check combo wiewer options and progress */
|
|
||||||
if (wiew_version || list_partitions) combo_wiewers = true;
|
|
||||||
break;
|
|
||||||
/* for invalid options */
|
|
||||||
case '?':
|
|
||||||
LOGD("%s `%s --help' %s\n", current->try_h, args[0], current->for_more);
|
|
||||||
return 1;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
LOGD("%s: %s [backup] [flash] [format] [-l | --logical] [-c | --context] [-p | --list] [-s | --silent] [-v | --version] [--help]\n", current->usage_head, args[0]);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* stop the program if multiple viewer is used */
|
|
||||||
if (combo_wiewers)
|
|
||||||
LOGE("%s", current->multiple_wiewers);
|
|
||||||
|
|
||||||
/* controller to handle viewer */
|
|
||||||
if (wiew_help)
|
|
||||||
{
|
|
||||||
help();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else if (wiew_version)
|
|
||||||
{
|
|
||||||
version();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else if (list_partitions)
|
|
||||||
{
|
|
||||||
check_root();
|
|
||||||
return listpart();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pmt_setlang)
|
|
||||||
{
|
|
||||||
LOGD("%s: %s\n", args[0], current->switching_lang);
|
|
||||||
setlang(langpr, 0);
|
|
||||||
sleep(2);
|
|
||||||
LOGD("%s: %s.\n", args[0], current->please_rerun);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pmt_backup && !pmt_flash && !pmt_format)
|
|
||||||
LOGE("%s.\n%s `%s --help` %s\n", current->no_target, current->try_h, args[0], current->for_more);
|
|
||||||
|
|
||||||
if (pmt_format)
|
|
||||||
{
|
|
||||||
if (strcmp(format_fs, "ext4") != 0 && strcmp(format_fs, "ext3") != 0 && strcmp(format_fs, "ext2") != 0)
|
|
||||||
LOGE("%s: %s\n", current->unsupported_fs, format_fs);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* checks */
|
|
||||||
check_root();
|
|
||||||
check_dev_point();
|
|
||||||
|
|
||||||
if (logical_spec)
|
|
||||||
{
|
|
||||||
if (pmt_logical)
|
|
||||||
pmt_use_logical = true;
|
|
||||||
else
|
|
||||||
LOGE("%s\n", current->not_logical);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pmt_flash)
|
|
||||||
{
|
|
||||||
search_result = get_stat(target_flash_file, "file");
|
|
||||||
|
|
||||||
if (search_result == 1)
|
|
||||||
LOGE("%s `%s': %s\n", current->cannot_stat, target_flash_file, strerror(errno));
|
|
||||||
else if (search_result == -1)
|
|
||||||
LOGE("`%s': %s\n", target_flash_file, current->not_file);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* custom context checker */
|
|
||||||
if (pmt_use_cust_cxt)
|
|
||||||
{
|
|
||||||
search_result = get_stat(cust_cxt, "dir");
|
|
||||||
|
|
||||||
if (search_result == 1)
|
|
||||||
LOGE("%s `%s': %s\n", current->cannot_stat, cust_cxt, strerror(errno));
|
|
||||||
else if (search_result == -1)
|
|
||||||
LOGE("`%s': %s\n", cust_cxt, current->not_dir);
|
|
||||||
|
|
||||||
if (strstr(cust_cxt, "/dev") == NULL && !pmt_force_mode)
|
|
||||||
LOGE("%s\n", current->not_in_dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (target_partition == NULL)
|
|
||||||
{
|
|
||||||
if (!pmt_force_mode)
|
|
||||||
LOGE("%s\n%s `%s --help' %s\n", current->req_part_name, current->try_h, args[0], current->for_more);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* 1 = backup mode
|
|
||||||
*
|
|
||||||
* 2 = flash mode
|
|
||||||
*
|
|
||||||
* 3 = format
|
|
||||||
*/
|
|
||||||
if (pmt_backup)
|
|
||||||
return pmt(1);
|
|
||||||
else if (pmt_flash)
|
|
||||||
return pmt(2);
|
|
||||||
else if (pmt_format)
|
|
||||||
return pmt(3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* end of code */
|
|
||||||
210
jni/tools.c
210
jni/tools.c
@@ -1,210 +0,0 @@
|
|||||||
/* By YZBruh */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copyright 2024 Partition Manager
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define BFSIZE 1024
|
|
||||||
#define INC_MAIN_LIBS
|
|
||||||
#define INC_STAT
|
|
||||||
#define INC_DEBUGERS
|
|
||||||
#define INC_TOOLS_REQS
|
|
||||||
|
|
||||||
#include <pmt/PartitionManager.h>
|
|
||||||
#include <pmt/StringKeys.h>
|
|
||||||
|
|
||||||
#define count (1024 * 1024 * 1024)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* it is meant to calculate the size of the quickly given file.
|
|
||||||
* its purpose is for rapid processing
|
|
||||||
*/
|
|
||||||
static double
|
|
||||||
calc_flsz(const char* _Nonnull filepath)
|
|
||||||
{
|
|
||||||
static int calc_flsz_file;
|
|
||||||
calc_flsz_file = open(filepath, O_RDONLY);
|
|
||||||
|
|
||||||
if (calc_flsz_file == -1)
|
|
||||||
return calc_flsz_file;
|
|
||||||
|
|
||||||
static off_t flsz;
|
|
||||||
flsz = lseek(calc_flsz_file, 0, SEEK_END);
|
|
||||||
close(calc_flsz_file);
|
|
||||||
|
|
||||||
if (flsz == (off_t)-1)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return (double)flsz / (1024 * 1024);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* error that the partition is not found.
|
|
||||||
* It's for quick action.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
partition_not_found(void) { LOGE("%s\n", current->part_not_found); }
|
|
||||||
|
|
||||||
/* to stop use of function type */
|
|
||||||
#define partition_not_found partition_not_found()
|
|
||||||
|
|
||||||
/* the partitions are meant to quickly find. */
|
|
||||||
static void
|
|
||||||
search_partition(const char* _Nonnull partition)
|
|
||||||
{
|
|
||||||
static int partition_results = 0;
|
|
||||||
partition_results = get_stat(partition, "blk");
|
|
||||||
|
|
||||||
if (partition_results == 1)
|
|
||||||
partition_not_found;
|
|
||||||
else if (partition_results == -1)
|
|
||||||
LOGE("%s\n", current->not_block);
|
|
||||||
}
|
|
||||||
|
|
||||||
int pmt(unsigned short progress_code)
|
|
||||||
{
|
|
||||||
/* required variables */
|
|
||||||
static int srcf, targetf;
|
|
||||||
static char acc_part_path[512];
|
|
||||||
static char formatter_cmd[200];
|
|
||||||
static char outf[512];
|
|
||||||
static char buffer[BFSIZE];
|
|
||||||
static ssize_t readed_data;
|
|
||||||
static unsigned long long copied_data = 0;
|
|
||||||
|
|
||||||
if (pmt_use_logical)
|
|
||||||
sprintf(acc_part_path, "/dev/block/mapper/%s", target_partition);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (pmt_use_cust_cxt)
|
|
||||||
sprintf(acc_part_path, "%s/%s", cust_cxt, target_partition);
|
|
||||||
else
|
|
||||||
sprintf(acc_part_path, "/dev/block/by-name/%s", target_partition);
|
|
||||||
}
|
|
||||||
|
|
||||||
search_partition(acc_part_path);
|
|
||||||
|
|
||||||
if (progress_code == 1)
|
|
||||||
{
|
|
||||||
if (calc_flsz(acc_part_path) != -1)
|
|
||||||
LOGD("%s: %.2fM\n", current->part_disk_sz, calc_flsz(acc_part_path));
|
|
||||||
else
|
|
||||||
LOGW("%s\n", current->part_disk_sz_fail);
|
|
||||||
|
|
||||||
srcf = open(acc_part_path, O_RDONLY);
|
|
||||||
if (srcf == -1)
|
|
||||||
LOGE("%s: %s: %s\n", current->not_read, acc_part_path, strerror(errno));
|
|
||||||
|
|
||||||
/* determine output */
|
|
||||||
if (strcmp(out, target_partition) == 0)
|
|
||||||
{
|
|
||||||
sprintf(outf, "%s.img", out);
|
|
||||||
LOGW("%s: %s\n", current->out_not_spec, outf);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
sprintf(outf, "%s", out);
|
|
||||||
|
|
||||||
targetf = open(outf, O_WRONLY | O_CREAT | O_TRUNC, 0660);
|
|
||||||
if (targetf == -1)
|
|
||||||
LOGE("%s: %s: %s\n", current->not_gen, outf, strerror(errno));
|
|
||||||
|
|
||||||
/* start writing */
|
|
||||||
while ((readed_data = read(srcf, buffer, BFSIZE)) > 0 && copied_data < count)
|
|
||||||
{
|
|
||||||
ssize_t writed_data = write(targetf, buffer, readed_data);
|
|
||||||
if (writed_data != readed_data)
|
|
||||||
{
|
|
||||||
if (get_stat(outf, "file") == 0)
|
|
||||||
remove(outf);
|
|
||||||
LOGF("%s: %s: %s\n", current->not_write, acc_part_path, strerror(errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
copied_data += writed_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* close files */
|
|
||||||
close(srcf);
|
|
||||||
close(targetf);
|
|
||||||
|
|
||||||
LOGD("%s: %s\n", current->success_backup, outf);
|
|
||||||
}
|
|
||||||
else if (progress_code == 2)
|
|
||||||
{
|
|
||||||
if (calc_flsz(target_flash_file) != -1)
|
|
||||||
LOGD("%s: %.2fM\n", current->flash_file_sz, calc_flsz(target_flash_file));
|
|
||||||
else
|
|
||||||
LOGW("%s\n", current->flash_file_sz_fail);
|
|
||||||
|
|
||||||
if (calc_flsz(acc_part_path) != -1)
|
|
||||||
LOGD("%s: %.2fM\n", current->part_disk_sz, calc_flsz(acc_part_path));
|
|
||||||
else
|
|
||||||
LOGW("%s\n", current->part_disk_sz_fail);
|
|
||||||
|
|
||||||
if (calc_flsz(target_flash_file) != -1 && calc_flsz(acc_part_path) != -1)
|
|
||||||
{
|
|
||||||
if (calc_flsz(target_flash_file) > calc_flsz(acc_part_path))
|
|
||||||
LOGE("%s\n", current->ffile_more_part);
|
|
||||||
}
|
|
||||||
|
|
||||||
srcf = open(target_flash_file, O_RDONLY);
|
|
||||||
if (srcf == -1)
|
|
||||||
LOGF("%s: %s: %s\n", current->not_read, target_flash_file, strerror(errno));
|
|
||||||
|
|
||||||
targetf = open(acc_part_path, O_WRONLY | O_CREAT | O_TRUNC, 0660);
|
|
||||||
if (targetf == -1)
|
|
||||||
LOGF("%s: %s: %s\n", current->not_read, acc_part_path, strerror(errno));
|
|
||||||
|
|
||||||
/* start writing */
|
|
||||||
while ((readed_data = read(srcf, buffer, BFSIZE)) > 0 && copied_data < count)
|
|
||||||
{
|
|
||||||
ssize_t writed_data = write(targetf, buffer, readed_data);
|
|
||||||
if (writed_data != readed_data)
|
|
||||||
LOGF("%s: %s: %s\n", current->not_write, acc_part_path, strerror(errno));
|
|
||||||
|
|
||||||
copied_data += writed_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
close(srcf);
|
|
||||||
close(targetf);
|
|
||||||
|
|
||||||
LOGD("%s.\n", current->success_flash);
|
|
||||||
}
|
|
||||||
else if (progress_code == 3)
|
|
||||||
{
|
|
||||||
/* get target partition block size */
|
|
||||||
struct statvfs file_sys_inf;
|
|
||||||
if (statvfs(acc_part_path, &file_sys_inf) != 0)
|
|
||||||
LOGE("%s\n", current->cannot_get_bsz);
|
|
||||||
|
|
||||||
/* generate mke2fs command */
|
|
||||||
sprintf(formatter_cmd, "mke2fs -Fq -t %s -b %lu %s", format_fs, file_sys_inf.f_bsize, acc_part_path);
|
|
||||||
|
|
||||||
/* run command */
|
|
||||||
if (system(formatter_cmd) != 0)
|
|
||||||
LOGF("%s\n", current->format_fail);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
/* end of code */
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
/* By YZBruh */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copyright 2024 Partition Manager
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define INC_MAIN_LIBS
|
|
||||||
#define VERSIONING
|
|
||||||
|
|
||||||
#include <pmt/PartitionManager.h>
|
|
||||||
#include <pmt/StringKeys.h>
|
|
||||||
#include <pmt/VersionVars.h>
|
|
||||||
|
|
||||||
void version(void)
|
|
||||||
{
|
|
||||||
LOGD("%s %s %d.%d.%d (%d%d%d) ", bin_name, current->version_str, PMT_MAJOR, PMT_MINOR, PMT_PATCHLEVEL, PMT_MAJOR, PMT_MINOR, PMT_PATCHLEVEL);
|
|
||||||
|
|
||||||
#if __SIZEOF_POINTER__ == 4
|
|
||||||
LOGD("32-bit %s\n", current->bin_str);
|
|
||||||
#elif __SIZEOF_POINTER__ == 8
|
|
||||||
LOGD("64-bit %s\n", current->bin_str);
|
|
||||||
#else
|
|
||||||
LOGD("<%s> %s\n", current->unknw_str, current->bin_str);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__clang__) && !defined(__NDK_BUILD)
|
|
||||||
LOGD("%s: clang %d.%d.%d\n", current->compiler_str, __clang_major__, __clang_minor__, __clang_patchlevel__);
|
|
||||||
#elif defined(__NDK_BUILD)
|
|
||||||
LOGD("%s\n", __NDK_CC_VERSION__);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* end of code */
|
|
||||||
@@ -68,7 +68,8 @@ install_binary:
|
|||||||
fi; \
|
fi; \
|
||||||
$(P) " - Success.\n\n"; \
|
$(P) " - Success.\n\n"; \
|
||||||
$(E_NS) "INSTALL_SUCCESS := true" > $(BUILD)/config/INS_STAT.mk; \
|
$(E_NS) "INSTALL_SUCCESS := true" > $(BUILD)/config/INS_STAT.mk; \
|
||||||
$(E_NS) "UNINSTALLED_SUCCESS := " > $(BUILD)/config/UNINS_STAT.mk; \
|
$(E_NS) "UNINSTALLED_SUCCESS := " > $(BUILD)/config/UNINS_STAT.mk
|
||||||
|
@ exit 0
|
||||||
|
|
||||||
uninstall_$(TARGET):
|
uninstall_$(TARGET):
|
||||||
if [ -f $(TERMUX_USR)/share/man/man8/$(TARGET).8.gz ]; then \
|
if [ -f $(TERMUX_USR)/share/man/man8/$(TARGET).8.gz ]; then \
|
||||||
|
|||||||
347
pmt-termux.sh
Executable file
347
pmt-termux.sh
Executable file
@@ -0,0 +1,347 @@
|
|||||||
|
#!/data/data/com.termux/files/usr/bin/env bash
|
||||||
|
|
||||||
|
# By YZBruh | ShawkTeam
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
LOCAL_VERSION="2.8.0"
|
||||||
|
LOCAL_OWNER="ShawkTeam"
|
||||||
|
LOCAL_REPO="pmt"
|
||||||
|
LOCAL_RELEASE_TAG="${LOCAL_VERSION}"
|
||||||
|
LOCAL_PREFIX="${PREFIX}"
|
||||||
|
[ -d "${LOCAL_PREFIX}" ] \
|
||||||
|
|| LOCAL_PREFIX="/data/data/com.termux/files/usr"
|
||||||
|
LOCAL_TMPDIR="${LOCAL_PREFIX}/tmp/pmt-termux-helper"
|
||||||
|
|
||||||
|
# Colors
|
||||||
|
RESET="\033[0m"
|
||||||
|
RED="\033[0;31m"
|
||||||
|
GREEN="\033[0;32m"
|
||||||
|
YELLOW="\033[0;33m"
|
||||||
|
|
||||||
|
# Printer functions
|
||||||
|
function printc() { echo -e "$*" >&2; }
|
||||||
|
function print()
|
||||||
|
{
|
||||||
|
if echo "$*" | grep "Success" &>/dev/null; then
|
||||||
|
echo -e " - ${GREEN}${1:0:7}${RESET}." >&2
|
||||||
|
else
|
||||||
|
echo -e " - $*" >&2
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Print error and exit
|
||||||
|
function abort()
|
||||||
|
{
|
||||||
|
print "${RED}Error:${RESET} ${@}"
|
||||||
|
cleanup
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Print warnings
|
||||||
|
function warning() { print "${YELLOW}Warning:${RESET} ${@}"; }
|
||||||
|
|
||||||
|
# Print head
|
||||||
|
function script_head() { printc " --- Partition Manager Termux Helper Script --- \n"; }
|
||||||
|
|
||||||
|
# For display help message
|
||||||
|
function view_help()
|
||||||
|
{
|
||||||
|
echo -n "Usage: "
|
||||||
|
if echo "${0}" | grep "./" >&/dev/null; then
|
||||||
|
printc "${0} [OPTIONS]..."
|
||||||
|
else
|
||||||
|
printc "(bash) ${0} [OPTIONS]"
|
||||||
|
fi
|
||||||
|
|
||||||
|
printc "Install, uninstall, install status checker for Partition Manager binary.\n"
|
||||||
|
printc "Options:"
|
||||||
|
printc " install, -i [OPTS] Download and install Partition Manager."
|
||||||
|
printc " uninstall, -u Uninstall Partition Manager."
|
||||||
|
printc " status, -s Display install/uninstall status."
|
||||||
|
printc " --setup, -S Setup required packages."
|
||||||
|
printc " --package <FILE> If you already have a debug package, make\n setup by specifying this way."
|
||||||
|
printc " --binary <FILE> Setup binary instead of the deb pack."
|
||||||
|
printc " --compress-algorithm [ALGO] Speficy custom algorithm for extracting package (if only custom package specified)."
|
||||||
|
printc "Supported algorithms: xz, gzip, zip, 7z, tar, tar.xz, tar.gz\n"
|
||||||
|
printc "Report bugs to <t.me/ShawkTeam | Topics | pmt>"
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Script really operated termux proclamation?
|
||||||
|
function really_termux()
|
||||||
|
{
|
||||||
|
ls "${LOCAL_PREFIX}/bin" | grep "termux" &>/dev/null \
|
||||||
|
|| abort "Are you sure you're in termux?"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get architecture info
|
||||||
|
function get_architecture()
|
||||||
|
{
|
||||||
|
local arch=$(uname -m)
|
||||||
|
local archs_64=("aarch64" "armv8" "arm64-v8a" "armv8-a")
|
||||||
|
local archs_32=("aarch32" "armv7" "armeabi-v7a" "armv7l")
|
||||||
|
|
||||||
|
print "Device architecture: '${arch}'."
|
||||||
|
|
||||||
|
for a in ${archs_64[@]}; do
|
||||||
|
[ "${arch}" = "${a}" ] \
|
||||||
|
&& LOCAL_ARCH="arm64-v8a" \
|
||||||
|
&& return
|
||||||
|
done
|
||||||
|
|
||||||
|
for a in ${archs_32[@]}; do
|
||||||
|
[ "${arch}" = "${a}" ] \
|
||||||
|
&& LOCAL_ARCH="armeabi-v7a" \
|
||||||
|
&& return
|
||||||
|
done
|
||||||
|
|
||||||
|
LOCAL_ARCH="arm64-v8a"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Generate template dir
|
||||||
|
function gen_tempdir() { mkdir -p "${LOCAL_TMPDIR}"; }
|
||||||
|
|
||||||
|
# Clean template dir
|
||||||
|
function cleanup() { rm -rf "${LOCAL_TMPDIR}"; }
|
||||||
|
|
||||||
|
# Check install/uninstall status
|
||||||
|
function check_status()
|
||||||
|
{
|
||||||
|
local installed="${RED}false${RESET}"
|
||||||
|
[ -f "${LOCAL_PREFIX}/bin/pmt" ] \
|
||||||
|
&& installed="${GREEN}true${RESET}"
|
||||||
|
|
||||||
|
print "Installed: ${installed}"
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check internet connection
|
||||||
|
function net_control()
|
||||||
|
{
|
||||||
|
curl "https://github.com" &>/dev/null \
|
||||||
|
|| abort "You need internet connection to this process."
|
||||||
|
}
|
||||||
|
|
||||||
|
# Download Partition Manager
|
||||||
|
function download()
|
||||||
|
{
|
||||||
|
local URL
|
||||||
|
|
||||||
|
if [ "${BINARY}" = 1 -a "${PACKAGE}" != 1 ]; then
|
||||||
|
URL="https://github.com/${LOCAL_OWNER}/${LOCAL_REPO}/releases/tag/${LOCAL_RELEASE_TAG}/download/pmt-${LOCAL_ARCH}.xz"
|
||||||
|
else
|
||||||
|
URL="https://github.com/${LOCAL_OWNER}/${LOCAL_REPO}/releases/tag/${LOCAL_RELEASE_TAG}/download/pmt-${LOCAL_ARCH}.deb"
|
||||||
|
fi
|
||||||
|
|
||||||
|
print "Downloading: \`${URL}'"
|
||||||
|
|
||||||
|
curl "${URL}" -o "${LOCAL_TMPDIR}" &>/dev/null \
|
||||||
|
|| abort "Download failed!"
|
||||||
|
|
||||||
|
chmod 777 "${LOCAL_TMPDIR}/*" \
|
||||||
|
|| warning "Cannot set mode '777' on installed sources."
|
||||||
|
}
|
||||||
|
|
||||||
|
# For installing required packages
|
||||||
|
function setup_packages()
|
||||||
|
{
|
||||||
|
net_control
|
||||||
|
|
||||||
|
print "Updating mirrors..."
|
||||||
|
if ! pkg update &>/dev/null || [ "$?" != 0 ]; then
|
||||||
|
abort "Updating failed!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
print "Installing: 'xz-utils, p7zip'"
|
||||||
|
if ! pkg install -y xz-utils p7zip || [ "$?" != 0 ]; then
|
||||||
|
abort "Installing failed!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
print "Success."
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Install deb package
|
||||||
|
function install_fn()
|
||||||
|
{
|
||||||
|
local mydir="$(pwd)"
|
||||||
|
local bname=$(basename ${LOCAL_PACKAGE})
|
||||||
|
|
||||||
|
[ "${PACKAGE}" = 1 ] && \
|
||||||
|
if [ ! -f "${LOCAL_PACKAGE}" ]; then
|
||||||
|
[ -d "${LOCAL_PACKAGE}" ] \
|
||||||
|
&& abort "\`${LOCAL_PACKAGE}': is directory."
|
||||||
|
|
||||||
|
abort "\`${LOCAL_PACKAGE}': no such file."
|
||||||
|
else
|
||||||
|
cp "${LOCAL_PACKAGE}" "${LOCAL_TMPDIR}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd "${LOCAL_TMPDIR}"
|
||||||
|
|
||||||
|
[ "${BINARY}" = 1 -a "${NONE_ALGO}" != 1 ] \
|
||||||
|
&& print "Extracting '${bname}'..." && \
|
||||||
|
if eval "${ALGO_DEC} ${ALGO_FLAGS} ${LOCAL_TMPDIR}/${bname}" &>/dev/null; then
|
||||||
|
rm -f "${bname}"
|
||||||
|
else
|
||||||
|
abort "Failed! Try speficing algorithm."
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ "$(basename *)" = "*" ] \
|
||||||
|
&& abort "Deb pack or binary file was not found!"
|
||||||
|
|
||||||
|
bname=$(basename *)
|
||||||
|
|
||||||
|
if [ "${BINARY}" = 1 ]; then
|
||||||
|
mv "${bname}" pmt &>/dev/null
|
||||||
|
|
||||||
|
print "Copying..."
|
||||||
|
cp pmt "${LOCAL_PREFIX}/bin/pmt" &>/dev/null \
|
||||||
|
|| abort "Copying failed"
|
||||||
|
|
||||||
|
print "Setting up permissions..."
|
||||||
|
chmod 777 "${LOCAL_PREFIX}/bin/pmt" &>/dev/null \
|
||||||
|
|| abort "Cannot set permissions!"
|
||||||
|
|
||||||
|
print "Success."
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
print "Installing Partition Manager with APT..."
|
||||||
|
if ! apt -y install ./pmt-${LOCAL_ARCH}.deb &>/dev/null; then
|
||||||
|
warning "Installing failed with APT. Trying installing with dpkg..."
|
||||||
|
|
||||||
|
dpkg install pmt-${LOCAL_ARCH}.deb &>/dev/null \
|
||||||
|
|| abort "Cannot install Partition Manager!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
print "Success."
|
||||||
|
cd "${mydir}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Uninstall deb package
|
||||||
|
function uninstall_fn()
|
||||||
|
{
|
||||||
|
[ "${BINARY}" = 1 ] \
|
||||||
|
&& print "Removing binary..." && \
|
||||||
|
if rm "${LOCAL_PREFIX}/bin/pmt" &>/dev/null; then
|
||||||
|
print "Success."
|
||||||
|
return
|
||||||
|
else
|
||||||
|
abort "Failed!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
print "Uninstalling Partition Manager with APT..."
|
||||||
|
if ! apt -y remove pmt &>/dev/null; then
|
||||||
|
warning "Uninstalling failed with APT. Trying uninstalling with dpkg..."
|
||||||
|
|
||||||
|
dpkg remove pmt &>/dev/null \
|
||||||
|
|| abort "Cannot uninstall Partition Manager!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
print "Success."
|
||||||
|
}
|
||||||
|
|
||||||
|
trap "abort Interrput; cleanup" SIGINT
|
||||||
|
# set -x
|
||||||
|
|
||||||
|
# Process arguments
|
||||||
|
while (($# >= 1)); do
|
||||||
|
SOME_SPEC=1
|
||||||
|
|
||||||
|
case "${1}" in
|
||||||
|
install|-i)
|
||||||
|
PROCESS=1
|
||||||
|
;;
|
||||||
|
uninstall|-u)
|
||||||
|
PROCESS=2
|
||||||
|
;;
|
||||||
|
status|-s)
|
||||||
|
script_head
|
||||||
|
check_status y
|
||||||
|
;;
|
||||||
|
--setup|-S)
|
||||||
|
script_head
|
||||||
|
print "Starting package setupper..."
|
||||||
|
setup_packages
|
||||||
|
;;
|
||||||
|
--package)
|
||||||
|
PACKAGE=1
|
||||||
|
LOCAL_PACKAGE="${2}"
|
||||||
|
;;
|
||||||
|
--binary)
|
||||||
|
BINARY=1
|
||||||
|
;;
|
||||||
|
--not-compressed)
|
||||||
|
NOT_COMP=1
|
||||||
|
;;
|
||||||
|
--compress-algorithm)
|
||||||
|
ALGO_SPEC=1
|
||||||
|
[ -z "${2}" ] \
|
||||||
|
&& abort "'--compress-algorithm' requires an argument."
|
||||||
|
case "${2}" in
|
||||||
|
xz|gzip|zip|7z|tar|tar.xz|tar.gz)
|
||||||
|
if echo "${2}" | grep "tar." &>/dev/null; then
|
||||||
|
ALGO_DEC="tar"
|
||||||
|
ALGO_FLAGS="-xf"
|
||||||
|
elif [ "${2}" = "zip" ]; then
|
||||||
|
ALGO_DEC="unzip"
|
||||||
|
ALGO_FLAGS=
|
||||||
|
elif [ "${2}" = "7z" ]; then
|
||||||
|
ALGO_DEC="7z"
|
||||||
|
ALGO_FLAGS="x"
|
||||||
|
else
|
||||||
|
ALGO_DEC="${2}"
|
||||||
|
ALGO_FLAGS="-d"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
none)
|
||||||
|
NONE_ALGO=1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
abort "Unknown compress algorithm: ${2}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
--help)
|
||||||
|
view_help
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
shift 1
|
||||||
|
done
|
||||||
|
|
||||||
|
### Main ###
|
||||||
|
[ -z "${1}" -a "${SOME_SPEC}" != 1 ] && view_help
|
||||||
|
|
||||||
|
script_head
|
||||||
|
|
||||||
|
[ -z "${LOCAL_PACKAGE}" -a "${PACKAGE}" = 1 ] \
|
||||||
|
&& abort "'--package' requires an argument (file)."
|
||||||
|
|
||||||
|
really_termux
|
||||||
|
gen_tempdir
|
||||||
|
|
||||||
|
[ -z "${ALGO_DEC}" ] && ALGO_DEC="xz" && ALGO_FLAGS="-d"
|
||||||
|
[ "${ALGO_SPEC}" = 1 -a "${PACKAGE}" != 1 ] \
|
||||||
|
&& abort "Compression algorithm cannot be specified without package specification option."
|
||||||
|
|
||||||
|
if [ "${PROCESS}" = 1 ]; then
|
||||||
|
[ -f "${LOCAL_PREFIX}/bin/pmt" ] \
|
||||||
|
&& abort "Partition Manager already installed."
|
||||||
|
[ "${PACKAGE}" = 1 ] || net_control
|
||||||
|
get_architecture
|
||||||
|
print "Starting install process..."
|
||||||
|
[ "${PACKAGE}" = 1 ] || download
|
||||||
|
install_fn
|
||||||
|
elif [ "${PROCESS}" = 2 ]; then
|
||||||
|
[ ! -f "${LOCAL_PREFIX}/bin/pmt" ] \
|
||||||
|
&& abort "Partition Manager already uninstalled."
|
||||||
|
print "Starting uninstall process..."
|
||||||
|
uninstall_fn
|
||||||
|
fi
|
||||||
|
|
||||||
|
cleanup
|
||||||
|
|
||||||
|
exit 0
|
||||||
Reference in New Issue
Block a user