SkinInstaller: Added Advanced button

This commit is contained in:
Birunthan Mohanathas 2012-06-10 12:01:17 +03:00
parent 5e3d266c25
commit 233f5fd08c
4 changed files with 113 additions and 22 deletions

View File

@ -46,11 +46,12 @@ inline bool IsWin32Build()
CDialogInstall::CDialogInstall(HWND wnd, const WCHAR* file) : CDialog(wnd), CDialogInstall::CDialogInstall(HWND wnd, const WCHAR* file) : CDialog(wnd),
m_TabInstall(wnd), m_TabInstall(wnd),
m_InstallThread(), m_InstallThread(),
m_BackupPackage(false),
m_PackageUnzFile(), m_PackageUnzFile(),
m_PackageFileName(file), m_PackageFileName(file),
m_PackageFormat(PackageFormat::Old), m_PackageFormat(PackageFormat::Old),
m_MergeSkins(false) m_BackupSkins(true),
m_MergeSkins(false),
m_SystemFonts(false)
{ {
} }
@ -188,6 +189,47 @@ INT_PTR CDialogInstall::OnCommand(WPARAM wParam, LPARAM lParam)
{ {
switch (LOWORD(wParam)) switch (LOWORD(wParam))
{ {
case IDC_INSTALL_ADVANCED_BUTTON:
{
RECT r;
GetWindowRect((HWND)lParam, &r);
HMENU menu = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_INSTALL_MENU));
HMENU subMenu = GetSubMenu(menu, 0);
if (m_PackageSkins.empty() || m_MergeSkins)
{
EnableMenuItem(subMenu, IDM_INSTALL_BACKUPSKINS, MF_BYCOMMAND | MF_GRAYED);
}
else
{
CheckMenuItem(subMenu, IDM_INSTALL_BACKUPSKINS, (m_BackupSkins ? MF_CHECKED : MF_UNCHECKED) | MF_BYCOMMAND);
}
if (m_PackageFonts.empty())
{
EnableMenuItem(subMenu, IDM_INSTALL_SYSTEMFONTS, MF_BYCOMMAND | MF_GRAYED);
}
else
{
CheckMenuItem(subMenu, IDM_INSTALL_SYSTEMFONTS, (m_SystemFonts ? MF_CHECKED : MF_UNCHECKED) | MF_BYCOMMAND);
}
const WCHAR* formatName = m_PackageFormat == PackageFormat::New ? L"New format" : L"Old format";
ModifyMenu(subMenu, IDM_INSTALL_FORMAT, MF_STRING | MF_GRAYED | MF_BYCOMMAND, IDM_INSTALL_FORMAT, formatName);
TrackPopupMenu(
subMenu,
TPM_RIGHTBUTTON | TPM_LEFTALIGN,
r.left,
--r.bottom,
0,
m_Window,
NULL);
DestroyMenu(menu);
}
break;
case IDC_INSTALL_INSTALL_BUTTON: case IDC_INSTALL_INSTALL_BUTTON:
BeginInstall(); BeginInstall();
break; break;
@ -199,6 +241,36 @@ INT_PTR CDialogInstall::OnCommand(WPARAM wParam, LPARAM lParam)
} }
break; break;
case IDM_INSTALL_BACKUPSKINS:
m_BackupSkins = !m_BackupSkins;
break;
case IDM_INSTALL_SYSTEMFONTS:
m_SystemFonts = !m_SystemFonts;
break;
default:
return FALSE;
}
return TRUE;
}
INT_PTR CDialogInstall::OnNotify(WPARAM wParam, LPARAM lParam)
{
LPNMHDR nm = (LPNMHDR)lParam;
switch (nm->code)
{
case BCN_DROPDOWN:
{
NMHDR* hdr = &((NMBCDROPDOWN*)lParam)->hdr;
// Unpush the drop-down button part and simulate click
Button_SetDropDownState(hdr->hwndFrom, FALSE);
SendMessage(hdr->hwndFrom, BM_CLICK, 0, 0);
}
break;
default: default:
return FALSE; return FALSE;
} }
@ -280,7 +352,7 @@ bool CDialogInstall::ReadPackage()
if (footer.flags) if (footer.flags)
{ {
m_BackupPackage = footer.flags & PackageFlag::Backup; m_BackupSkins = !(footer.flags & PackageFlag::Backup);
} }
} }
} }
@ -476,6 +548,14 @@ bool CDialogInstall::ReadOptions(const WCHAR* file)
} }
Static_SetText(GetDlgItem(window, IDC_INSTALLTAB_NAME_TEXT), buffer); Static_SetText(GetDlgItem(window, IDC_INSTALLTAB_NAME_TEXT), buffer);
if (!newFormat)
{
// Determine if skins need to backed up based on name
int s;
int scanned = swscanf(buffer, L"Backup-%d.%d.%d-%d.%d.rmskin", &s, &s, &s, &s, &s);
m_BackupSkins = scanned != 5;
}
GetPrivateProfileString(section, L"Author", L"", buffer, 64, file); GetPrivateProfileString(section, L"Author", L"", buffer, 64, file);
Static_SetText(GetDlgItem(window, IDC_INSTALLTAB_AUTHOR_TEXT), buffer); Static_SetText(GetDlgItem(window, IDC_INSTALLTAB_AUTHOR_TEXT), buffer);
@ -562,15 +642,14 @@ bool CDialogInstall::InstallPackage()
return false; return false;
}; };
// Move skins into backup folder if (!m_MergeSkins && m_BackupSkins)
if (!m_MergeSkins)
{ {
// Move skins into backup folder
for (auto iter = m_PackageSkins.cbegin(); iter != m_PackageSkins.cend(); ++iter) for (auto iter = m_PackageSkins.cbegin(); iter != m_PackageSkins.cend(); ++iter)
{ {
std::wstring from = g_Data.skinsPath + *iter; std::wstring from = g_Data.skinsPath + *iter;
std::wstring to = g_Data.skinsPath + L"Backup\\"; std::wstring to = g_Data.skinsPath + L"Backup\\";
to += m_InstallTime; CreateDirectory(to.c_str(), NULL);
to += L'\\';
to += *iter; to += *iter;
CopyFiles(from, to, true); CopyFiles(from, to, true);
} }
@ -688,12 +767,6 @@ bool CDialogInstall::InstallPackage()
void CDialogInstall::BeginInstall() void CDialogInstall::BeginInstall()
{ {
WCHAR buffer[64];
SYSTEMTIME lt;
GetLocalTime(&lt);
int len = _snwprintf_s(buffer, _TRUNCATE, L"%02d.%02d.%02d %02d.%02d-%02d", lt.wYear, lt.wMonth, lt.wDay, lt.wHour, lt.wMinute, lt.wSecond);
m_InstallTime.assign(buffer, len);
HWND item = GetDlgItem(m_Window, IDC_INSTALL_ADVANCED_BUTTON); HWND item = GetDlgItem(m_Window, IDC_INSTALL_ADVANCED_BUTTON);
EnableWindow(item, FALSE); EnableWindow(item, FALSE);
@ -796,8 +869,6 @@ void CDialogInstall::KeepVariables()
for (int i = 0, isize = m_VariablesFiles.size(); i < isize; ++i) for (int i = 0, isize = m_VariablesFiles.size(); i < isize; ++i)
{ {
std::wstring fromPath = g_Data.skinsPath + L"Backup\\"; std::wstring fromPath = g_Data.skinsPath + L"Backup\\";
fromPath += m_InstallTime;
fromPath += L'\\';
fromPath += m_VariablesFiles[i]; fromPath += m_VariablesFiles[i];
std::wstring toPath = g_Data.skinsPath + m_VariablesFiles[i]; std::wstring toPath = g_Data.skinsPath + m_VariablesFiles[i];
@ -1196,7 +1267,7 @@ void CDialogInstall::CTabInstall::Initialize()
WCHAR* text = L"Add"; WCHAR* text = L"Add";
if (_waccess(itemPath.c_str(), 0) != -1) if (_waccess(itemPath.c_str(), 0) != -1)
{ {
text = (groupId == 0) ? L"Backup and replace" : L"Replace"; text = (groupId == 0 && c_Dialog->m_BackupSkins) ? L"Backup and replace" : L"Replace";
} }
ListView_SetItemText(item, lvi.iItem, 1, text); ListView_SetItemText(item, lvi.iItem, 1, text);

View File

@ -31,6 +31,7 @@ public:
static INT_PTR CALLBACK DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); static INT_PTR CALLBACK DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
INT_PTR OnInitDialog(WPARAM wParam, LPARAM lParam); INT_PTR OnInitDialog(WPARAM wParam, LPARAM lParam);
INT_PTR OnCommand(WPARAM wParam, LPARAM lParam); INT_PTR OnCommand(WPARAM wParam, LPARAM lParam);
INT_PTR OnNotify(WPARAM wParam, LPARAM lParam);
static void LoadTheme(const std::wstring& name, bool setWallpaper); static void LoadTheme(const std::wstring& name, bool setWallpaper);
@ -105,12 +106,9 @@ private:
CTabInstall m_TabInstall; CTabInstall m_TabInstall;
HANDLE m_InstallThread; HANDLE m_InstallThread;
std::wstring m_InstallTime;
std::wstring m_ErrorMessage; std::wstring m_ErrorMessage;
bool m_BackupPackage;
unzFile m_PackageUnzFile; unzFile m_PackageUnzFile;
std::wstring m_PackageFileName; std::wstring m_PackageFileName;
std::wstring m_PackageRoot; std::wstring m_PackageRoot;
@ -121,8 +119,9 @@ private:
std::set<std::wstring> m_PackageFonts; std::set<std::wstring> m_PackageFonts;
std::set<std::wstring> m_PackagePlugins; std::set<std::wstring> m_PackagePlugins;
// Package options bool m_BackupSkins;
bool m_MergeSkins; bool m_MergeSkins;
bool m_SystemFonts;
std::vector<std::wstring> m_VariablesFiles; std::vector<std::wstring> m_VariablesFiles;
std::vector<std::wstring> m_LoadSkins; std::vector<std::wstring> m_LoadSkins;
std::wstring m_LoadTheme; std::wstring m_LoadTheme;

View File

@ -45,6 +45,22 @@ VS_VERSION_INFO VERSIONINFO
} }
} }
/////////////////////////////////////////////////////////////////////////////
//
// Menu
//
IDR_INSTALL_MENU MENU
{
POPUP " "
{
MENUITEM "Backup skins", IDM_INSTALL_BACKUPSKINS
MENUITEM "Install fonts to system", IDM_INSTALL_SYSTEMFONTS, GRAYED
MENUITEM SEPARATOR
MENUITEM " ", IDM_INSTALL_FORMAT, GRAYED
}
}
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// //
// Dialog // Dialog
@ -80,7 +96,7 @@ FONT 8, "MS Shell Dlg 2"
CONTROL IDB_INSTALLHEADER, IDC_INSTALL_HEADER_BITMAP, STATIC, SS_BITMAP | WS_CHILD | WS_VISIBLE, 0, 0, 266, 37 CONTROL IDB_INSTALLHEADER, IDC_INSTALL_HEADER_BITMAP, STATIC, SS_BITMAP | WS_CHILD | WS_VISIBLE, 0, 0, 266, 37
CONTROL "", IDC_STATIC, STATIC, SS_ETCHEDHORZ | WS_CHILD | WS_VISIBLE, 0, 37, 270, 1 CONTROL "", IDC_STATIC, STATIC, SS_ETCHEDHORZ | WS_CHILD | WS_VISIBLE, 0, 37, 270, 1
CONTROL "", IDC_INSTALL_TAB, "SysTabControl32", TCS_TABS | TCS_FIXEDWIDTH, 6, 42, 254, 205 CONTROL "", IDC_INSTALL_TAB, "SysTabControl32", TCS_TABS | TCS_FIXEDWIDTH, 6, 42, 254, 205
// PUSHBUTTON "Advanced", IDC_INSTALL_ADVANCED_BUTTON, 6, 251, 70, 14 PUSHBUTTON "Advanced", IDC_INSTALL_ADVANCED_BUTTON, 6, 251, 70, 14
DEFPUSHBUTTON "Install", IDC_INSTALL_INSTALL_BUTTON, 155, 251, 50, 14 DEFPUSHBUTTON "Install", IDC_INSTALL_INSTALL_BUTTON, 155, 251, 50, 14
PUSHBUTTON "Cancel", IDCLOSE, 210, 251, 50, 14 PUSHBUTTON "Cancel", IDCLOSE, 210, 251, 50, 14
} }

View File

@ -5,6 +5,7 @@
#define IDD_INSTALL_TAB 103 #define IDD_INSTALL_TAB 103
#define IDD_BACKUP_DIALOG 104 #define IDD_BACKUP_DIALOG 104
#define IDD_BACKUP_TABDIALOG 105 #define IDD_BACKUP_TABDIALOG 105
#define IDR_INSTALL_MENU 106
#define IDC_BACKUP_TAB 1019 #define IDC_BACKUP_TAB 1019
#define IDC_BACKUP_FILE_TEXT 1020 #define IDC_BACKUP_FILE_TEXT 1020
@ -26,3 +27,7 @@
#define IDC_INSTALLTAB_THEME_CHECKBOX 1004 #define IDC_INSTALLTAB_THEME_CHECKBOX 1004
#define IDC_INSTALLTAB_INPROGRESS_TEXT 1005 #define IDC_INSTALLTAB_INPROGRESS_TEXT 1005
#define IDC_INSTALLTAB_PROGRESS 1006 #define IDC_INSTALLTAB_PROGRESS 1006
#define IDM_INSTALL_BACKUPSKINS 4200
#define IDM_INSTALL_SYSTEMFONTS 4201
#define IDM_INSTALL_FORMAT 4202