Compare commits

..

11 Commits

Author SHA1 Message Date
7405083815 Revert "README: Fix wrong URLs."
This reverts commit eda1b3d50c.
2025-11-02 23:06:03 +03:00
9a1af981d9 pmt: Set version as release candicate 2025-11-02 22:54:27 +03:00
eda1b3d50c README: Fix wrong URLs. 2025-10-28 12:02:31 +03:00
0c48c13852 Cleanup idea files, etc. 2025-10-28 11:42:35 +03:00
7ab20f1c99 .github/workflows/build.yml Güncelle 2025-10-28 11:15:15 +03:00
a45b7332cc build.sh: Stop thread allocation on dual-threaded devices 2025-10-28 11:03:47 +03:00
caff1510f9 .github/workflows/build.yml Güncelle 2025-10-28 10:54:22 +03:00
876674726d revert 4b1c1607ed
revert build.yml: use local server for builds
2025-10-28 10:16:55 +03:00
4b1c1607ed build.yml: use local server for builds 2025-10-28 09:21:34 +03:00
6a25a663e7 revert 1545511859
revert build.yml: Adapt with local git server

Signed-off-by: YZBruh <yagizzengin73@gmail.com>
2025-10-28 09:20:47 +03:00
1545511859 build.yml: Adapt with local git server
Signed-off-by: YZBruh <yagizzengin73@gmail.com>
2025-10-28 08:43:05 +03:00
34 changed files with 654 additions and 784 deletions

View File

@@ -1,6 +1,6 @@
---
Language: Cpp
AccessModifierOffset: -1
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
@@ -65,7 +65,7 @@ AlignConsecutiveTableGenDefinitionColons:
AlignFunctionDeclarations: false
AlignFunctionPointers: false
PadOperators: false
AlignEscapedNewlines: Left
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments:
Kind: Always
@@ -79,22 +79,17 @@ AllowShortCaseLabelsOnASingleLine: false
AllowShortCompoundRequirementOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AllowShortLoopsOnASingleLine: false
AllowShortNamespacesOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakBeforeMultilineStrings: false
AttributeMacros:
- __capability
- absl_nonnull
- absl_nullable
- absl_nullability_unknown
BinPackArguments: true
BinPackLongBracedList: true
BinPackParameters: BinPack
BitFieldColonSpacing: Both
BracedInitializerIndentWidth: -1
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
@@ -123,14 +118,13 @@ BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: Always
BreakBeforeBraces: Attach
BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTemplateCloser: false
BreakBeforeTernaryOperators: true
BreakBinaryOperations: Never
BreakConstructorInitializers: BeforeColon
BreakFunctionDefinitionParameters: false
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
BreakTemplateDeclarations: Yes
BreakTemplateDeclarations: MultiLine
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
@@ -141,7 +135,6 @@ DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
EnumTrailingComma: Leave
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
@@ -150,29 +143,25 @@ ForEachMacros:
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Regroup
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^<ext/.*\.h>'
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^<.*\.h>'
Priority: 1
SortPriority: 0
CaseSensitive: false
- Regex: '^<.*'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '([-_](test|unittest))?$'
- Regex: '.*'
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: true
IndentCaseLabels: false
IndentExportBlock: true
IndentExternBlock: AfterExternBlock
IndentGotoLabels: true
@@ -194,7 +183,7 @@ JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLines:
AtEndOfFile: false
AtStartOfBlock: false
AtStartOfBlock: true
AtStartOfFile: true
KeepFormFeed: false
LambdaBodyIndentation: Signature
@@ -204,15 +193,14 @@ MacroBlockEnd: ''
MainIncludeChar: Quote
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
OneLineFormatOffRegex: ''
PackConstructorInitializers: NextLine
PackConstructorInitializers: BinPack
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakBeforeMemberAccess: 150
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
@@ -222,40 +210,10 @@ PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
PPIndentWidth: -1
QualifierAlignment: Leave
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
- ParseTestProto
- ParsePartialTestProto
CanonicalDelimiter: pb
BasedOnStyle: google
ReferenceAlignment: Pointer
ReflowComments: Always
RemoveBracesLLVM: false
@@ -267,14 +225,11 @@ RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SkipMacroDefinitionBody: false
SortIncludes:
Enabled: true
IgnoreCase: false
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: LexicographicNumeric
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterOperatorKeyword: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
@@ -290,7 +245,6 @@ SpaceBeforeParensOptions:
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterNot: false
AfterOverloadedOperator: false
AfterPlacementOperator: true
AfterRequiresInClause: false
@@ -299,7 +253,7 @@ SpaceBeforeParensOptions:
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpacesBeforeTrailingComments: 2
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInContainerLiterals: true
SpacesInLineCommentPrefix:
@@ -313,7 +267,7 @@ SpacesInParensOptions:
InEmptyParentheses: false
Other: false
SpacesInSquareBrackets: false
Standard: Auto
Standard: Latest
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:

View File

