Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace legacy playlist views in layout with NG playlist on upgrade #114

Merged
merged 1 commit into from
May 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions foo_ui_columns/foo_ui_columns.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@
<ClCompile Include="button_items.cpp" />
<ClCompile Include="file_info_reader.cpp" />
<ClCompile Include="legacy_config.cpp" />
<ClCompile Include="migrate.cpp" />
<ClCompile Include="ng_playlist\ng_playlist.cpp">
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\stdafx.h</PrecompiledHeaderFile>
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\stdafx.h</PrecompiledHeaderFile>
Expand Down Expand Up @@ -456,6 +457,7 @@
<ClInclude Include=".\menu_helpers.h" />
<ClInclude Include=".\mw_drop_target.h" />
<ClInclude Include="button_items.h" />
<ClInclude Include="migrate.h" />
<ClInclude Include="playlist_view_tfhooks.h" />
<ClInclude Include=".\setup_dialog.h" />
<ClInclude Include="file_info_reader.h" />
Expand Down
9 changes: 9 additions & 0 deletions foo_ui_columns/foo_ui_columns.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
<Filter Include="Panels\Playlist view">
<UniqueIdentifier>{9bc42edf-9fd0-4976-b96f-a1ac4492b347}</UniqueIdentifier>
</Filter>
<Filter Include="Migration">
<UniqueIdentifier>{f48d2be5-8e31-495d-ace6-d8afa072dfce}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ng_playlist\ng_playlist.cpp">
Expand Down Expand Up @@ -436,6 +439,9 @@
<ClCompile Include="button_items.cpp">
<Filter>Misc</Filter>
</ClCompile>
<ClCompile Include="migrate.cpp">
<Filter>Migration</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ng_playlist\ng_playlist.h">
Expand Down Expand Up @@ -623,6 +629,9 @@
<ClInclude Include="button_items.h">
<Filter>Misc</Filter>
</ClInclude>
<ClInclude Include="migrate.h">
<Filter>Migration</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include=".\buttons2.bmp">
Expand Down
3 changes: 3 additions & 0 deletions foo_ui_columns/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "notification_area.h"
#include "font_notify.h"
#include "status_bar.h"
#include "migrate.h"

rebar_window* g_rebar_window = nullptr;
layout_window g_layout_window;
Expand Down Expand Up @@ -51,6 +52,8 @@ HWND cui::MainWindow::initialise(user_interface::HookProc_t hook)
return nullptr;
}

migrate::v100::migrate();

if (main_window::config_get_is_first_run()) {
if (!cfg_layout.get_presets().get_count())
cfg_layout.reset_presets();
Expand Down
75 changes: 75 additions & 0 deletions foo_ui_columns/migrate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include "stdafx.h"
#include "layout.h"

namespace cui::migrate::v100 {

cfg_bool has_migrated_to_v100({0xba7516e5, 0xd1f1, 0x4784, {0xa6, 0x93, 0x62, 0x72, 0x37, 0xc3, 0x7e, 0x9c}}, false);

bool replace_legacy_playlist(uie::splitter_item_t* splitter_item)
{
#pragma warning(suppress : 4996)
if (splitter_item->get_panel_guid() == cui::panels::guid_playlist_view) {
splitter_item->set_panel_guid(cui::panels::guid_playlist_view_v2);
return true;
}

uie::window_ptr window;
uie::splitter_window_ptr splitter;

if (!uie::window::create_by_guid(splitter_item->get_panel_guid(), window))
return false;

if (!window->service_query_t(splitter))
return false;

auto modified = false;
stream_writer_memblock writer;
abort_callback_dummy aborter;
splitter_item->get_panel_config(&writer);
window->set_config_from_ptr(writer.m_data.get_ptr(), writer.m_data.get_size(), aborter);

const auto child_count = splitter->get_panel_count();
for (size_t i{0}; i < child_count; ++i) {
uie::splitter_item_ptr child_splitter_item;
splitter->get_panel(i, child_splitter_item);

if (replace_legacy_playlist(child_splitter_item.get_ptr())) {
splitter->replace_panel(i, child_splitter_item.get_ptr());
modified = true;
}
}

if (modified) {
writer.m_data.set_size(0);
splitter->get_config(&writer, aborter);
splitter_item->set_panel_config_from_ptr(writer.m_data.get_ptr(), writer.m_data.get_size());
}
return modified;
}

bool replace_legacy_playlist_in_all_presets()
{
auto preset_modified = false;
auto&& presets = cfg_layout.get_presets();
const auto count = presets.get_count();
for (size_t i{0}; i < count; ++i) {
uie::splitter_item_ptr splitter_item;
presets[i].get(splitter_item);
if (replace_legacy_playlist(splitter_item.get_ptr())) {
cfg_layout.set_preset(i, splitter_item.get_ptr());
preset_modified = true;
}
}
return preset_modified;
}

void migrate()
{
if (!has_migrated_to_v100) {
if (!main_window::config_get_is_first_run())
replace_legacy_playlist_in_all_presets();
has_migrated_to_v100 = true;
}
}

} // namespace cui::migrate::v100
5 changes: 5 additions & 0 deletions foo_ui_columns/migrate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

namespace cui::migrate::v100 {
void migrate();
}
1 change: 0 additions & 1 deletion foo_ui_columns/user_interface_impl.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "stdafx.h"
#include "status_pane.h"
#include "layout.h"
#include "font_notify.h"
#include "status_bar.h"
#include "notification_area.h"
Expand Down