--- np2/win9xc/dialog/dialogs.cpp 2003/11/21 06:51:15 1.2 +++ np2/win9xc/dialog/dialogs.cpp 2004/02/13 20:31:55 1.3 @@ -9,9 +9,6 @@ static const char str_nc[] = "N/C"; -static char pathname[MAX_PATH]; -static char filename[MAX_PATH]; - const char str_int0[] = "INT0"; const char str_int1[] = "INT1"; const char str_int2[] = "INT2"; @@ -22,103 +19,90 @@ const char str_int6[] = "INT6"; // ---- file select -const char *dlgs_selectfile(HWND hWnd, const FILESEL *item, - const char *defname, char *folder, UINT size, int *ro) { +BOOL dlgs_selectfile(HWND hWnd, const FILESEL *item, + char *path, UINT size, int *ro) { OPENFILENAME ofn; - if ((defname) && (defname[0])) { - milstr_ncpy(pathname, defname, sizeof(pathname)); - } - else if (folder) { - milstr_ncpy(pathname, folder, sizeof(pathname)); - } - else { - pathname[0] = '\0'; + if ((item == NULL) || (path == NULL) || (size == 0)) { + return(FALSE); } - filename[0] = '\0'; - ZeroMemory(&ofn, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hWnd; ofn.lpstrFilter = item->filter; ofn.nFilterIndex = item->defindex; - ofn.lpstrFile = pathname; - ofn.lpstrFileTitle = filename; - ofn.nMaxFile = MAX_PATH; + ofn.lpstrFile = path; + ofn.nMaxFile = size; ofn.Flags = OFN_FILEMUSTEXIST; ofn.lpstrDefExt = item->ext; ofn.lpstrTitle = item->title; if (!GetOpenFileName(&ofn)) { - return(NULL); - } - if (folder) { - milstr_ncpy(folder, pathname, size); - sysmng_update(SYS_UPDATEOSCFG); + return(FALSE); } if (ro) { *ro = ofn.Flags & OFN_READONLY; } - return(pathname); + return(TRUE); } -const char *dlgs_selectwritefile(HWND hWnd, const FILESEL *item, - const char *defname, char *folder, UINT size) { +BOOL dlgs_selectwritefile(HWND hWnd, const FILESEL *item, + char *path, UINT size) { OPENFILENAME ofn; - if (defname) { - milstr_ncpy(pathname, defname, sizeof(pathname)); - } - else { - pathname[0] = '\0'; + if ((item == NULL) || (path == NULL) || (size == 0)) { + return(FALSE); } - filename[0] = '\0'; - ZeroMemory(&ofn, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hWnd; ofn.lpstrFilter = item->filter; - ofn.lpstrFile = pathname; - ofn.lpstrFileTitle = filename; ofn.nFilterIndex = item->defindex; - ofn.nMaxFile = MAX_PATH; - ofn.nMaxFileTitle = sizeof(filename); + ofn.lpstrFile = path; + ofn.nMaxFile = size; ofn.Flags = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY; ofn.lpstrDefExt = item->ext; ofn.lpstrTitle = item->title; if (!GetSaveFileName(&ofn)) { - return(NULL); - } - if (folder) { - milstr_ncpy(folder, pathname, size); - sysmng_update(SYS_UPDATEOSCFG); + return(FALSE); } - return(pathname); + return(TRUE); } -const char *dlgs_selectwritenum(HWND hWnd, const FILESEL *item, - const char *defname, char *folder, UINT size) { +BOOL dlgs_selectwritenum(HWND hWnd, const FILESEL *item, + char *path, UINT size) { - char numfile[MAX_PATH]; + char *file; char *p; - int i; + char *q; + UINT i; + BOOL r; - if (folder) { - milstr_ncpy(numfile, folder, sizeof(numfile)); + if ((item == NULL) || (path == NULL) || (size == 0)) { + return(FALSE); } - else { - numfile[0] = '\0'; - } - file_cutname(numfile); - p = numfile + strlen(numfile); + file = (char *)_MALLOC(size + 16, path); + if (file == NULL) { + return(FALSE); + } + p = file_getname(path); + milstr_ncpy(file, path, size); + file_cutname(file); + q = file + strlen(file); + for (i=0; i<10000; i++) { - wsprintf(p, defname, i); - if (file_attr(numfile) == -1) { + SPRINTF(q, p, i); + if (file_attr(file) == (short)-1) { break; } } - return(dlgs_selectwritefile(hWnd, item, numfile, folder, size)); + r = dlgs_selectwritefile(hWnd, item, file, size); + if (r) { + milstr_ncpy(path, file, size); + } + _MFREE(file); + return(r); }