pmt: reformat code and improve workflow
This commit is contained in:
5
.github/workflows/build.yml
vendored
5
.github/workflows/build.yml
vendored
@@ -49,6 +49,9 @@ jobs:
|
|||||||
zip pmt-static-armeabi-v7a.zip pmt_static
|
zip pmt-static-armeabi-v7a.zip pmt_static
|
||||||
echo "BUILD_DATE=$(date +%Y%m%d)" >> $GITHUB_ENV
|
echo "BUILD_DATE=$(date +%Y%m%d)" >> $GITHUB_ENV
|
||||||
echo "BUILD=${{ github.workspace }}/pmt" >> $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
|
||||||
working-directory: ${{ github.workspace }}
|
working-directory: ${{ github.workspace }}
|
||||||
|
|
||||||
- name: Upload To GitHub Releases
|
- name: Upload To GitHub Releases
|
||||||
@@ -60,4 +63,4 @@ jobs:
|
|||||||
${{ env.BUILD }}/build_armeabi-v7a/*.zip
|
${{ env.BUILD }}/build_armeabi-v7a/*.zip
|
||||||
name: Partition Manager Tool Release ${{ env.BUILD_DATE }}
|
name: Partition Manager Tool Release ${{ env.BUILD_DATE }}
|
||||||
tag_name: ${{ env.BUILD_DATE }}
|
tag_name: ${{ env.BUILD_DATE }}
|
||||||
body: "Read [Wiki - About Release Types](https://github.com/ShawkTeam/pmt-renovated/wiki/About-Release-Types) for getting more information."
|
body_path: ${{ env.BUILD }}/release.txt
|
||||||
|
|||||||
@@ -15,12 +15,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <PartitionManager/PartitionManager.hpp>
|
#include <PartitionManager/PartitionManager.hpp>
|
||||||
|
#include <algorithm>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
namespace PartitionManager {
|
namespace PartitionManager {
|
||||||
std::vector<std::string> splitIfHasDelim(const std::string &s, const char delim,
|
std::vector<std::string> splitIfHasDelim(const std::string &s, const char delim,
|
||||||
@@ -96,9 +96,11 @@ bool basic_function_manager::hasFlagOnUsedFunction(const int flag) const {
|
|||||||
for (const auto &func : _functions) {
|
for (const auto &func : _functions) {
|
||||||
if (func->isUsed()) {
|
if (func->isUsed()) {
|
||||||
std::for_each(func->flags.begin(), func->flags.end(), [&](const int x) {
|
std::for_each(func->flags.begin(), func->flags.end(), [&](const int x) {
|
||||||
LOGN(PMTF, INFO) << "Used flag " << x << " on " << func->name() << std::endl;
|
LOGN(PMTF, INFO) << "Used flag " << x << " on " << func->name()
|
||||||
|
<< std::endl;
|
||||||
});
|
});
|
||||||
return std::find(func->flags.begin(), func->flags.end(), flag) != func->flags.end();
|
return std::find(func->flags.begin(), func->flags.end(), flag) !=
|
||||||
|
func->flags.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -47,13 +47,13 @@ __attribute__((constructor)) void init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void sigHandler(const int sig) {
|
static void sigHandler(const int sig) {
|
||||||
if (sig == SIGINT) println("\n%sInterrupted.%s", YELLOW, STYLE_RESET);
|
if (sig == SIGINT) println("\n%sInterrupted.%s", YELLOW, STYLE_RESET);
|
||||||
if (sig == SIGABRT) println("\n%sAborted.%s", RED, STYLE_RESET);
|
if (sig == SIGABRT) println("\n%sAborted.%s", RED, STYLE_RESET);
|
||||||
exit(sig);
|
exit(sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int write(void *cookie, const char *buf, const int size) {
|
static int write(void *cookie, const char *buf, const int size) {
|
||||||
auto *real = static_cast<FILE*>(cookie);
|
auto *real = static_cast<FILE *>(cookie);
|
||||||
if (!VARS.quietProcess) {
|
if (!VARS.quietProcess) {
|
||||||
const int ret = fwrite(buf, 1, static_cast<size_t>(size), real);
|
const int ret = fwrite(buf, 1, static_cast<size_t>(size), real);
|
||||||
fflush(real);
|
fflush(real);
|
||||||
@@ -163,9 +163,8 @@ int Main(int argc, char **argv) {
|
|||||||
|
|
||||||
if (!Helper::hasSuperUser() && !FuncManager.hasFlagOnUsedFunction(NO_SU)) {
|
if (!Helper::hasSuperUser() && !FuncManager.hasFlagOnUsedFunction(NO_SU)) {
|
||||||
if (!(FuncManager.hasFlagOnUsedFunction(ADB_SUFFICIENT) &&
|
if (!(FuncManager.hasFlagOnUsedFunction(ADB_SUFFICIENT) &&
|
||||||
Helper::hasAdbPermissions())) {
|
Helper::hasAdbPermissions())) {
|
||||||
throw Error(
|
throw Error("This function is requires super-user privileges!");
|
||||||
"This function is requires super-user privileges!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ Copyright 2025 Yağız Zengin
|
|||||||
|
|
||||||
namespace PartitionManager {
|
namespace PartitionManager {
|
||||||
INIT {
|
INIT {
|
||||||
LOGN(CFUN, INFO) << "Initializing variables of clean log function." << std::endl;
|
LOGN(CFUN, INFO) << "Initializing variables of clean log function."
|
||||||
|
<< std::endl;
|
||||||
flags = {FunctionFlags::NO_MAP_CHECK, FunctionFlags::NO_SU};
|
flags = {FunctionFlags::NO_MAP_CHECK, FunctionFlags::NO_SU};
|
||||||
cmd = _app.add_subcommand("clean-logs", "Clean PMT logs.");
|
cmd = _app.add_subcommand("clean-logs", "Clean PMT logs.");
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -42,17 +42,12 @@ INIT {
|
|||||||
"Print info(s) as JSON body. The body of each partition will "
|
"Print info(s) as JSON body. The body of each partition will "
|
||||||
"be written separately")
|
"be written separately")
|
||||||
->default_val(false);
|
->default_val(false);
|
||||||
cmd->add_flag("--as-byte", asByte,
|
cmd->add_flag("--as-byte", asByte, "View sizes as byte.")->default_val(true);
|
||||||
"View sizes as byte.")
|
cmd->add_flag("--as-kilobyte", asKiloBytes, "View sizes as kilobyte.")
|
||||||
->default_val(true);
|
|
||||||
cmd->add_flag("--as-kilobyte", asKiloBytes,
|
|
||||||
"View sizes as kilobyte.")
|
|
||||||
->default_val(false);
|
->default_val(false);
|
||||||
cmd->add_flag("--as-megabyte", asMega,
|
cmd->add_flag("--as-megabyte", asMega, "View sizes as megabyte.")
|
||||||
"View sizes as megabyte.")
|
|
||||||
->default_val(false);
|
->default_val(false);
|
||||||
cmd->add_flag("--as-gigabyte", asGiga,
|
cmd->add_flag("--as-gigabyte", asGiga, "View sizes as gigabyte.")
|
||||||
"View sizes as gigabyte.")
|
|
||||||
->default_val(false);
|
->default_val(false);
|
||||||
cmd->add_option("--json-partition-name", jNamePartition,
|
cmd->add_option("--json-partition-name", jNamePartition,
|
||||||
"Specify partition name element for JSON body")
|
"Specify partition name element for JSON body")
|
||||||
@@ -90,10 +85,13 @@ RUN {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (jsonFormat)
|
if (jsonFormat)
|
||||||
jParts.push_back({partition, {std::stoull(Helper::convertTo(props.size, multiple)), props.isLogical}});
|
jParts.push_back({partition,
|
||||||
|
{std::stoull(Helper::convertTo(props.size, multiple)),
|
||||||
|
props.isLogical}});
|
||||||
else
|
else
|
||||||
println("partition=%s size=%s isLogical=%s",
|
println("partition=%s size=%s isLogical=%s", partition.data(),
|
||||||
partition.data(), Helper::convertTo(props.size, multiple).data(), props.isLogical ? "true" : "false");
|
Helper::convertTo(props.size, multiple).data(),
|
||||||
|
props.isLogical ? "true" : "false");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,12 +20,12 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <functional>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
#define KB(x) (static_cast<uint64_t>(x) * 1024) // KB(8) = 8192 (8 * 1024)
|
#define KB(x) (static_cast<uint64_t>(x) * 1024) // KB(8) = 8192 (8 * 1024)
|
||||||
#define MB(x) (KB(x) * 1024) // MB(4) = 4194304 (KB(4) * 1024)
|
#define MB(x) (KB(x) * 1024) // MB(4) = 4194304 (KB(4) * 1024)
|
||||||
@@ -96,9 +96,8 @@ private:
|
|||||||
public:
|
public:
|
||||||
~garbageCollector();
|
~garbageCollector();
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> void delAfterProgress(T *_ptr) {
|
||||||
void delAfterProgress(T *_ptr) {
|
_cleaners.push_back([_ptr] { delete[] _ptr; });
|
||||||
_cleaners.push_back([_ptr] { delete[] _ptr; });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void delFileAfterProgress(const std::string &_path);
|
void delFileAfterProgress(const std::string &_path);
|
||||||
@@ -115,13 +114,11 @@ void set(std::string_view name, std::string_view file);
|
|||||||
void setProgramName(std::string_view name);
|
void setProgramName(std::string_view name);
|
||||||
void setLogFile(std::string_view file);
|
void setLogFile(std::string_view file);
|
||||||
|
|
||||||
template <int state>
|
template <int state> void setPrinting() {
|
||||||
void setPrinting() {
|
|
||||||
if (state == 1 || state == 0) PRINT = state;
|
if (state == 1 || state == 0) PRINT = state;
|
||||||
else PRINT = NO;
|
else PRINT = NO;
|
||||||
}
|
}
|
||||||
template <int state>
|
template <int state> void setLoggingState() {
|
||||||
void setLoggingState() {
|
|
||||||
if (state == 1 || state == 0) DISABLE = state;
|
if (state == 1 || state == 0) DISABLE = state;
|
||||||
else DISABLE = NO;
|
else DISABLE = NO;
|
||||||
}
|
}
|
||||||
@@ -352,8 +349,7 @@ std::string convertTo(uint64_t size, const std::string &multiple);
|
|||||||
/**
|
/**
|
||||||
* Convert input size to input multiple
|
* Convert input size to input multiple
|
||||||
*/
|
*/
|
||||||
template <uint64_t size>
|
template <uint64_t size> std::string convertTo(const std::string &multiple) {
|
||||||
std::string convertTo(const std::string &multiple) {
|
|
||||||
if (multiple == "KB") return std::to_string(TO_KB(size));
|
if (multiple == "KB") return std::to_string(TO_KB(size));
|
||||||
if (multiple == "MB") return std::to_string(TO_MB(size));
|
if (multiple == "MB") return std::to_string(TO_MB(size));
|
||||||
if (multiple == "GB") return std::to_string(TO_GB(size));
|
if (multiple == "GB") return std::to_string(TO_GB(size));
|
||||||
|
|||||||
@@ -21,8 +21,8 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <functional>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <functional>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <libhelper/lib.hpp>
|
#include <libhelper/lib.hpp>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#else
|
#else
|
||||||
#include <sys/system_properties.h>
|
#include <sys/system_properties.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <cutils/android_reboot.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <libhelper/lib.hpp>
|
#include <libhelper/lib.hpp>
|
||||||
@@ -32,7 +33,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <sys/_system_properties.h>
|
#include <sys/_system_properties.h>
|
||||||
#include <cutils/android_reboot.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ public:
|
|||||||
explicit operator bool() const;
|
explicit operator bool() const;
|
||||||
|
|
||||||
Info operator[](int index) const;
|
Info operator[](int index) const;
|
||||||
BasicInf operator[](const std::string_view& name) const;
|
BasicInf operator[](const std::string_view &name) const;
|
||||||
|
|
||||||
operator std::vector<Info>() const;
|
operator std::vector<Info>() const;
|
||||||
operator int() const;
|
operator int() const;
|
||||||
@@ -363,7 +363,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Get BasicInfo structure with given index
|
* Get BasicInfo structure with given index
|
||||||
*/
|
*/
|
||||||
BasicInf operator[](const std::string_view& name) const;
|
BasicInf operator[](const std::string_view &name) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get map contents as vector (PartitionManager::Info type).
|
* Get map contents as vector (PartitionManager::Info type).
|
||||||
|
|||||||
@@ -136,8 +136,7 @@ basic_partition_map_builder::basic_partition_map_builder() {
|
|||||||
LOGN(MAP, ERROR) << "Cannot build map by any default search entry."
|
LOGN(MAP, ERROR) << "Cannot build map by any default search entry."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
LOGN(MAP, INFO) << "default constructor ended work."
|
LOGN(MAP, INFO) << "default constructor ended work." << std::endl;
|
||||||
<< std::endl;
|
|
||||||
_insert_logicals(_build_map("/dev/block/mapper", true));
|
_insert_logicals(_build_map("/dev/block/mapper", true));
|
||||||
_map_builded = true;
|
_map_builded = true;
|
||||||
}
|
}
|
||||||
@@ -420,7 +419,8 @@ Info basic_partition_map_builder::operator[](const int index) const {
|
|||||||
return _current_map[index];
|
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];
|
return _current_map[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -184,9 +184,7 @@ std::string basic_partition_map::find_(const std::string &name) const {
|
|||||||
|
|
||||||
size_t basic_partition_map::size() const { return _count; }
|
size_t basic_partition_map::size() const { return _count; }
|
||||||
|
|
||||||
bool basic_partition_map::empty() const {
|
bool basic_partition_map::empty() const { return _count == 0; }
|
||||||
return _count == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void basic_partition_map::clear() {
|
void basic_partition_map::clear() {
|
||||||
LOGN(MAP, INFO) << "map clean requested. Cleaning..." << std::endl;
|
LOGN(MAP, INFO) << "map clean requested. Cleaning..." << std::endl;
|
||||||
@@ -228,20 +226,16 @@ bool basic_partition_map::operator!=(const basic_partition_map &other) const {
|
|||||||
return !(*this == other);
|
return !(*this == other);
|
||||||
}
|
}
|
||||||
|
|
||||||
basic_partition_map::operator bool() const{
|
basic_partition_map::operator bool() const { return _count > 0; }
|
||||||
return _count > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool basic_partition_map::operator!() const{
|
bool basic_partition_map::operator!() const { return _count == 0; }
|
||||||
return _count == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Info basic_partition_map::operator[](const int index) const {
|
Info basic_partition_map::operator[](const int index) const {
|
||||||
if (_count == 0 || index >= _count) return {};
|
if (_count == 0 || index >= _count) return {};
|
||||||
return _data[index];
|
return _data[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicInf basic_partition_map::operator[](const std::string_view& name) const {
|
BasicInf basic_partition_map::operator[](const std::string_view &name) const {
|
||||||
if (_count == 0) return {};
|
if (_count == 0) return {};
|
||||||
|
|
||||||
if (const int i = _index_of(name); name == _data[i].name)
|
if (const int i = _index_of(name); name == _data[i].name)
|
||||||
|
|||||||
Reference in New Issue
Block a user