From b76b79ba07d15e38611b6407ac5d5278336209bb Mon Sep 17 00:00:00 2001 From: YZBruh Date: Mon, 11 Aug 2025 12:29:21 +0300 Subject: [PATCH] pmt: fix std::filesystem exceptions --- README.md | 1 + include/LICENSE.picosha2 | 21 +++++++ manager.sh | 121 +++++++++++++++++++++++++++++++++++++++ src/PartitionManager.cpp | 8 ++- 4 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 include/LICENSE.picosha2 create mode 100644 manager.sh diff --git a/README.md b/README.md index e4284bb..8dc1291 100755 --- a/README.md +++ b/README.md @@ -30,3 +30,4 @@ Detailed usage instructions and option references can be found in the [USAGE.md] ## Credits - [CLI11: Command line parser for C++11](https://github.com/CLIUtils/CLI11) + - [PicoSHA2: A header-file-only, SHA256 hash generator in C++](https://github.com/okdshin/PicoSHA2) diff --git a/include/LICENSE.picosha2 b/include/LICENSE.picosha2 new file mode 100644 index 0000000..b6658bb --- /dev/null +++ b/include/LICENSE.picosha2 @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 okdshin + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/manager.sh b/manager.sh new file mode 100644 index 0000000..fc470f3 --- /dev/null +++ b/manager.sh @@ -0,0 +1,121 @@ +#!/data/data/com.termux/files/usr/bin/env bash +# +# Copyright 2025 Yağız Zengin +# +# 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. +# + +THIS="$(basename $0)" +RELEASE="20250810" + +echo() { command echo "[$THIS]: $@"; } + +checks() +{ + if ! curl "https://github.com" &>/dev/null; then + echo "No internet connection!" + exit 1 + fi + + echo "Updating repositories and checking required packages..." + pkg update &>/dev/null + [ ! -f $PREFIX/bin/unzip ] && pkg install -y unzip + [ ! -f $PREFIX/bin/wget ] && pkg install -y wget +} + +select_variant() +{ + LINK=""; ARCH=""; VARIANT="" + + if getprop ro.product.cpu.abi | grep "arm64-v8a" &>/dev/null; then ARCH="arm64-v8a"; + else ARCH="armeabi-v7a" + fi + [ $1 == "static" ] && VARIANT="static-" + + LINK="https://github.com/ShawkTeam/pmt-renovated/releases/download/${RELEASE}/pmt-${VARIANT}${ARCH}.zip" +} + +download() +{ + mkdir -p $PREFIX/tmp + echo "Downloading pmt-${VARIANT}${ARCH}.zip (${RELEASE})" + if ! wget -o $PREFIX/tmp/pmt.zip "${LINK}" &>/dev/null; then + echo "Download failed! LINK=${LINK}" + rm $PREFIX/tmp/*.zip + exit 1 + fi + + echo "Extracting..." + if ! unzip -d $PREFIX/tmp $PREFIX/tmp/pmt.zip &>/dev/null; then + echo "Extraction failed!" + exit 1 + fi +} + +setup() +{ + [ -f $PREFIX/tmp/pmt_static ]; mv $PREFIX/tmp/pmt_static $PREFIX/tmp/pmt + set -e + install -t $PREFIX/bin $PREFIX/tmp/pmt + if [ -f $PREFIX/tmp/libhelper.so ]; then + install -t $PREFIX/lib $(find $PREFIX/tmp -name "lib*.so") + install -t $PREFIX/lib $(find $PREFIX/tmp -name "lib*.a") + fi + echo "Installed successfully. Try running 'pmt' command." +} + +uninstall() +{ + rm -f $PREFIX/pmt $PREFIX/lib/libhelper* $PREFIX/libpartition_map* &>/dev/null +} + +is_installed() +{ + if /system/bin/which pmt &>/dev/null; then + echo "PMT is already installed." + exit 1 + fi +} + +cleanup() +{ + rm -f $PREFIX/tmp/pmt* $PREFIX/tmp/lib* $PREFIX/tmp/*.zip &>/dev/null +} + +if [ $# -eq 0 ]; then + command echo "Usage: $0 install|uninstall [--static]" + exit 1 +fi + +case $1 in + "install") + is_installed + checks + select_variant $([ "$2" == "--static" ] && echo static) + download + setup + ;; + "uninstall") + uninstall && echo "Uninstalled successfully." + ;; + "reinstall") + uninstall + checks + select_variant $([ "$2" == "--static" ] && echo static) + download + setup + ;; + *) + command echo "$0: Unknown argument: $1" + exit 1 ;; +esac diff --git a/src/PartitionManager.cpp b/src/PartitionManager.cpp index 9011bbe..feea9ca 100644 --- a/src/PartitionManager.cpp +++ b/src/PartitionManager.cpp @@ -37,10 +37,12 @@ void variableProtect::setVariablePointer(basic_variables *&_ptr) { basic_variables::~basic_variables() { delete PartMap; } basic_variables::basic_variables() - : PartMap(new PartitionMap::BuildMap()), - logFile("/sdcard/Documents/last_pmt_logs.log"), onLogical(false), + : logFile("/sdcard/Documents/last_pmt_logs.log"), onLogical(false), quietProcess(false), verboseMode(false), viewVersion(false), - forceProcess(false) {} + forceProcess(false) { + try { PartMap = new PartitionMap::BuildMap(); } + catch (std::exception&) {} +} int Main(int argc, char **argv) { try {