Skip to content

Commit

Permalink
add flag_reorder
Browse files Browse the repository at this point in the history
  • Loading branch information
arm64v8a committed Jul 22, 2023
1 parent 2fc17e8 commit 387285e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
52 changes: 52 additions & 0 deletions db/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions main/NekoGui_DataStore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 387285e

Please sign in to comment.