summaryrefslogtreecommitdiffstats
path: root/docs/release/src/osd/winui/directories.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'docs/release/src/osd/winui/directories.cpp')
-rw-r--r--docs/release/src/osd/winui/directories.cpp206
1 files changed, 78 insertions, 128 deletions
diff --git a/docs/release/src/osd/winui/directories.cpp b/docs/release/src/osd/winui/directories.cpp
index 25928d136be..034ed91f2fa 100644
--- a/docs/release/src/osd/winui/directories.cpp
+++ b/docs/release/src/osd/winui/directories.cpp
@@ -13,15 +13,12 @@
#include <windowsx.h>
// standard C headers
-#include <sys/stat.h>
-#include <assert.h>
+#include <sys/stat.h> // S_IFDIR
#include <tchar.h>
// MAME/MAMEUI headers
-#include "winui.h"
#include "directories.h"
#include "resource.h"
-#include "strconv.h"
#include "mui_util.h"
// SHELL DIR header
@@ -92,7 +89,7 @@ static tDirInfo *g_pDirInfo;
INT_PTR CALLBACK DirectoriesDialogProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
- BOOL bReturn = FALSE;
+ BOOL bReturn = false;
switch (Msg)
{
@@ -101,7 +98,7 @@ INT_PTR CALLBACK DirectoriesDialogProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARA
case WM_COMMAND:
HANDLE_WM_COMMAND(hDlg, wParam, lParam, Directories_OnCommand);
- bReturn = TRUE;
+ bReturn = true;
break;
case WM_NOTIFY:
@@ -116,7 +113,7 @@ INT_PTR CALLBACK DirectoriesDialogProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARA
break;
default:
- bReturn = FALSE;
+ break;
}
return bReturn;
}
@@ -149,18 +146,14 @@ static void DirInfo_SetDir(tDirInfo *pInfo, int nType, int nItem, LPCTSTR pText)
t_pOldText = pInfo[nType].m_tDirectory;
if (t_pOldText)
free(t_pOldText);
- pInfo[nType].m_tDirectory = t_s;
+ pInfo[nType].m_tDirectory = t_s; // don't free t_s else directory name is corrupted
}
}
static TCHAR* DirInfo_Dir(tDirInfo *pInfo, int nType)
{
- assert(!IsMultiDir(nType));
- TCHAR* t = pInfo[nType].m_tDirectory;
// if a multipath exists in a single-path-only area then truncate it
- TCHAR* i = _tcstok(t, TEXT(";"));
- i++;
- return t;
+ return _tcstok(pInfo[nType].m_tDirectory, TEXT(";"));
}
static TCHAR* DirInfo_Path(tDirInfo *pInfo, int nType, int nItem)
@@ -170,13 +163,13 @@ static TCHAR* DirInfo_Path(tDirInfo *pInfo, int nType, int nItem)
static void DirInfo_SetModified(tDirInfo *pInfo, int nType, BOOL bModified)
{
- assert(IsMultiDir(nType));
+ //assert(IsMultiDir(nType));
pInfo[nType].m_Path->m_bModified = bModified;
}
static BOOL DirInfo_Modified(tDirInfo *pInfo, int nType)
{
- assert(IsMultiDir(nType));
+ //assert(IsMultiDir(nType));
return pInfo[nType].m_Path->m_bModified;
}
@@ -199,28 +192,25 @@ static TCHAR * FixSlash(TCHAR *s)
static void UpdateDirectoryList(HWND hDlg)
{
- bool b_res = 0;
- int i = 0;
- int nType = 0;
- LV_ITEM Item;
HWND hList = GetDlgItem(hDlg, IDC_DIR_LIST);
HWND hCombo = GetDlgItem(hDlg, IDC_DIR_COMBO);
/* Remove previous */
- b_res = ListView_DeleteAllItems(hList);
+ BOOL b_res = ListView_DeleteAllItems(hList);
/* Update list */
+ LV_ITEM Item;
memset(&Item, 0, sizeof(LV_ITEM));
Item.mask = LVIF_TEXT;
- nType = ComboBox_GetCurSel(hCombo);
+ int nType = ComboBox_GetCurSel(hCombo);
if (IsMultiDir(nType))
{
Item.pszText = (TCHAR*) TEXT(DIRLIST_NEWENTRYTEXT); // puts the < > empty entry in
(void)ListView_InsertItem(hList, &Item);
int t = DirInfo_NumDir(g_pDirInfo, nType);
// directories are inserted in reverse order
- for (i = t; 0 < i; i--)
+ for (int i = t; 0 < i; i--)
{
Item.pszText = DirInfo_Path(g_pDirInfo, nType, i-1);
(void)ListView_InsertItem(hList, &Item);
@@ -261,15 +251,14 @@ static BOOL Directories_OnInitDialog(HWND hDlg, HWND hwndFocus, LPARAM lParam)
RECT rectClient;
LVCOLUMN LVCol;
int i = 0;
- int nDirInfoCount = 0;
- LPCSTR s;
+ std::string s;
TCHAR *token;
TCHAR buf[MAX_PATH * MAX_DIRS];
TCHAR* t_s = NULL;
HRESULT res = 0;
/* count how many dirinfos there are */
- nDirInfoCount = 0;
+ int nDirInfoCount = 0;
while(g_directoryInfo[nDirInfoCount].lpName)
nDirInfoCount++;
@@ -303,14 +292,14 @@ static BOOL Directories_OnInitDialog(HWND hDlg, HWND hwndFocus, LPARAM lParam)
for (i = 0; i < nDirInfoCount; i++)
{
s = g_directoryInfo[i].pfnGetTheseDirs();
- t_s = ui_wstring_from_utf8(s);
+ t_s = ui_wstring_from_utf8(s.c_str());
if( !t_s )
- return FALSE;
+ return false;
+ /* Copy the string to our own buffer so that we can mutilate it */
+ _tcscpy(buf, t_s);
+
if (IsMultiDir(i))
{
- /* Copy the string to our own buffer so that we can mutilate it */
- _tcscpy(buf, t_s);
-
g_pDirInfo[i].m_Path = (tPath*)malloc(sizeof(tPath));
if (!g_pDirInfo[i].m_Path)
goto error;
@@ -327,35 +316,38 @@ static BOOL Directories_OnInitDialog(HWND hDlg, HWND hwndFocus, LPARAM lParam)
}
else
{
- DirInfo_SetDir(g_pDirInfo, i, -1, t_s);
+ // multi not supported so get first directory only
+ token = _tcstok(buf, TEXT(";"));
+ if (token)
+ DirInfo_SetDir(g_pDirInfo, i, -1, token);
+ else
+ DirInfo_SetDir(g_pDirInfo, i, -1, t_s);
}
free(t_s);
t_s = NULL;
}
UpdateDirectoryList(hDlg);
- return TRUE;
+ return true;
error:
if( t_s )
free(t_s);
Directories_OnDestroy(hDlg);
EndDialog(hDlg, -1);
- return FALSE;
+ return false;
}
static void Directories_OnDestroy(HWND hDlg)
{
- int nDirInfoCount = 0, i = 0;
-
if (g_pDirInfo)
{
/* count how many dirinfos there are */
- nDirInfoCount = 0;
+ int nDirInfoCount = 0;
while(g_directoryInfo[nDirInfoCount].lpName)
nDirInfoCount++;
- for (i = 0; i < nDirInfoCount; i++)
+ for (int i = 0; i < nDirInfoCount; i++)
{
if (g_pDirInfo[i].m_Path)
free(g_pDirInfo[i].m_Path);
@@ -374,24 +366,21 @@ static void Directories_OnClose(HWND hDlg)
static int RetrieveDirList(int nDir, int nFlagResult, void (*SetTheseDirs)(const char *s))
{
- int i = 0;
int nResult = 0;
- int nPaths = 0;
- TCHAR buf[MAX_PATH * MAX_DIRS];
- char* utf8_buf;
if (DirInfo_Modified(g_pDirInfo, nDir))
{
+ TCHAR buf[MAX_PATH * MAX_DIRS];
memset(buf, 0, sizeof(buf));
- nPaths = DirInfo_NumDir(g_pDirInfo, nDir);
- for (i = 0; i < nPaths; i++)
+ int nPaths = DirInfo_NumDir(g_pDirInfo, nDir);
+ for (int i = 0; i < nPaths; i++)
{
_tcscat(buf, FixSlash(DirInfo_Path(g_pDirInfo, nDir, i)));
if (i < nPaths - 1)
_tcscat(buf, TEXT(";"));
}
- utf8_buf = ui_utf8_from_wstring(buf);
+ char* utf8_buf = ui_utf8_from_wstring(buf);
SetTheseDirs(utf8_buf);
free(utf8_buf);
@@ -402,21 +391,16 @@ static int RetrieveDirList(int nDir, int nFlagResult, void (*SetTheseDirs)(const
static void Directories_OnOk(HWND hDlg)
{
- int i = 0;
int nResult = 0;
- LPTSTR s;
- char* utf8_s;
- for (i = 0; g_directoryInfo[i].lpName; i++)
+ for (int i = 0; g_directoryInfo[i].lpName; i++)
{
if (IsMultiDir(i))
- {
nResult |= RetrieveDirList(i, g_directoryInfo[i].nDirDlgFlags, g_directoryInfo[i].pfnSetTheseDirs);
- }
else
{
- s = FixSlash(DirInfo_Dir(g_pDirInfo, i));
- utf8_s = ui_utf8_from_wstring(s);
+ LPTSTR s = FixSlash(DirInfo_Dir(g_pDirInfo, i));
+ char* utf8_s = ui_utf8_from_wstring(s);
g_directoryInfo[i].pfnSetTheseDirs(utf8_s);
free(utf8_s);
}
@@ -431,34 +415,28 @@ static void Directories_OnCancel(HWND hDlg)
static void Directories_OnInsert(HWND hDlg)
{
- int nItem = 0;
- TCHAR buf[MAX_PATH];
- HWND hList = 0;
-
- hList = GetDlgItem(hDlg, IDC_DIR_LIST);
- nItem = ListView_GetNextItem(hList, -1, LVNI_SELECTED);
+ HWND hList = GetDlgItem(hDlg, IDC_DIR_LIST);
+ int nItem = ListView_GetNextItem(hList, -1, LVNI_SELECTED);
- if (BrowseForDirectory(hDlg, NULL, buf) == TRUE)
+ TCHAR buf[MAX_PATH];
+ if (BrowseForDirectory(hDlg, NULL, buf) == true)
{
- int i = 0;
- int nType = 0;
-
/* list was empty */
if (nItem == -1)
nItem = 0;
- nType = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_DIR_COMBO));
+ int nType = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_DIR_COMBO));
if (IsMultiDir(nType))
{
if (MAX_DIRS <= DirInfo_NumDir(g_pDirInfo, nType))
return;
- for (i = DirInfo_NumDir(g_pDirInfo, nType); nItem < i; i--)
+ for (int i = DirInfo_NumDir(g_pDirInfo, nType); nItem < i; i--)
_tcscpy(DirInfo_Path(g_pDirInfo, nType, i), DirInfo_Path(g_pDirInfo, nType, i - 1));
_tcscpy(DirInfo_Path(g_pDirInfo, nType, nItem), buf);
DirInfo_NumDir(g_pDirInfo, nType)++;
- DirInfo_SetModified(g_pDirInfo, nType, TRUE);
+ DirInfo_SetModified(g_pDirInfo, nType, true);
}
UpdateDirectoryList(hDlg);
@@ -469,19 +447,13 @@ static void Directories_OnInsert(HWND hDlg)
static void Directories_OnBrowse(HWND hDlg)
{
- int nType = 0;
- int nItem = 0;
- TCHAR inbuf[MAX_PATH];
- TCHAR outbuf[MAX_PATH];
- HWND hList = 0;
-
- hList = GetDlgItem(hDlg, IDC_DIR_LIST);
- nItem = ListView_GetNextItem(hList, -1, LVNI_SELECTED);
+ HWND hList = GetDlgItem(hDlg, IDC_DIR_LIST);
+ int nItem = ListView_GetNextItem(hList, -1, LVNI_SELECTED);
if (nItem == -1)
return;
- nType = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_DIR_COMBO));
+ int nType = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_DIR_COMBO));
if (IsMultiDir(nType))
{
/* Last item is placeholder for append */
@@ -492,9 +464,10 @@ static void Directories_OnBrowse(HWND hDlg)
}
}
+ TCHAR inbuf[MAX_PATH], outbuf[MAX_PATH];
ListView_GetItemText(hList, nItem, 0, inbuf, MAX_PATH);
- if (BrowseForDirectory(hDlg, inbuf, outbuf) == TRUE)
+ if (BrowseForDirectory(hDlg, inbuf, outbuf) == true)
{
nType = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_DIR_COMBO));
DirInfo_SetDir(g_pDirInfo, nType, nItem, outbuf);
@@ -504,14 +477,8 @@ static void Directories_OnBrowse(HWND hDlg)
static void Directories_OnDelete(HWND hDlg)
{
- int nType = 0;
- int nCount = 0;
- int nSelect = 0;
- int i = 0;
- int nItem = 0;
HWND hList = GetDlgItem(hDlg, IDC_DIR_LIST);
-
- nItem = ListView_GetNextItem(hList, -1, LVNI_SELECTED | LVNI_ALL);
+ int nItem = ListView_GetNextItem(hList, -1, LVNI_SELECTED | LVNI_ALL);
if (nItem == -1)
return;
@@ -520,12 +487,11 @@ static void Directories_OnDelete(HWND hDlg)
if (nItem == ListView_GetItemCount(hList) - 1)
return;
- nType = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_DIR_COMBO));
+ int nType = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_DIR_COMBO));
if (IsMultiDir(nType))
{
- for (i = nItem; i < DirInfo_NumDir(g_pDirInfo, nType) - 1; i++)
- _tcscpy(DirInfo_Path(g_pDirInfo, nType, i),
- DirInfo_Path(g_pDirInfo, nType, i + 1));
+ for (int i = nItem; i < DirInfo_NumDir(g_pDirInfo, nType) - 1; i++)
+ _tcscpy(DirInfo_Path(g_pDirInfo, nType, i), DirInfo_Path(g_pDirInfo, nType, i + 1));
_tcscpy(DirInfo_Path(g_pDirInfo, nType, DirInfo_NumDir(g_pDirInfo, nType) - 1), TEXT(""));
DirInfo_NumDir(g_pDirInfo, nType)--;
@@ -535,12 +501,12 @@ static void Directories_OnDelete(HWND hDlg)
UpdateDirectoryList(hDlg);
-
- nCount = ListView_GetItemCount(hList);
+ int nCount = ListView_GetItemCount(hList);
if (nCount <= 1)
return;
/* If the last item was removed, select the item above. */
+ int nSelect;
if (nItem == nCount - 1)
nSelect = nCount - 2;
else
@@ -551,19 +517,18 @@ static void Directories_OnDelete(HWND hDlg)
static BOOL Directories_OnBeginLabelEdit(HWND hDlg, NMHDR* pNMHDR)
{
- int nType = 0;
- BOOL bResult = FALSE;
+ BOOL bResult = false;
NMLVDISPINFO* pDispInfo = (NMLVDISPINFO*)pNMHDR;
LVITEM* pItem = &pDispInfo->item;
- nType = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_DIR_COMBO));
+ int nType = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_DIR_COMBO));
if (IsMultiDir(nType))
{
/* Last item is placeholder for append */
if (pItem->iItem == ListView_GetItemCount(GetDlgItem(hDlg, IDC_DIR_LIST)) - 1)
{
if (MAX_DIRS <= DirInfo_NumDir(g_pDirInfo, nType))
- return TRUE; /* don't edit */
+ return true; /* don't edit */
HWND hEdit = (HWND)(LRESULT)(int)SendDlgItemMessage(hDlg, IDC_DIR_LIST, LVM_GETEDITCONTROL, 0, 0);
Edit_SetText(hEdit, TEXT(""));
@@ -575,68 +540,54 @@ static BOOL Directories_OnBeginLabelEdit(HWND hDlg, NMHDR* pNMHDR)
static BOOL Directories_OnEndLabelEdit(HWND hDlg, NMHDR* pNMHDR)
{
- BOOL bResult = FALSE;
+ BOOL bResult = false;
NMLVDISPINFO* pDispInfo = (NMLVDISPINFO*)pNMHDR;
LVITEM* pItem = &pDispInfo->item;
- if (pItem->pszText != NULL)
+ if (pItem->pszText)
{
struct _stat file_stat;
/* Don't allow empty entries. */
if (!_tcscmp(pItem->pszText, TEXT("")))
- {
- return FALSE;
- }
+ return false;
/* Check validity of edited directory. */
if (_tstat(pItem->pszText, &file_stat) == 0
&& (file_stat.st_mode & S_IFDIR))
- {
- bResult = TRUE;
- }
+ bResult = true;
else
- {
- if (MessageBox(NULL, TEXT("Directory does not exist, continue anyway?"), TEXT(MAMEUINAME), MB_OKCANCEL) == IDOK)
- bResult = TRUE;
- }
+ if (MessageBox(NULL, TEXT("Directory does not exist, continue anyway?"), TEXT(MAMEUINAME), MB_OKCANCEL) == IDOK)
+ bResult = true;
}
- if (bResult == TRUE)
+ if (bResult == true)
{
- int nType = 0;
- int i = 0;
-
- nType = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_DIR_COMBO));
+ int nType = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_DIR_COMBO));
if (IsMultiDir(nType))
{
/* Last item is placeholder for append */
if (pItem->iItem == ListView_GetItemCount(GetDlgItem(hDlg, IDC_DIR_LIST)) - 1)
{
if (MAX_DIRS <= DirInfo_NumDir(g_pDirInfo, nType))
- return FALSE;
+ return false;
- for (i = DirInfo_NumDir(g_pDirInfo, nType); pItem->iItem < i; i--)
- _tcscpy(DirInfo_Path(g_pDirInfo, nType, i),
- DirInfo_Path(g_pDirInfo, nType, i - 1));
+ for (int i = DirInfo_NumDir(g_pDirInfo, nType); pItem->iItem < i; i--)
+ _tcscpy(DirInfo_Path(g_pDirInfo, nType, i), DirInfo_Path(g_pDirInfo, nType, i - 1));
_tcscpy(DirInfo_Path(g_pDirInfo, nType, pItem->iItem), pItem->pszText);
- DirInfo_SetModified(g_pDirInfo, nType, TRUE);
+ DirInfo_SetModified(g_pDirInfo, nType, true);
DirInfo_NumDir(g_pDirInfo, nType)++;
}
else
DirInfo_SetDir(g_pDirInfo, nType, pItem->iItem, pItem->pszText);
}
else
- {
DirInfo_SetDir(g_pDirInfo, nType, pItem->iItem, pItem->pszText);
- }
UpdateDirectoryList(hDlg);
- ListView_SetItemState(GetDlgItem(hDlg, IDC_DIR_LIST), pItem->iItem,
- LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
-
+ ListView_SetItemState(GetDlgItem(hDlg, IDC_DIR_LIST), pItem->iItem, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
}
return bResult;
@@ -713,7 +664,7 @@ static int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPAR
*/
if (uMsg == BFFM_INITIALIZED)
{
- if ((const char*)lpData != NULL)
+ if ((const char*)lpData)
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData);
}
@@ -722,11 +673,10 @@ static int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPAR
BOOL BrowseForDirectory(HWND hwnd, LPCTSTR pStartDir, TCHAR* pResult)
{
- BOOL bResult = FALSE;
- BROWSEINFO Info;
- LPITEMIDLIST pItemIDList = NULL;
+ BOOL bResult = false;
TCHAR buf[MAX_PATH];
+ BROWSEINFO Info;
Info.hwndOwner = hwnd;
Info.pidlRoot = NULL;
Info.pszDisplayName = buf;
@@ -735,18 +685,18 @@ BOOL BrowseForDirectory(HWND hwnd, LPCTSTR pStartDir, TCHAR* pResult)
Info.lpfn = BrowseCallbackProc;
Info.lParam = (LPARAM)pStartDir;
- pItemIDList = SHBrowseForFolder(&Info);
+ LPITEMIDLIST pItemIDList = SHBrowseForFolder(&Info);
- if (pItemIDList != NULL)
+ if (pItemIDList)
{
- if (SHGetPathFromIDList(pItemIDList, buf) == TRUE)
+ if (SHGetPathFromIDList(pItemIDList, buf) == true)
{
_sntprintf(pResult, MAX_PATH, TEXT("%s"), buf);
- bResult = TRUE;
+ bResult = true;
}
}
else
- bResult = FALSE;
+ bResult = false;
return bResult;
}