@@ -35,7 +35,7 @@ jobs:
- name: Build And Prepare For Release
id: build
run: |
git clone https://github.com/ShawkTeam/pmt-renovated -b main ./pmt && cd pmt
git clone https://git.yzbruh.space/${{ github.repository }} -b main ./pmt && cd pmt
export ANDROID_NDK="${{ github.workspace }}/android-ndk-r28c"
bash build.sh clean
bash build.sh build -DCMAKE_BUILD_TYPE=Release
@@ -50,8 +50,8 @@ jobs:
echo "BUILD_DATE=$(date +%Y%m%d)" >> $GITHUB_ENV
echo "BUILD=${{ github.workspace }}/pmt" >> $GITHUB_ENV
cd ..
echo -e "Read [Wiki - About Release Types](https://github.com/ShawkTeam/pmt-renovated/wiki/About-Release-Types) for getting more information.\n\n### Changes\n" > release.txt
git log --since="2025-08-21" --pretty=format:" * %ad | [%s](https://github.com/ShawkTeam/pmt-renovated/commit/%H)" --date=short | sed 's/ -.*//' | grep -v cleanup >> release.txt
echo -e "Read [Wiki - About Release Types](https://git.yzbruh.space/${{ github.repository }}/wiki/About-Release-Types) for getting more information.\n\n### Changes\n" > release.txt
git log --since="2025-08-21" --pretty=format:" * %ad | [%s](https://git.yzbruh.space/${{ github.repository }}/commit/%H)" --date=short | sed 's/ -.*//' | grep -v cleanup >> release.txt
working-directory: ${{ github.workspace }}
- name: Upload To GitHub Releases

View File

@@ -1,25 +0,0 @@
name: Mirror External Repo to GitHub
on:
schedule:
- cron: '0 * * * *'
workflow_dispatch:
jobs:
mirror:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Mirror external repo
run: |
git config --global user.name "github-actions"
git config --global user.email "actions@github.com"
git clone --mirror https://git.yzbruh.space/YZBruh/pmt-renovated.git temp-mirror
cd temp-mirror
git remote add github https://github.com/ShawkTeam/pmt-renovated.git
git push --mirror github

View File

@@ -16,7 +16,7 @@
# Project info
cmake_minimum_required(VERSION 3.10)
project(pmt VERSION 1.3.0)
project(pmt VERSION 1.3.0-rc1)
# Set compiler flags
add_compile_options(-Wall -Werror -Wno-deprecated-declarations)

View File

@@ -61,9 +61,12 @@ build() {
-DANDROID_STL=c++_static
done
CORES=$(($(nproc --all) - 2))
[ $CORES -eq 0 ] && CORES=2
for a in ${TARGET_ABI_LIST[@]}; do
echo "Building $a artifacts... Using $(($(nproc) - 2)) thread."
cmake --build build_$a -j$(($(nproc) - 2))
echo "Building $a artifacts... Using $CORES thread."
cmake --build build_$a -j$CORES
echo "$a build complete, artifacts: $PWD/build_$a"
done
}

View File

