Mercurial > foo_out_sdl
comparison foosdk/sdk/foobar2000/SDK/threaded_process.cpp @ 1:20d02a178406 default tip
*: check in everything else
yay
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 05 Jan 2026 02:15:46 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:e9bb126753e7 | 1:20d02a178406 |
|---|---|
| 1 #include "foobar2000-sdk-pch.h" | |
| 2 #include "threaded_process.h" | |
| 3 #include "advconfig.h" | |
| 4 | |
| 5 void threaded_process_status::set_progress(t_size p_state,t_size p_max) | |
| 6 { | |
| 7 set_progress( progress_min + MulDiv_Size(p_state,progress_max-progress_min,p_max) ); | |
| 8 } | |
| 9 | |
| 10 void threaded_process_status::set_progress_secondary(t_size p_state,t_size p_max) | |
| 11 { | |
| 12 set_progress_secondary( progress_min + MulDiv_Size(p_state,progress_max-progress_min,p_max) ); | |
| 13 } | |
| 14 | |
| 15 void threaded_process_status::set_progress_float(double p_state) | |
| 16 { | |
| 17 if (p_state < 0.0) set_progress(progress_min); | |
| 18 else if (p_state < 1.0) set_progress( progress_min + (t_size)(p_state * (progress_max - progress_min))); | |
| 19 else set_progress(progress_max); | |
| 20 } | |
| 21 | |
| 22 void threaded_process_status::set_progress_secondary_float(double p_state) | |
| 23 { | |
| 24 if (p_state < 0.0) set_progress_secondary(progress_min); | |
| 25 else if (p_state < 1.0) set_progress_secondary( progress_min + (t_size)(p_state * (progress_max - progress_min))); | |
| 26 else set_progress_secondary(progress_max); | |
| 27 } | |
| 28 | |
| 29 | |
| 30 bool threaded_process::g_run_modal(service_ptr_t<threaded_process_callback> p_callback,unsigned p_flags,fb2k::hwnd_t p_parent,const char * p_title,t_size p_title_len) | |
| 31 { | |
| 32 PFC_ASSERT( core_api::is_main_thread() ); | |
| 33 return threaded_process::get()->run_modal(p_callback,p_flags,p_parent,p_title,p_title_len); | |
| 34 } | |
| 35 | |
| 36 bool threaded_process::g_run_modeless(service_ptr_t<threaded_process_callback> p_callback,unsigned p_flags,fb2k::hwnd_t p_parent,const char * p_title,t_size p_title_len) | |
| 37 { | |
| 38 PFC_ASSERT( core_api::is_main_thread() ); | |
| 39 return threaded_process::get()->run_modeless(p_callback,p_flags,p_parent,p_title,p_title_len); | |
| 40 } | |
| 41 | |
| 42 bool threaded_process::g_query_preventStandby() { | |
| 43 static const GUID guid_preventStandby = { 0x7aafeffb, 0x5f11, 0x483f, { 0xac, 0x65, 0x61, 0xec, 0x9c, 0x70, 0x37, 0x4e } }; | |
| 44 advconfig_entry_checkbox::ptr obj; | |
| 45 if (advconfig_entry::g_find_t(obj, guid_preventStandby)) { | |
| 46 return obj->get_state(); | |
| 47 } else { | |
| 48 return false; | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 enum { | |
| 53 set_items_max_characters = 80 | |
| 54 }; | |
| 55 | |
| 56 void threaded_process_status::set_items(pfc::list_base_const_t<const char*> const & items) { | |
| 57 const size_t count = items.get_count(); | |
| 58 if (count == 0) return; | |
| 59 if (count == 1) { set_item_path(items[0]); } | |
| 60 pfc::string8 acc; | |
| 61 | |
| 62 filesystem::ptr fs; | |
| 63 for (size_t w = 0; w < count; ++w) { | |
| 64 pfc::string8 name = fb2k::filename_ext(items[w], fs); | |
| 65 if (w > 0 && acc.length() + name.length() > set_items_max_characters) { | |
| 66 acc << " and " << (count - w) << " more"; | |
| 67 break; | |
| 68 } | |
| 69 if (w > 0) acc << ", "; | |
| 70 acc << name; | |
| 71 } | |
| 72 | |
| 73 set_item(acc); | |
| 74 } | |
| 75 | |
| 76 void threaded_process_status::set_items(metadb_handle_list_cref items) { | |
| 77 const size_t count = items.get_count(); | |
| 78 if ( count == 0 ) return; | |
| 79 if ( count == 1 ) { set_item_path(items[0]->get_path()); } | |
| 80 pfc::string8 acc; | |
| 81 | |
| 82 filesystem::ptr fs; | |
| 83 for( size_t w = 0; w < count; ++w ) { | |
| 84 pfc::string8 name = fb2k::filename_ext(items[w]->get_path(), fs); | |
| 85 if ( w > 0 && acc.length() + name.length() > set_items_max_characters) { | |
| 86 acc << " and " << (count-w) << " more"; | |
| 87 break; | |
| 88 } | |
| 89 if (w > 0) acc << ", "; | |
| 90 acc << name; | |
| 91 } | |
| 92 | |
| 93 set_item(acc); | |
| 94 } | |
| 95 | |
| 96 | |
| 97 void threaded_process_callback_lambda::on_init(ctx_t p_ctx) { | |
| 98 if (m_on_init) m_on_init(p_ctx); | |
| 99 } | |
| 100 | |
| 101 void threaded_process_callback_lambda::run(threaded_process_status & p_status, abort_callback & p_abort) { | |
| 102 m_run(p_status, p_abort); | |
| 103 } | |
| 104 | |
| 105 void threaded_process_callback_lambda::on_done(ctx_t p_ctx, bool p_was_aborted) { | |
| 106 if (m_on_done) m_on_done(p_ctx, p_was_aborted); | |
| 107 } | |
| 108 | |
| 109 service_ptr_t<threaded_process_callback_lambda> threaded_process_callback_lambda::create() { | |
| 110 return new service_impl_t<threaded_process_callback_lambda>(); | |
| 111 } | |
| 112 | |
| 113 service_ptr_t<threaded_process_callback_lambda> threaded_process_callback_lambda::create(run_t f) { | |
| 114 auto obj = create(); | |
| 115 obj->m_run = f; | |
| 116 return obj; | |
| 117 } | |
| 118 service_ptr_t<threaded_process_callback_lambda> threaded_process_callback_lambda::create(on_init_t f1, run_t f2, on_done_t f3) { | |
| 119 auto obj = create(); | |
| 120 obj->m_on_init = f1; | |
| 121 obj->m_run = f2; | |
| 122 obj->m_on_done = f3; | |
| 123 return obj; | |
| 124 } |
