add flag_reorder

This commit is contained in:
arm64v8a
2023-07-22 16:39:43 +09:00
parent 2fc17e86e7
commit 387285e1e4
3 changed files with 54 additions and 0 deletions

View File

@@ -81,6 +81,58 @@ namespace NekoGui {
defaultGroup->name = QObject::tr("Default");
NekoGui::profileManager->AddGroup(defaultGroup);
}
//
if (dataStore->flag_reorder) {
{
// remove all (contains orphan)
for (const auto &profile: profiles) {
QFile::remove(profile.second->fn);
}
}
std::map<int, int> gidOld2New;
{
int i = 0;
int ii = 0;
QList<int> newProfilesIdOrder;
std::map<int, std::shared_ptr<ProxyEntity>> newProfiles;
for (auto gid: groupsTabOrder) {
auto group = GetGroup(gid);
gidOld2New[gid] = ii++;
for (auto const &profile: group->ProfilesWithOrder()) {
auto oldId = profile->id;
auto newId = i++;
profile->id = newId;
profile->gid = gidOld2New[gid];
profile->fn = QString("profiles/%1.json").arg(newId);
profile->Save();
newProfiles[newId] = profile;
newProfilesIdOrder << newId;
}
group->order = {};
group->Save();
}
profiles = newProfiles;
profilesIdOrder = newProfilesIdOrder;
}
{
QList<int> newGroupsIdOrder;
std::map<int, std::shared_ptr<Group>> newGroups;
for (auto oldGid: groupsTabOrder) {
auto newId = gidOld2New[oldGid];
auto group = groups[oldGid];
QFile::remove(group->fn);
group->id = newId;
group->fn = QString("groups/%1.json").arg(newId);
group->Save();
newGroups[newId] = group;
newGroupsIdOrder << newId;
}
groups = newGroups;
groupsIdOrder = newGroupsIdOrder;
groupsTabOrder = newGroupsIdOrder;
}
MessageBoxInfo(software_name, "Profiles and groups reorder complete.");
}
}
void ProfileManager::SaveManager() {

View File

@@ -88,6 +88,7 @@ namespace NekoGui {
bool flag_debug = false;
bool flag_linux_run_core_as_admin = false;
bool flag_restart_tun_on = false;
bool flag_reorder = false;
// Saved

View File

@@ -92,6 +92,7 @@ int main(int argc, char* argv[]) {
if (NekoGui::dataStore->argv.contains("-debug")) NekoGui::dataStore->flag_debug = true;
if (NekoGui::dataStore->argv.contains("-flag_linux_run_core_as_admin")) NekoGui::dataStore->flag_linux_run_core_as_admin = true;
if (NekoGui::dataStore->argv.contains("-flag_restart_tun_on")) NekoGui::dataStore->flag_restart_tun_on = true;
if (NekoGui::dataStore->argv.contains("-flag_reorder")) NekoGui::dataStore->flag_reorder = true;
#ifdef NKR_CPP_USE_APPDATA
NekoGui::dataStore->flag_use_appdata = true; // Example: Package & MacOS
#endif