@@ -82,8 +82,7 @@ class basic_function {
};
// A class for function management.
template <class _Type>
class basic_manager {
template <class _Type> class basic_manager {
private:
std::vector<std::unique_ptr<_Type>> _functions;

View File

@@ -19,7 +19,8 @@ RELEASE="20250821"
echo() { command echo "[$THIS]: $@"; }
checks() {
checks()
{
if ! curl "https://github.com" &>/dev/null; then
echo "No internet connection!"
exit 1
@@ -31,7 +32,8 @@ checks() {
[ ! -f $PREFIX/bin/wget ] && pkg install -y wget
}
select_variant() {
select_variant()
{
LINK=""; ARCH=""; VARIANT=""
if getprop ro.product.cpu.abi | grep "arm64-v8a" &>/dev/null; then ARCH="arm64-v8a"
@@ -42,7 +44,8 @@ select_variant() {
LINK="https://github.com/ShawkTeam/pmt-renovated/releases/download/${RELEASE}/pmt-${VARIANT}${ARCH}.zip"
}
download() {
download()
{
echo "Downloading pmt-${VARIANT}${ARCH}.zip (${RELEASE})"
if ! wget -O $PREFIX/tmp/pmt.zip "${LINK}" &>/dev/null; then
echo "Download failed! LINK=${LINK}"
@@ -57,7 +60,8 @@ download() {
fi
}
setup() {
setup()
{
[ -f $PREFIX/tmp/pmt_static ] && mv $PREFIX/tmp/pmt_static $PREFIX/tmp/pmt
set -e
install -t $PREFIX/bin $PREFIX/tmp/pmt
@@ -68,18 +72,21 @@ setup() {
echo "Installed successfully. Try running 'pmt' command."
}
uninstall() {
uninstall()
{
rm -f $PREFIX/bin/pmt $PREFIX/lib/libhelper* $PREFIX/lib/libpartition_map* &>/dev/null
}
is_installed() {
is_installed()
{
if /system/bin/which pmt &>/dev/null; then
echo "PMT is already installed."
exit 1
fi
}
cleanup() {
cleanup()
{
rm -f $PREFIX/tmp/pmt* $PREFIX/tmp/lib* $PREFIX/tmp/*.zip &>/dev/null
}

View File

@@ -14,10 +14,9 @@
limitations under the License.
*/
#include <fcntl.h>
#include <PartitionManager/PartitionManager.hpp>
#include <algorithm>
#include <fcntl.h>
#include <memory>
#include <string>
#include <unordered_set>
@@ -43,15 +42,13 @@ std::vector<std::string> splitIfHasDelim(const std::string& s, const char delim,
void setupBufferSize(uint64_t &size, const std::string &entry) {
if (PART_MAP.hasPartition(entry) && PART_MAP.sizeOf(entry) % size != 0) {
println(
"%sWARNING%s: Specified buffer size is invalid for %s! Using "
println("%sWARNING%s: Specified buffer size is invalid for %s! Using "
"different buffer size for %s.",
YELLOW, STYLE_RESET, entry.data(), entry.data());
size = PART_MAP.sizeOf(entry) % 4096 == 0 ? 4096 : 1;
} else if (Helper::fileIsExists(entry)) {
if (Helper::fileSize(entry) % size != 0) {
println(
"%sWARNING%s: Specified buffer size is invalid for %s! using "
println("%sWARNING%s: Specified buffer size is invalid for %s! using "
"different buffer size for %s.",
YELLOW, STYLE_RESET, entry.data(), entry.data());
size = Helper::fileSize(entry) % 4096 == 0 ? 4096 : 1;

View File

@@ -14,19 +14,17 @@
limitations under the License.
*/
#include "functions/functions.hpp"
#include <PartitionManager/PartitionManager.hpp>
#include <csignal>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include "functions/functions.hpp"
#ifndef ANDROID_BUILD
#include <generated/buildInfo.hpp>
#endif
#include <unistd.h>
#include <string>
#include <unistd.h>
namespace PartitionManager {
@@ -39,11 +37,8 @@ namespace PartitionManager {
FuncManager.registerFunction(std::make_unique<cls>(), AppMain)
basic_variables::basic_variables()
: logFile(Helper::LoggingProperties::FILE),
onLogical(false),
quietProcess(false),
verboseMode(false),
viewVersion(false),
: logFile(Helper::LoggingProperties::FILE), onLogical(false),
quietProcess(false), verboseMode(false), viewVersion(false),
forceProcess(false) {
try {
PartMap = std::make_unique<PartitionMap::BuildMap>();
@@ -68,8 +63,7 @@ static int write(void* cookie, const char* buf, const int size) {
const int ret = fwrite(buf, 1, static_cast<size_t>(size), real);
fflush(real);
return ret;
} else
return size;
} else return size;
}
static FILE *make_fp(FILE *real) {
@@ -117,8 +111,7 @@ int Main(int argc, char** argv) {
AppMain.fallthrough(true);
AppMain.set_help_all_flag("--help-all", "Print full help message and exit");
AppMain.footer(
"Partition Manager Tool is written by YZBruh\n"
AppMain.footer("Partition Manager Tool is written by YZBruh\n"
"This project licensed under "
"Apache 2.0 license\nReport "
"bugs to https://github.com/ShawkTeam/pmt-renovated/issues");
@@ -166,18 +159,15 @@ int Main(int argc, char** argv) {
if (FuncManager.hasFlagOnUsedFunction(NO_MAP_CHECK)) {
if (!VARS.searchPath.empty())
WARNING(
"-S (--search-path) flag is ignored. Because, don't needed "
WARNING("-S (--search-path) flag is ignored. Because, don't needed "
"partition map by your used function.\n");
if (VARS.onLogical)
WARNING(
"-l (--logical) flag ignored. Because, partition type don't "
WARNING("-l (--logical) flag ignored. Because, partition type don't "
"needed by your used function.\n");
} else {
if (!VARS.searchPath.empty()) (PART_MAP)(VARS.searchPath);
if (!VARS.PartMap && VARS.searchPath.empty())
throw Error(
"No default search entries were found. Specify a search "
throw Error("No default search entries were found. Specify a search "
"directory with -S "
"(--search-path)");

View File

@@ -14,17 +14,15 @@
limitations under the License.
*/
#include <fcntl.h>
#include <private/android_filesystem_config.h>
#include <unistd.h>
#include "functions.hpp"
#include <PartitionManager/PartitionManager.hpp>
#include <cerrno>
#include <chrono>
#include <cstdlib>
#include <fcntl.h>
#include <future>
#include "functions.hpp"
#include <private/android_filesystem_config.h>
#include <unistd.h>
#define BFUN "backupFunction"
#define FUNCTION_CLASS backupFunction
@@ -155,8 +153,7 @@ RUN {
if (!snd) {
end += fst + '\n';
endResult = false;
} else
println("%s", fst.c_str());
} else println("%s", fst.c_str());
}
if (!endResult) throw Error("%s", end.c_str());

View File

@@ -14,9 +14,8 @@ Copyright 2025 Yağız Zengin
limitations under the License.
*/
#include <PartitionManager/PartitionManager.hpp>
#include "functions.hpp"
#include <PartitionManager/PartitionManager.hpp>
#define CFUN "cleanLogFunction"
#define FUNCTION_CLASS cleanLogFunction

View File

@@ -14,14 +14,12 @@ Copyright 2025 Yağız Zengin
limitations under the License.
*/
#include <fcntl.h>
#include <unistd.h>
#include "functions.hpp"
#include <PartitionManager/PartitionManager.hpp>
#include <cerrno>
#include <fcntl.h>
#include <future>
#include "functions.hpp"
#include <unistd.h>
#define EFUN "eraseFunction"
#define FUNCTION_CLASS eraseFunction
@@ -83,8 +81,7 @@ RUN_ASYNC(const std::string& partitionName, const uint64_t bufferSize) {
return {Helper::format("Can't write zero bytes to partition: %s: %s",
partitionName.data(), strerror(errno)),
false};
else
bytesWritten += result;
else bytesWritten += result;
}
return {Helper::format("Successfully wrote zero bytes to the %s partition",
@@ -123,8 +120,7 @@ RUN {
if (!snd) {
end += fst + '\n';
endResult = false;
} else
println("%s", fst.c_str());
} else println("%s", fst.c_str());
}
if (!endResult) throw Error("%s", end.c_str());

View File

@@ -14,15 +14,13 @@ Copyright 2025 Yağız Zengin
limitations under the License.
*/
#include <fcntl.h>
#include <unistd.h>
#include "functions.hpp"
#include <PartitionManager/PartitionManager.hpp>
#include <cerrno>
#include <cstdlib>
#include <fcntl.h>
#include <future>
#include "functions.hpp"
#include <unistd.h>
#define FFUN "flashFunction"
#define FUNCTION_CLASS flashFunction
@@ -153,8 +151,7 @@ RUN {
if (!snd) {
end += fst + '\n';
endResult = false;
} else
println("%s", fst.c_str());
} else println("%s", fst.c_str());
}
if (!endResult) throw Error("%s", end.c_str());

View File

@@ -14,15 +14,13 @@ Copyright 2025 Yağız Zengin
limitations under the License.
*/
#include <fcntl.h>
#include "functions.hpp"
#include <PartitionManager/PartitionManager.hpp>
#include <cerrno>
#include <cstdlib>
#include <fcntl.h>
#include <nlohmann/json.hpp>
#include "functions.hpp"
#define IFUN "infoFunction"
#define FUNCTION_CLASS infoFunction
@@ -32,8 +30,7 @@ INIT {
LOGN(IFUN, INFO) << "Initializing variables of info printer function."
<< std::endl;
cmd = _app.add_subcommand("info", "Tell info(s) of input partition list")
->footer(
"Use get-all or getvar-all as partition name for getting "
->footer("Use get-all or getvar-all as partition name for getting "
"info's of all partitions.\nUse get-logicals as partition "
"name for getting info's of logical partitions.\n"
"Use get-physical as partition name for getting info's of "
@@ -106,8 +103,7 @@ RUN {
PART_MAP.doForLogicalPartitions(func);
else if (partitions.back() == "get-physicals")
PART_MAP.doForPhysicalPartitions(func);
else
PART_MAP.doForPartitionList(partitions, func);
else PART_MAP.doForPartitionList(partitions, func);
if (jsonFormat) {
nlohmann::json j;

View File

@@ -14,16 +14,14 @@ Copyright 2025 Yağız Zengin
limitations under the License.
*/
#include <fcntl.h>
#include <unistd.h>
#include "functions.hpp"
#include <PartitionManager/PartitionManager.hpp>
#include <chrono>
#include <cstdlib>
#include <cstring>
#include <fcntl.h>
#include <random>
#include "functions.hpp"
#include <unistd.h>
#define MTFUN "memoryTestFunction"
#define FUNCTION_CLASS memoryTestFunction

View File

@@ -14,9 +14,8 @@ Copyright 2025 Yağız Zengin
limitations under the License.
*/
#include <PartitionManager/PartitionManager.hpp>
#include "functions.hpp"
#include <PartitionManager/PartitionManager.hpp>
#define SFUN "partitionSizeFunction"
#define FUNCTION_CLASS partitionSizeFunction
@@ -27,8 +26,7 @@ INIT {
<< "Initializing variables of partition size getter function."
<< std::endl;
cmd = _app.add_subcommand("sizeof", "Tell size(s) of input partition list")
->footer(
"Use get-all or getvar-all as partition name for getting "
->footer("Use get-all or getvar-all as partition name for getting "
"sizes of all partitions.\nUse get-logicals as partition "
"name for getting sizes of logical partitions.\n"
"Use get-physical as partition name for getting sizes of "
@@ -74,8 +72,7 @@ RUN {
partition.data());
}
if (onlySize)
println("%d", Helper::convertTo(props.size, multiple));
if (onlySize) println("%d", Helper::convertTo(props.size, multiple));
else
println("%s: %d%s", partition.data(),
Helper::convertTo(props.size, multiple),
@@ -90,8 +87,7 @@ RUN {
PART_MAP.doForLogicalPartitions(func);
else if (partitions.back() == "get-physicals")
PART_MAP.doForPhysicalPartitions(func);
else
PART_MAP.doForPartitionList(partitions, func);
else PART_MAP.doForPartitionList(partitions, func);
return true;
}

View File

@@ -14,9 +14,8 @@
limitations under the License.
*/
#include <PartitionManager/PartitionManager.hpp>
#include "functions.hpp"
#include <PartitionManager/PartitionManager.hpp>
#define RPFUN "realPathFunction"
#define FUNCTION_CLASS realPathFunction
@@ -52,8 +51,7 @@ RUN {
if (realLinkPath)
println("%s", PART_MAP.getRealLinkPathOf(partition).data());
else
println("%s", PART_MAP.getRealPathOf(partition).data());
else println("%s", PART_MAP.getRealPathOf(partition).data());
}
return true;

View File

@@ -14,9 +14,8 @@ Copyright 2025 Yağız Zengin
limitations under the License.
*/
#include <PartitionManager/PartitionManager.hpp>
#include "functions.hpp"
#include <PartitionManager/PartitionManager.hpp>
#define RFUN "rebootFunction"
#define FUNCTION_CLASS rebootFunction
@@ -36,10 +35,8 @@ RUN {
<< (rebootTarget.empty() ? "none" : rebootTarget)
<< std::endl;
if (Helper::androidReboot(rebootTarget))
println("Reboot command was sent");
else
throw Error("Cannot reboot device");
if (Helper::androidReboot(rebootTarget)) println("Reboot command was sent");
else throw Error("Cannot reboot device");
return true;
}

View File

@@ -14,11 +14,10 @@
limitations under the License.
*/
#include "functions.hpp"
#include <PartitionManager/PartitionManager.hpp>
#include <map>
#include "functions.hpp"
#define TFUN "typeFunction"
#define FUNCTION_CLASS typeFunction
@@ -48,8 +47,7 @@ RUN {
magics.merge(PartitionMap::Extras::AndroidMagicMap);
else if (onlyCheckFileSystemMagics)
magics.merge(PartitionMap::Extras::FileSystemMagicMap);
else
magics.merge(PartitionMap::Extras::MagicMap);
else magics.merge(PartitionMap::Extras::MagicMap);
for (const auto &content : contents) {
if (!PART_MAP.hasPartition(content) && !Helper::fileIsExists(content))

View File

@@ -17,9 +17,8 @@
#ifndef LIBHELPER_LIB_HPP
#define LIBHELPER_LIB_HPP
#include <dirent.h>
#include <cstdint>
#include <dirent.h>
#include <exception>
#include <functional>
#include <optional>
@@ -87,8 +86,7 @@ class Logger final {
~Logger();
template <typename T>
Logger& operator<<(const T& msg) {
template <typename T> Logger &operator<<(const T &msg) {
_oss << msg;
return *this;
}
@@ -108,8 +106,7 @@ class garbageCollector {
public:
~garbageCollector();
template <typename T>
void delAfterProgress(T* _ptr) {
template <typename T> void delAfterProgress(T *_ptr) {
_cleaners.push_back([_ptr] { delete[] _ptr; });
}
@@ -133,10 +130,12 @@ class Random {
if constexpr (d > 0) {
std::uniform_int_distribution<> dist(0, (max - start - 1) / d);
while (set.size() < count) set.insert(start + dist(gen) * d);
while (set.size() < count)
set.insert(start + dist(gen) * d);
} else {
std::uniform_int_distribution<> dist(start, max - 1);
while (set.size() < count) set.insert(dist(gen));
while (set.size() < count)
set.insert(dist(gen));
}
return set;
@@ -159,15 +158,15 @@ class Random {
}
};
template <typename _Type1, typename _Type2, typename _Type3>
class PureTuple {
template <typename _Type1, typename _Type2, typename _Type3> class PureTuple {
private:
void expand_if_needed() {
if (count == capacity) {
capacity *= 2;
Data *data = new Data[capacity];
for (size_t i = 0; i < count; i++) data[i] = tuple_data[i];
for (size_t i = 0; i < count; i++)
data[i] = tuple_data[i];
delete[] tuple_data;
tuple_data = data;
@@ -180,8 +179,8 @@ class PureTuple {
_Type2 second;
_Type3 third;
bool operator==(
const std::tuple<_Type1, _Type2, _Type3>& t) const noexcept {
bool
operator==(const std::tuple<_Type1, _Type2, _Type3> &t) const noexcept {
return first == std::get<0>(t) && second == std::get<1>(t) &&
third == std::get<2>(t);
}
@@ -224,17 +223,16 @@ class PureTuple {
PureTuple(std::initializer_list<Data> val)
: tuple_data(new Data[20]), capacity(20), count(0) {
for (const auto& v : val) insert(v);
for (const auto &v : val)
insert(v);
}
PureTuple(PureTuple &other)
: tuple_data(new Data[other.capacity]),
capacity(other.capacity),
: tuple_data(new Data[other.capacity]), capacity(other.capacity),
count(other.count) {
std::copy(other.tuple_data, other.tuple_data + count, tuple_data);
}
PureTuple(PureTuple &&other) noexcept
: tuple_data(new Data[other.capacity]),
capacity(other.capacity),
: tuple_data(new Data[other.capacity]), capacity(other.capacity),
count(other.count) {
std::copy(other.tuple_data, other.tuple_data + count, tuple_data);
other.clear();
@@ -345,7 +343,8 @@ class PureTuple {
}
void merge(const PureTuple &other) noexcept {
for (const auto& v : other) insert(v);
for (const auto &v : other)
insert(v);
}
void pop_back() noexcept {
@@ -482,8 +481,7 @@ class PureTuple {
};
// Provides a capsule structure to store variable references and values.
template <typename _Type>
class Capsule : public garbageCollector {
template <typename _Type> class Capsule : public garbageCollector {
public:
_Type &value;
@@ -565,19 +563,13 @@ void set(std::string_view name, std::string_view file);
void setProgramName(std::string_view name);
void setLogFile(std::string_view file);
template <int state>
void setPrinting() {
if (state == 1 || state == 0)
PRINT = state;
else
PRINT = NO;
template <int state> void setPrinting() {
if (state == 1 || state == 0) PRINT = state;
else PRINT = NO;
}
template <int state>
void setLoggingState() {
if (state == 1 || state == 0)
DISABLE = state;
else
DISABLE = NO;
template <int state> void setLoggingState() {
if (state == 1 || state == 0) DISABLE = state;
else DISABLE = NO;
}
void reset();
@@ -817,8 +809,7 @@ __attribute__((format(printf, 1, 2))) std::string format(const char* format,
/**
* Convert input size to input multiple
*/
template <uint64_t size>
int convertTo(const sizeCastTypes type) {
template <uint64_t size> int convertTo(const sizeCastTypes type) {
if (type == KB) return TO_KB(size);
if (type == MB) return TO_MB(size);
if (type == GB) return TO_GB(size);

View File

@@ -14,13 +14,12 @@
limitations under the License.
*/
#include <private/android_filesystem_config.h>
#include <sys/stat.h>
#include <unistd.h>
#include <cstdio>
#include <cstdlib>
#include <libhelper/lib.hpp>
#include <private/android_filesystem_config.h>
#include <sys/stat.h>
#include <unistd.h>
namespace Helper {
bool hasSuperUser() { return (getuid() == AID_ROOT); }

View File

@@ -14,20 +14,19 @@
limitations under the License.
*/
#include <dirent.h>
#include <fcntl.h>
#include <libgen.h>
#include <unistd.h>
#include <cerrno>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <dirent.h>
#include <exception>
#include <fcntl.h>
#include <functional>
#include <libgen.h>
#include <libhelper/lib.hpp>
#include <sstream>
#include <unistd.h>
namespace Helper {
Error::Error(const char *format, ...) {
@@ -44,12 +43,8 @@ const char* Error::what() const noexcept { return _message.data(); }
Logger::Logger(const LogLevels level, const char *func, const char *file,
const char *name, const char *source_file, const int line)
: _level(level),
_function_name(func),
_logFile(file),
_program_name(name),
_file(source_file),
_line(line) {}
: _level(level), _function_name(func), _logFile(file), _program_name(name),
_file(source_file), _line(line) {}
Logger::~Logger() {
if (LoggingProperties::DISABLE) return;
@@ -102,11 +97,16 @@ Logger& Logger::operator<<(std::ostream& (*msg)(std::ostream&)) {
}
garbageCollector::~garbageCollector() {
for (auto& ptr_func : _cleaners) ptr_func();
for (const auto& fd : _fds) close(fd);
for (const auto& fp : _fps) fclose(fp);
for (const auto& dp : _dps) closedir(dp);
for (const auto& file : _files) eraseEntry(file);
for (auto &ptr_func : _cleaners)
ptr_func();
for (const auto &fd : _fds)
close(fd);
for (const auto &fp : _fps)
fclose(fp);
for (const auto &dp : _dps)
closedir(dp);
for (const auto &file : _files)
eraseEntry(file);
}
void garbageCollector::delFileAfterProgress(const std::string &_path) {

View File

@@ -14,17 +14,16 @@
limitations under the License.
*/
#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <dirent.h>
#include <fcntl.h>
#include <libhelper/lib.hpp>
#include <string>
#include <sys/stat.h>
#include <unistd.h>
namespace Helper {
bool writeFile(const std::string_view file, const std::string_view text) {
@@ -49,7 +48,8 @@ std::optional<std::string> readFile(const std::string_view file) {
char buffer[1024];
std::string str;
while (fgets(buffer, sizeof(buffer), fp)) str += buffer;
while (fgets(buffer, sizeof(buffer), fp))
str += buffer;
LOGN(HELPER, INFO) << "read " << file << " successfully, read text: \"" << str
<< "\"" << std::endl;

View File

@@ -14,14 +14,13 @@
limitations under the License.
*/
#include <picosha2.h>
#include <sys/stat.h>
#include <fstream>
#include <iostream>
#include <libhelper/lib.hpp>
#include <optional>
#include <picosha2.h>
#include <string>
#include <sys/stat.h>
#include <vector>
namespace Helper {

View File

@@ -14,31 +14,28 @@
limitations under the License.
*/
#include <cutils/android_reboot.h>
#include <fcntl.h>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cutils/android_reboot.h>
#include <fcntl.h>
#ifndef ANDROID_BUILD
#include <sys/_system_properties.h>
#include <generated/buildInfo.hpp>
#include <sys/_system_properties.h>
#else
#include <sys/system_properties.h>
#endif
#include <cutils/android_reboot.h>
#include <libgen.h>
#include <sys/_system_properties.h>
#include <sys/stat.h>
#include <unistd.h>
#include <cstdarg>
#include <cutils/android_reboot.h>
#include <iostream>
#include <libgen.h>
#include <libhelper/lib.hpp>
#include <memory>
#include <string>
#include <string_view>
#include <sys/_system_properties.h>
#include <sys/stat.h>
#include <unistd.h>
#ifdef __ANDROID__
// From system/core/libcutils/android_reboot.cpp android16-s2-release
@@ -61,10 +58,8 @@ int android_reboot(const unsigned cmd, int /*flags*/, const char* arg) {
}
if (!restart_cmd) return -1;
if (arg && arg[0])
ret = asprintf(&prop_value, "%s,%s", restart_cmd, arg);
else
ret = asprintf(&prop_value, "%s", restart_cmd);
if (arg && arg[0]) ret = asprintf(&prop_value, "%s,%s", restart_cmd, arg);
else ret = asprintf(&prop_value, "%s", restart_cmd);
if (ret < 0) return -1;
ret = __system_property_set(ANDROID_RB_PROPERTY, prop_value);

View File

@@ -51,13 +51,11 @@ int main(int argc, char** argv) {
if (!Helper::writeFile("file.txt", "hello world"))
throw Helper::Error("Cannot write \"hello world\" in 'file.txt'");
else
std::cout << "file.txt writed." << std::endl;
else std::cout << "file.txt writed." << std::endl;
if (const auto content = Helper::readFile("file.txt"); !content)
throw Helper::Error("Cannot read 'file.txt'");
else
std::cout << "'file.txt': " << *content << std::endl;
else std::cout << "'file.txt': " << *content << std::endl;
std::cout << "Making directory 'dir2': " << std::boolalpha
<< Helper::makeDirectory(test_path("dir2")) << std::endl;
@@ -82,8 +80,7 @@ int main(int argc, char** argv) {
if (const auto sha256 = Helper::sha256Of(test_path("file2.txt")); !sha256)
throw Helper::Error("Cannot get sha256 of 'file2.txt'");
else
std::cout << "SHA256 of 'file2.txt': " << *sha256 << std::endl;
else std::cout << "SHA256 of 'file2.txt': " << *sha256 << std::endl;
std::cout << "'file2.txt' and 'file2lnk.txt' same? (SHA256): "
<< std::boolalpha

View File

@@ -98,7 +98,8 @@ class basic_partition_map {
explicit iterator(_entry *p);
auto operator*() const -> std::pair<std::string&, decltype(_entry::props)&>;
auto operator*() const
-> std::pair<std::string &, decltype(_entry::props) &>;
_entry *operator->() const;
iterator &operator++();
iterator operator++(int);
@@ -173,8 +174,8 @@ class basic_partition_map_builder final {
* Map_temp_t type. If the partition is not in the
* currently created list, returns std::nullopt.
*/
[[nodiscard]] std::optional<std::pair<uint64_t, bool>> get(
std::string_view name) const;
[[nodiscard]] std::optional<std::pair<uint64_t, bool>>
get(std::string_view name) const;
/**
* If there is a logical partition(s) in the created
@@ -182,16 +183,16 @@ class basic_partition_map_builder final {
* data of type std::string). If there is no logical
* partition in the created list, it returns std::nullopt.
*/
[[nodiscard]] std::optional<std::list<std::string>> getLogicalPartitionList()
const;
[[nodiscard]] std::optional<std::list<std::string>>
getLogicalPartitionList() const;
/**
* The physical partitions in the created list are
* returned as std::list type. If there is no content
* due to any problem, returns std::nullopt.
*/
[[nodiscard]] std::optional<std::list<std::string>> getPhysicalPartitionList()
const;
[[nodiscard]] std::optional<std::list<std::string>>
getPhysicalPartitionList() const;
/**
* The partitions in the created list are returned as std::list

View File

@@ -25,8 +25,8 @@ Map_t basic_partition_map_builder::getAll() const {
return _current_map;
}
std::optional<std::pair<uint64_t, bool>> basic_partition_map_builder::get(
const std::string_view name) const {
std::optional<std::pair<uint64_t, bool>>
basic_partition_map_builder::get(const std::string_view name) const {
_map_build_check();
if (!_current_map.find(name)) return std::nullopt;
@@ -63,7 +63,8 @@ basic_partition_map_builder::getPartitionList() const {
_map_build_check();
std::list<std::string> partitions;
for (const auto& [name, props] : _current_map) partitions.push_back(name);
for (const auto &[name, props] : _current_map)
partitions.push_back(name);
if (partitions.empty()) return std::nullopt;
return partitions;
@@ -77,8 +78,8 @@ std::string basic_partition_map_builder::getRealLinkPathOf(
return std::string(_workdir + "/" + name.data());
}
std::string basic_partition_map_builder::getRealPathOf(
const std::string_view name) const {
std::string
basic_partition_map_builder::getRealPathOf(const std::string_view name) const {
_map_build_check();
const std::string full = (isLogical(name))

View File

@@ -15,13 +15,12 @@
*/
#include <fcntl.h>
#include <unistd.h>
#include <libhelper/lib.hpp>
#include <libpartition_map/lib.hpp>
#include <map>
#include <sstream>
#include <string>
#include <unistd.h>
#include "PartitionManager/PartitionManager.hpp"

View File

@@ -14,26 +14,24 @@
limitations under the License.
*/
#include <fcntl.h>
#include <algorithm>
#include <array>
#include <cerrno>
#include <cstring>
#include <fcntl.h>
#include <filesystem>
#ifndef ANDROID_BUILD
#include <generated/buildInfo.hpp>
#endif
#include <linux/fs.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <iostream>
#include <libpartition_map/lib.hpp>
#include <linux/fs.h>
#include <memory>
#include <string>
#include <string_view>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <vector>
static constexpr std::array<std::string_view, 3> defaultEntryList = {
@@ -151,10 +149,8 @@ basic_partition_map_builder::basic_partition_map_builder(
if (std::filesystem::exists(path)) {
if (!_is_real_block_dir(path)) return;
_current_map = _build_map(path);
if (_current_map.empty())
_any_generating_error = true;
else
_workdir = path;
if (_current_map.empty()) _any_generating_error = true;
else _workdir = path;
} else
throw Error("Cannot find directory: %s. Cannot build partition map!",
path.data());
@@ -209,8 +205,7 @@ bool basic_partition_map_builder::readDirectory(const std::string_view path) {
if (_current_map.empty()) {
_any_generating_error = true;
return false;
} else
_workdir = path;
} else _workdir = path;
} else
throw Error("Cannot find directory: %s. Cannot build partition map!",
path.data());
@@ -255,7 +250,8 @@ bool basic_partition_map_builder::copyPartitionsToVector(
return false;
}
vec.clear();
for (const auto& [name, props] : _current_map) vec.push_back(name);
for (const auto &[name, props] : _current_map)
vec.push_back(name);
return true;
}
@@ -272,8 +268,7 @@ bool basic_partition_map_builder::copyLogicalPartitionsToVector(
if (vec2.empty()) {
LOGN(MAP, ERROR) << "Cannot find logical partitions in current map.";
return false;
} else
vec = vec2;
} else vec = vec2;
return true;
}
@@ -290,8 +285,7 @@ bool basic_partition_map_builder::copyPhysicalPartitionsToVector(
if (vec2.empty()) {
LOGN(MAP, ERROR) << "Cannot find physical partitions in current map.";
return false;
} else
vec = vec2;
} else vec = vec2;
return true;
}
@@ -385,8 +379,8 @@ bool basic_partition_map_builder::doForPartitionList(
return err;
}
uint64_t basic_partition_map_builder::sizeOf(
const std::string_view name) const {
uint64_t
basic_partition_map_builder::sizeOf(const std::string_view name) const {
_map_build_check();
return _current_map.get_size(name);
}
@@ -425,8 +419,8 @@ Info basic_partition_map_builder::operator[](const int index) const {
return _current_map[index];
}
BasicInf basic_partition_map_builder::operator[](
const std::string_view& name) const {
BasicInf
basic_partition_map_builder::operator[](const std::string_view &name) const {
return _current_map[name];
}

View File

@@ -87,7 +87,8 @@ void basic_partition_map::_resize_map() {
const size_t new_capacity = _capacity * 2;
auto *new_data = new _entry[new_capacity];
for (size_t i = 0; i < _count; i++) new_data[i] = _data[i];
for (size_t i = 0; i < _count; i++)
new_data[i] = _data[i];
delete[] _data;
_data = new_data;
@@ -110,15 +111,13 @@ basic_partition_map::basic_partition_map(const std::string& name,
}
basic_partition_map::basic_partition_map(const basic_partition_map &other)
: _data(new _entry[other._capacity]),
_count(other._count),
: _data(new _entry[other._capacity]), _count(other._count),
_capacity(other._capacity) {
std::copy(other._data, other._data + _count, _data);
}
basic_partition_map::basic_partition_map(basic_partition_map &&other) noexcept
: _data(new _entry[other._capacity]),
_count(other._count),
: _data(new _entry[other._capacity]), _count(other._count),
_capacity(other._capacity) {
std::copy(other._data, other._data + _count, _data);
other.clear();
@@ -163,8 +162,8 @@ bool basic_partition_map::is_logical(const std::string_view name) const {
return false;
}
_returnable_entry basic_partition_map::get_all(
const std::string_view name) const {
_returnable_entry
basic_partition_map::get_all(const std::string_view name) const {
if (const int pos = _index_of(name); name == _data[pos].name)
return _returnable_entry{_data[pos].props.size, _data[pos].props.isLogical};
@@ -195,8 +194,8 @@ void basic_partition_map::clear() {
_data = new _entry[_capacity];
}
basic_partition_map& basic_partition_map::operator=(
const basic_partition_map& map) {
basic_partition_map &
basic_partition_map::operator=(const basic_partition_map &map) {
if (this != &map) {
delete[] _data;
@@ -218,8 +217,7 @@ bool basic_partition_map::operator==(const basic_partition_map& other) const {
_data[i].props.size == other._data[i].props.size &&
_data[i].props.isLogical == other._data[i].props.isLogical)
continue;
else
return false;
else return false;
return true;
}

View File

@@ -14,11 +14,10 @@
limitations under the License.
*/
#include <unistd.h>
#include <fstream>
#include <iostream>
#include <libpartition_map/lib.hpp>
#include <unistd.h>
int main() {
if (getuid() != 0) return 2;