static void Directories_OnOk(HWND hDlg) { int i; int nResult = 0; int nPaths; char buf[MAX_PATH * MAX_DIRS]; /* set path options */ if (pDirInfo->m_Paths[ROM].m_bModified == TRUE) { memset(buf, 0, MAX_PATH * MAX_DIRS); nPaths = DirInfo_NumDir(pDirInfo, ROM); for (i = 0; i < nPaths; i++) { strcat(buf, FixSlash(DirInfo_Path(pDirInfo, ROM, i))); if (i < nPaths - 1) strcat(buf, ";"); } SetRomDirs(buf); nResult |= DIRDLG_ROMS; } if (pDirInfo->m_Paths[SAMPLE].m_bModified == TRUE) { memset(buf, 0, MAX_PATH * MAX_DIRS); nPaths = DirInfo_NumDir(pDirInfo, SAMPLE); for (i = 0; i < DirInfo_NumDir(pDirInfo, SAMPLE); i++) { strcat(buf, FixSlash(DirInfo_Path(pDirInfo, SAMPLE, i))); if (i < nPaths - 1) strcat(buf, ";"); } SetSampleDirs(buf); nResult |= DIRDLG_SAMPLES; } SetCfgDir(FixSlash(DirInfo_Dir(pDirInfo, CFG))); SetHiDir(FixSlash(DirInfo_Dir(pDirInfo, HI))); SetImgDir(FixSlash(DirInfo_Dir(pDirInfo, IMG))); SetInpDir(FixSlash(DirInfo_Dir(pDirInfo, INP))); SetStateDir(FixSlash(DirInfo_Dir(pDirInfo, STATE))); SetArtDir(FixSlash(DirInfo_Dir(pDirInfo, ART))); SetMemcardDir(FixSlash(DirInfo_Dir(pDirInfo, MEMCARD))); SetFlyerDir(FixSlash(DirInfo_Dir(pDirInfo, FLYER))); SetCabinetDir(FixSlash(DirInfo_Dir(pDirInfo, CABINET))); SetNvramDir(FixSlash(DirInfo_Dir(pDirInfo, NVRAM))); EndDialog(hDlg, nResult); }
static void Directories_OnDelete(HWND hDlg) { int nType; int nCount; int nSelect; int i; int nItem; HWND hList = GetDlgItem(hDlg, IDC_DIR_LIST); nItem = ListView_GetNextItem(hList, -1, LVNI_SELECTED | LVNI_ALL); if (nItem == -1) return; /* Don't delete "Append" placeholder. */ if (nItem == ListView_GetItemCount(hList) - 1) return; nType = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_DIR_COMBO)); switch (nType) { case ROM: case SAMPLE: for (i = nItem; i < DirInfo_NumDir(pDirInfo, nType) - 1; i++) strcpy(DirInfo_Path(pDirInfo, nType, i), DirInfo_Path(pDirInfo, nType, i + 1)); strcpy(DirInfo_Path(pDirInfo, nType, DirInfo_NumDir(pDirInfo, nType) - 1), ""); DirInfo_NumDir(pDirInfo, nType)--; pDirInfo->m_Paths[nType].m_bModified = TRUE; break; } UpdateDirectoryList(hDlg); nCount = ListView_GetItemCount(hList); if (nCount <= 1) return; /* If the last item was removed, select the item above. */ if (nItem == nCount - 1) nSelect = nCount - 2; else nSelect = nItem; ListView_SetItemState(hList, nSelect, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); }
static int RetrieveDirList(int nDir, int nFlagResult, void (*SetTheseDirs)(const char *s)) { int i; int nResult = 0; int nPaths; TCHAR buf[MAX_PATH * MAX_DIRS]; char* utf8_buf; if (DirInfo_Modified(g_pDirInfo, nDir)) { memset(buf, 0, sizeof(buf)); nPaths = DirInfo_NumDir(g_pDirInfo, nDir); for (i = 0; i < nPaths; i++) { _tcscat(buf, FixSlash(DirInfo_Path(g_pDirInfo, nDir, i))); if (i < nPaths - 1) _tcscat(buf, TEXT(";")); } utf8_buf = utf8_from_tstring(buf); SetTheseDirs(utf8_buf); osd_free(utf8_buf); nResult |= nFlagResult; } return nResult; }
static void Directories_OnDelete(HWND hDlg) { int nType; int nCount; int nSelect; int i; int nItem; HWND hList = GetDlgItem(hDlg, IDC_DIR_LIST); nItem = ListView_GetNextItem(hList, -1, LVNI_SELECTED | LVNI_ALL); if (nItem == -1) return; /* Don't delete "Append" placeholder. */ if (nItem == ListView_GetItemCount(hList) - 1) return; 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)); _tcscpy(DirInfo_Path(g_pDirInfo, nType, DirInfo_NumDir(g_pDirInfo, nType) - 1), TEXT("")); DirInfo_NumDir(g_pDirInfo, nType)--; DirInfo_SetModified(g_pDirInfo, nType, TRUE); } UpdateDirectoryList(hDlg); nCount = ListView_GetItemCount(hList); if (nCount <= 1) return; /* If the last item was removed, select the item above. */ if (nItem == nCount - 1) nSelect = nCount - 2; else nSelect = nItem; ListView_SetItemState(hList, nSelect, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); }
static void Directories_OnInsert(HWND hDlg) { int nItem; char buf[MAX_PATH]; HWND hList; hList = GetDlgItem(hDlg, IDC_DIR_LIST); nItem = ListView_GetNextItem(hList, -1, LVNI_SELECTED); if (BrowseForDirectory(hDlg, NULL, buf) == TRUE) { int i; int nType; /* list was empty */ if (nItem == -1) nItem = 0; nType = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_DIR_COMBO)); switch (nType) { case ROM: case SAMPLE: if (MAX_DIRS <= DirInfo_NumDir(pDirInfo, nType)) return; for (i = DirInfo_NumDir(pDirInfo, nType); nItem < i; i--) strcpy(DirInfo_Path(pDirInfo, nType, i), DirInfo_Path(pDirInfo, nType, i - 1)); strcpy(DirInfo_Path(pDirInfo, nType, nItem), buf); DirInfo_NumDir(pDirInfo, nType)++; pDirInfo->m_Paths[nType].m_bModified = TRUE; break; } UpdateDirectoryList(hDlg); ListView_SetItemState(hList, nItem, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); } }
static void Directories_OnInsert(HWND hDlg) { int nItem; TCHAR buf[MAX_PATH]; HWND hList; hList = GetDlgItem(hDlg, IDC_DIR_LIST); nItem = ListView_GetNextItem(hList, -1, LVNI_SELECTED); if (BrowseForDirectory(hDlg, NULL, buf) == TRUE) { int i; int nType; /* list was empty */ if (nItem == -1) nItem = 0; 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--) _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); } UpdateDirectoryList(hDlg); ListView_SetItemState(hList, nItem, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); } }
static void DirInfo_SetDir(struct tDirInfo* pInfo, int nType, int nItem, const char* pText) { switch (nType) { case ROM: case SAMPLE: strcpy(DirInfo_Path(pInfo, nType, nItem), pText); pInfo->m_Paths[nType].m_bModified = TRUE; break; default: if (nType < LASTDIR) strcpy(DirInfo_Dir(pInfo, nType), pText); break; } }
static void UpdateDirectoryList(HWND hDlg) { int i; int nType; LV_ITEM Item; HWND hList = GetDlgItem(hDlg, IDC_DIR_LIST); HWND hCombo = GetDlgItem(hDlg, IDC_DIR_COMBO); /* Remove previous */ ListView_DeleteAllItems(hList); /* Update list */ memset(&Item, 0, sizeof(LV_ITEM)); Item.mask = LVIF_TEXT; nType = ComboBox_GetCurSel(hCombo); switch (nType) { case ROM: case SAMPLE: Item.pszText = "< >"; ListView_InsertItem(hList, &Item); for (i = DirInfo_NumDir(pDirInfo, nType) - 1; 0 <= i; i--) { Item.pszText = DirInfo_Path(pDirInfo, nType, i); ListView_InsertItem(hList, &Item); } break; default: if (nType < LASTDIR) { Item.pszText = DirInfo_Dir(pDirInfo, nType); ListView_InsertItem(hList, &Item); } break; } /* select first one */ ListView_SetItemState(hList, 0, LVIS_SELECTED, LVIS_SELECTED); }
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); /* Update list */ memset(&Item, 0, sizeof(LV_ITEM)); Item.mask = LVIF_TEXT; 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--) { Item.pszText = DirInfo_Path(g_pDirInfo, nType, i-1); (void)ListView_InsertItem(hList, &Item); } } else { Item.pszText = DirInfo_Dir(g_pDirInfo, nType); (void)ListView_InsertItem(hList, &Item); } /* select first one */ ListView_SetItemState(hList, 0, LVIS_SELECTED, LVIS_SELECTED); b_res++; }
static void UpdateDirectoryList(HWND hDlg) { int i; int nType; LV_ITEM Item; HWND hList = GetDlgItem(hDlg, IDC_DIR_LIST); HWND hCombo = GetDlgItem(hDlg, IDC_DIR_COMBO); BOOL b_res; /* Remove previous */ b_res = ListView_DeleteAllItems(hList); /* Update list */ memset(&Item, 0, sizeof(LV_ITEM)); Item.mask = LVIF_TEXT; nType = ComboBox_GetCurSel(hCombo); if (IsMultiDir(nType)) { Item.pszText = (TCHAR*) TEXT(DIRLIST_NEWENTRYTEXT); (void)ListView_InsertItem(hList, &Item); for (i = DirInfo_NumDir(g_pDirInfo, nType) - 1; 0 <= i; i--) { Item.pszText = DirInfo_Path(g_pDirInfo, nType, i); (void)ListView_InsertItem(hList, &Item); } } else { Item.pszText = DirInfo_Dir(g_pDirInfo, nType); (void)ListView_InsertItem(hList, &Item); } /* select first one */ ListView_SetItemState(hList, 0, LVIS_SELECTED, LVIS_SELECTED); }
static void DirInfo_SetDir(tDirInfo *pInfo, int nType, int nItem, LPCTSTR pText) { TCHAR *t_s; TCHAR *t_pOldText; if (IsMultiDir(nType)) { assert(nItem >= 0); _tcscpy(DirInfo_Path(pInfo, nType, nItem), pText); DirInfo_SetModified(pInfo, nType, TRUE); } else { t_s = win_tstring_strdup(pText); if (!t_s) return; t_pOldText = pInfo[nType].m_tDirectory; if (t_pOldText) osd_free(t_pOldText); pInfo[nType].m_tDirectory = t_s; } }
static BOOL Directories_OnEndLabelEdit(HWND hDlg, NMHDR* pNMHDR) { BOOL bResult = FALSE; NMLVDISPINFO* pDispInfo = (NMLVDISPINFO*)pNMHDR; LVITEM* pItem = &pDispInfo->item; if (pItem->pszText != NULL) { struct _stat file_stat; /* Don't allow empty entries. */ if (!_tcscmp(pItem->pszText, TEXT(""))) { return FALSE; } /* Check validity of edited directory. */ if (_tstat(pItem->pszText, &file_stat) == 0 && (file_stat.st_mode & S_IFDIR)) { bResult = TRUE; } else { if (MessageBox(NULL, TEXT("Directory does not exist, continue anyway?"), TEXT(MAMEUINAME), MB_OKCANCEL) == IDOK) bResult = TRUE; } } if (bResult == TRUE) { int nType; int i; 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; 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)); _tcscpy(DirInfo_Path(g_pDirInfo, nType, pItem->iItem), pItem->pszText); 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); } return bResult; }
static BOOL Directories_OnInitDialog(HWND hDlg, HWND hwndFocus, LPARAM lParam) { RECT rectClient; LVCOLUMN LVCol; int i; int nDirInfoCount; LPCSTR s; TCHAR *token; TCHAR buf[MAX_PATH * MAX_DIRS]; TCHAR* t_s = NULL; HRESULT res; /* count how many dirinfos there are */ nDirInfoCount = 0; while(g_directoryInfo[nDirInfoCount].lpName) nDirInfoCount++; g_pDirInfo = (tDirInfo *) malloc(sizeof(tDirInfo) * nDirInfoCount); if (!g_pDirInfo) /* bummer */ goto error; memset(g_pDirInfo, 0, sizeof(tDirInfo) * nDirInfoCount); for (i = nDirInfoCount - 1; i >= 0; i--) { t_s = tstring_from_utf8(g_directoryInfo[i].lpName); if( !t_s ) return FALSE; (void)ComboBox_InsertString(GetDlgItem(hDlg, IDC_DIR_COMBO), 0, win_tstring_strdup(t_s)); osd_free(t_s); t_s = NULL; } (void)ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_DIR_COMBO), 0); GetClientRect(GetDlgItem(hDlg, IDC_DIR_LIST), &rectClient); memset(&LVCol, 0, sizeof(LVCOLUMN)); LVCol.mask = LVCF_WIDTH; LVCol.cx = rectClient.right - rectClient.left - GetSystemMetrics(SM_CXHSCROLL); res = ListView_InsertColumn(GetDlgItem(hDlg, IDC_DIR_LIST), 0, &LVCol); /* Keep a temporary copy of the directory strings in g_pDirInfo. */ for (i = 0; i < nDirInfoCount; i++) { s = g_directoryInfo[i].pfnGetTheseDirs(); t_s = tstring_from_utf8(s); if( !t_s ) return FALSE; if (g_directoryInfo[i].bMulti) { /* 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; g_pDirInfo[i].m_Path->m_NumDirectories = 0; token = _tcstok(buf, TEXT(";")); while ((DirInfo_NumDir(g_pDirInfo, i) < MAX_DIRS) && token) { _tcscpy(DirInfo_Path(g_pDirInfo, i, DirInfo_NumDir(g_pDirInfo, i)), token); DirInfo_NumDir(g_pDirInfo, i)++; token = _tcstok(NULL, TEXT(";")); } DirInfo_SetModified(g_pDirInfo, i, FALSE); } else { DirInfo_SetDir(g_pDirInfo, i, -1, t_s); } osd_free(t_s); t_s = NULL; } UpdateDirectoryList(hDlg); return TRUE; error: if( t_s ) osd_free(t_s); Directories_OnDestroy(hDlg); EndDialog(hDlg, -1); return FALSE; }
static BOOL Directories_OnEndLabelEdit(HWND hDlg, NMHDR* pNMHDR) { BOOL bResult = FALSE; NMLVDISPINFO* pDispInfo = (NMLVDISPINFO*)pNMHDR; LVITEM* pItem = &pDispInfo->item; if (pItem->pszText != NULL) { struct stat file_stat; /* Don't allow empty entries. */ if (!strcmp(pItem->pszText, "")) { return FALSE; } /* Check validity of edited directory. */ if (stat(pItem->pszText, &file_stat) == 0 && (file_stat.st_mode & S_IFDIR)) { bResult = TRUE; } else { if (MessageBox(NULL, "Directory does not exist, continue anyway?", "MAME32", MB_OKCANCEL) == IDOK) bResult = TRUE; } } if (bResult == TRUE) { int nType; int i; nType = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_DIR_COMBO)); switch (nType) { case ROM: case SAMPLE: /* Last item is placeholder for append */ if (pItem->iItem == ListView_GetItemCount(GetDlgItem(hDlg, IDC_DIR_LIST)) - 1) { if (MAX_DIRS <= DirInfo_NumDir(pDirInfo, nType)) return FALSE; for (i = DirInfo_NumDir(pDirInfo, nType); pItem->iItem < i; i--) strcpy(DirInfo_Path(pDirInfo, nType, i), DirInfo_Path(pDirInfo, nType, i - 1)); strcpy(DirInfo_Path(pDirInfo, nType, pItem->iItem), pItem->pszText); pDirInfo->m_Paths[nType].m_bModified = TRUE; DirInfo_NumDir(pDirInfo, nType)++; } else DirInfo_SetDir(pDirInfo, nType, pItem->iItem, pItem->pszText); break; case CFG: case HI: case IMG: case INP: case STATE: case ART: case MEMCARD: case FLYER: case CABINET: case NVRAM: DirInfo_SetDir(pDirInfo, nType, pItem->iItem, pItem->pszText); break; } UpdateDirectoryList(hDlg); ListView_SetItemState(GetDlgItem(hDlg, IDC_DIR_LIST), pItem->iItem, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); } return bResult; }
static BOOL Directories_OnInitDialog(HWND hDlg, HWND hwndFocus, LPARAM lParam) { RECT rectClient; LVCOLUMN LVCol; char* token; char buf[MAX_PATH * MAX_DIRS]; int i; pDirInfo = (struct tDirInfo*) malloc(sizeof(struct tDirInfo)); if (pDirInfo == NULL) /* bummer */ { EndDialog(hDlg, -1); return FALSE; } for (i = LASTDIR - 1; i >= 0; i--) { ComboBox_InsertString(GetDlgItem(hDlg, IDC_DIR_COMBO), 0, dir_names[i]); } ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_DIR_COMBO), 0); GetClientRect(GetDlgItem(hDlg, IDC_DIR_LIST), &rectClient); memset(&LVCol, 0, sizeof(LVCOLUMN)); LVCol.mask = LVCF_WIDTH; LVCol.cx = rectClient.right - rectClient.left - GetSystemMetrics(SM_CXHSCROLL); ListView_InsertColumn(GetDlgItem(hDlg, IDC_DIR_LIST), 0, &LVCol); /* Keep a temporary copy of the directory strings in pDirInfo. */ memset(pDirInfo, 0, sizeof(struct tDirInfo)); strcpy(buf, GetRomDirs()); pDirInfo->m_Paths[ROM].m_NumDirectories = 0; token = strtok(buf, ";"); while ((DirInfo_NumDir(pDirInfo, ROM) < MAX_DIRS) && token) { strcpy(DirInfo_Path(pDirInfo, ROM, DirInfo_NumDir(pDirInfo, ROM)), token); DirInfo_NumDir(pDirInfo, ROM)++; token = strtok(NULL, ";"); } pDirInfo->m_Paths[ROM].m_bModified = FALSE; strcpy(buf, GetSampleDirs()); pDirInfo->m_Paths[SAMPLE].m_NumDirectories = 0; token = strtok(buf, ";"); while ((DirInfo_NumDir(pDirInfo, SAMPLE) < MAX_DIRS) && token) { strcpy(DirInfo_Path(pDirInfo, SAMPLE, DirInfo_NumDir(pDirInfo, SAMPLE)), token); DirInfo_NumDir(pDirInfo, SAMPLE)++; token = strtok(NULL, ";"); } pDirInfo->m_Paths[SAMPLE].m_bModified = FALSE; strcpy(DirInfo_Dir(pDirInfo, CFG), GetCfgDir()); strcpy(DirInfo_Dir(pDirInfo, HI), GetHiDir()); strcpy(DirInfo_Dir(pDirInfo, IMG), GetImgDir()); strcpy(DirInfo_Dir(pDirInfo, INP), GetInpDir()); strcpy(DirInfo_Dir(pDirInfo, STATE), GetStateDir()); strcpy(DirInfo_Dir(pDirInfo, ART), GetArtDir()); strcpy(DirInfo_Dir(pDirInfo, MEMCARD), GetMemcardDir()); strcpy(DirInfo_Dir(pDirInfo, FLYER), GetFlyerDir()); strcpy(DirInfo_Dir(pDirInfo, CABINET), GetCabinetDir()); strcpy(DirInfo_Dir(pDirInfo, NVRAM), GetNvramDir()); UpdateDirectoryList(hDlg); return TRUE; }