Repository navigation
Expand file tree
/
Copy pathinit_quit.cpp
More file actions
144 lines (112 loc) · 3.72 KB
/
Copy pathinit_quit.cpp
File metadata and controls
144 lines (112 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "bookmark_core.h"
#include "bookmark_worker.h"
#include "bookmark_list_control.h"
#include "bookmark_store.h"
using namespace glb;
namespace {
class initquit_bbookmark : public initquit {
virtual void on_init() {
std::function add_bookmark_callback([]() {
bookmark_store::set_no_refresh(false);
fb2k::inMainThread([]() {
FB2K_console_print_v("Checking startup options");
size_t cmaster = g_store.GetMasterList().size();
if (cmaster) {
for (std::list<dlg::CListControlBookmark*>::iterator it = g_guiLists.begin(); it != g_guiLists.end(); ++it) {
(*it)->ShowWindow(SW_SHOW);
(*it)->ReloadItems(bit_array_true());
(*it)->OnItemsInserted(cmaster - 1, cmaster, false);
(*it)->Invalidate(true);
}
if (g_primaryGuiList) {
g_primaryGuiList->RestoreLastFocus();
}
if (is_cfg_Play_OnInit() &&
!playback_control::get()->is_playing() &&
!playlist_manager::get()->queue_get_count()) {
bookmark_worker bmWorker;
bmWorker.restore(cmaster - 1);
if (is_cfg_Rq_OnInit()) {
bookmark_t bm = g_store.GetItem(cmaster - 1);
metadb_handle_list mhl;
metadb_handle_ptr mhp;
bool res = playback_control::get()->get_now_playing(mhp);
mhl.add_item(mhp);
ThreadUtils::cmdThread cmd;
cmd.add([mhl]() {
Sleep(atoi(cfg_rq_wait.get()) * 1000);
fb2k::inMainThread([mhl]() {
menu_helpers::name_to_guid_table menu_table;
GUID guid_fbn;
bool res = mainmenu_commands_v3::g_find_by_name("Restore last session queue", guid_fbn);
if (res) {
FB2K_console_print_v("Restoring queue on startup");
mainmenu_commands_v3::g_execute(guid_fbn);
}
}); //main thread
}); //thread pool
}
}
}
pfc::string8 msg = PFC_string_formatter() << std::to_string(cmaster).c_str() << " loaded in " << bookmark_store::get_timer().queryString();
FB2K_console_print_i("Bookmarks initialized: ", msg);
});
});
ThreadUtils::cmdThread cmd;
cmd.add([add_bookmark_callback] {
bool ordered = false;
if (GetPrimaryGuiList()) {
ordered = g_primaryGuiList->GetSortOrder();
}
bookmark_t bm_loading;
bm_loading.set_desc(kLoading);
bm_loading.set_current_date();
g_store.AddItem(bm_loading, std::function<void()>([]() {
if (GetPrimaryGuiList()) {
fb2k::inMainThread([]() {
for (std::list<dlg::CListControlBookmark*>::iterator it = g_guiLists.begin(); it != g_guiLists.end(); ++it) {
(*it)->ShowWindow(SW_SHOW);
(*it)->ReloadData();
(*it)->ReloadItems(bit_array_true());
(*it)->ShowScrollBar(SB_VERT, true);
(*it)->Invalidate(true);
}
});
}
}));
FB2K_console_print_i("Initializing bookmarks...");
bool done = g_store.Initialize(ordered, add_bookmark_callback);
});
}
virtual void on_quit() {
try {
std::unique_lock<std::mutex> ulock{ bookmark_store::get_init_lock(), std::defer_lock};
if (!ulock.try_lock()) {
bookmark_store::get_abort_callback().abort();
FB2K_console_print_e("Skipped save", "Quitting before initialization");
//
return;
//
}
ulock.unlock();
ulock.release();
if (is_cfg_Bookmarking() && cfg_autosave_on_quit.get()) {
if (g_bmAuto.checkDummy()) {
g_store.AddItem(g_bmAuto.getDummy(),
//callback
std::function<void()>([]() { g_store.Write(false); }));
}
//
return;
//
}
g_store.Write(false);
}
catch (std::system_error e) {
return;
}
}
};
// S T A T I C I N I T / Q U I T
static initquit_factory_t< initquit_bbookmark > g_bookmark_initquit;
}