int PosixFilesystem::rename (RFs& aFs, const wchar_t* oldname, const wchar_t* newname, int& anErrno) { TFileName oldFullName; TInt err = GetFullFile(oldFullName,(const TText16 *)oldname,aFs); if (!err) { TFileName newFullName; err = GetFullFile(newFullName,(const TText16 *)newname,aFs); if (!err) { // ANSI doesn't require specific handling when newname exists, // so we can just use the EPOC32 semantics and insist that // newname doesn't currently exist. err=aFs.Rename(oldFullName,newFullName); } } return MapError(err, anErrno); }
int PosixFilesystem::chmod (RFs& aFs, const wchar_t* name, int perms, int& anErrno) { TFullName fullName; TInt err=GetFullFile(fullName,(const TText16*)name,aFs); if (!err) { if ((perms&S_IWUSR)==0) err=aFs.SetAtt(fullName,KEntryAttReadOnly,0); else err=aFs.SetAtt(fullName,0,KEntryAttReadOnly); } return MapError(err, anErrno); }
int PosixFilesystem::unlink (RFs& aFs, const wchar_t* name, int& anErrno) { TFullName fullName; TInt err=GetFullFile(fullName, (TText16*)name, aFs); if (!err) { TUint att=0; err=aFs.Att(fullName, att); if (!err) if (att&KEntryAttDir) err=EPERM; else err=aFs.Delete(fullName); } return MapError(err, anErrno); }
int PosixFilesystem::stat (RFs& aFs, const wchar_t* name, struct stat *st, int& anErrno) { TFullName fullName; TInt err=GetFullFile(fullName,(const TText16*)name,aFs); if (!err) { TEntry entry; if (fullName.Length()==3) { entry.iAtt=KEntryAttDir; entry.iModified==TTime(0); } else err=aFs.Entry(fullName,entry); if (!err) { st->st_size = entry.iSize; st->st_dev = st->st_rdev = (dev_t)TDriveUnit(fullName); CFileDesc::MapStat(*st, entry.iModified, entry.iAtt); return 0; } } return MapError(err, anErrno); }
MRESULT EXPENTRY ViceFileDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) { switch (msg) { case WM_INITDLG: { FILEDLG *fdlg = (FILEDLG*)WinQueryWindowPtr(hwnd, QWL_USER); int i; char *szpath; const int action = fdlg->ulUser; const int nact = (action >> 8) & 0xff; const int nsact = (action) & 0xff; FillABox(hwnd, action ? nact - 1 : 0); FillSBox(hwnd, action ? nsact - 1 : 0); FillFBox(hwnd); NewFilter(hwnd); for (i = 0; i < numfonts; i++) { WinDlgLboxInsertItem(hwnd, DID_FONTNAME_LB, fnames[i]); } WinDlgLboxSelectItem(hwnd, DID_FONTNAME_LB, 0); if (action) { WinEnableControl(hwnd, DID_ACTION_CB, FALSE); WinEnableControl(hwnd, DID_SUBACTION_CB, FALSE); } if (action || fdlg->fl & FDS_SAVEAS_DIALOG) { WinEnableControl(hwnd, DID_AUTOSTART_PB, FALSE); } szpath = util_concat(fdlg->pszIDrive, fdlg->szFullFile, NULL); *(strrchr(szpath, '\\') + 1) = '\0'; WinSetDlgItemText(hwnd, DID_DIR_SELECTED, szpath); lib_free(szpath); szpath = util_concat(archdep_boot_path(), "\\vice2.dll", NULL); if (!GpiLoadFonts(WinQueryAnchorBlock(hwnd), szpath)) { log_debug("dlg-fileio.c: GpiLoadFonts('%s') failed.", szpath); WinEnableControl(hwnd, DID_FONTNAME_LB, FALSE); } lib_free(szpath); } return FALSE; case WM_DESTROY: { char *szpath = util_concat(archdep_boot_path(), "\\vice2.dll", NULL); LboxFreeContents(WinWindowFromID(hwnd, DID_CONTENTS_LB)); if (!GpiUnloadFonts(WinQueryAnchorBlock(hwnd), szpath)) { log_debug("dlg-fileio.c: GpiUnloadFonts('%s') failed.", szpath); } lib_free (szpath); } break; case WM_CONTROL: switch (SHORT1FROMMP(mp1)) { case DID_ACTION_CB: if (SHORT2FROMMP(mp1) == CBN_ENTER) { FillSBox(hwnd, 0); } case DID_SUBACTION_CB: if (SHORT2FROMMP(mp1) == CBN_ENTER) { FillFBox(hwnd); } case DID_FFILTER_CB: if (SHORT2FROMMP(mp1) == CBN_ENTER) { NewFilter(hwnd); } return FALSE; case DID_DIRECTORY_LB: WinDefFileDlgProc(hwnd, msg, mp1, mp2); if (SHORT2FROMMP(mp1) == LN_SELECT || SHORT2FROMMP(mp1) == LN_ENTER) { char szpath[CCHMAXPATH]; const int nr = WinQueryLboxSelectedItem((HWND)mp2); if (nr < 0) { return FALSE; } if (SHORT2FROMMP(mp1) == LN_SELECT && WinQueryFocus(HWND_DESKTOP) == (HWND)mp2) { return FALSE; } if (!GetLboxPath((HWND)mp2, nr, szpath)) { return FALSE; } WinSetDlgItemText(hwnd, DID_DIR_SELECTED, szpath); } return FALSE; case DID_FILENAME_ED: if (WinQueryButtonCheckstate(hwnd, DID_CONTENTS_CB) && SHORT2FROMMP(mp1) == EN_CHANGE) { char szpath[CCHMAXPATH]; if (GetFullFile(hwnd, szpath)) { ShowContents(hwnd, szpath); } } break; case DID_CONTENTS_CB: { const int state = WinQueryButtonCheckstate(hwnd, DID_CONTENTS_CB); WinEnableControl(hwnd, DID_CONTENTS_LB, state); WinEnableControl(hwnd, DID_FONTNAME_LB, state); if (state) { ContentsUpdate(hwnd); } else { LboxFreeContents(WinWindowFromID(hwnd, DID_CONTENTS_LB)); } } return FALSE; case DID_FONTNAME_LB: if (SHORT2FROMMP(mp1) != CBN_ENTER) { break; } ContentsUpdate(hwnd); return FALSE; } break; case WM_COMMAND: switch (SHORT1FROMMP(mp1)) { case DID_DIRUP: { const HWND name = WinWindowFromID(hwnd, DID_FILENAME_ED); const int pos = WinDlgLboxSelectedItem(hwnd, DID_DIRECTORY_LB); char szpath[CCHMAXPATH]; char *cpos; int len; if (!pos) { return FALSE; } WinQueryDlgItemText(hwnd, DID_DIR_SELECTED, CCHMAXPATH - 1, szpath); if (strlen(szpath) < 4) { return FALSE; } *strrchr(szpath, '\\') = '\0'; cpos = strrchr(szpath,'\\') + 1; len = cpos - szpath + 2; if (len == CCHMAXPATH - 1) { return FALSE; } WinQueryDlgItemText(hwnd, DID_FILENAME_ED, CCHMAXPATH - len - 1, cpos); WinSetWindowText(name, szpath); *cpos = '\0'; WinSetDlgItemText(hwnd, DID_DIR_SELECTED, szpath); // // set focus to entry field and simulate an Apply // WinSetFocus(HWND_DESKTOP, name); WinDefFileDlgProc(hwnd, WM_COMMAND, (MPARAM)DID_OK, MPFROM2SHORT(CMDSRC_PUSHBUTTON, TRUE)); } return FALSE; case DID_AUTOSTART_PB: { const int pos = WinDlgLboxSelectedItem(hwnd, DID_CONTENTS_LB); FILEDLG *fdlg = (FILEDLG*)WinQueryWindowPtr(hwnd, QWL_USER); size_t length; char szpath[CCHMAXPATH]; if (!GetFullFile(hwnd, szpath)) { return FALSE; } if (autostart_autodetect(szpath, NULL, pos < 0 ? 0 : pos, AUTOSTART_MODE_RUN)) { return FALSE; } length = strrchr(szpath, '\\') - szpath; fdlg->lReturn = DID_OK; if (length > 0) { fdlg->szFullFile[length] = 0; } } break; } break; case WM_MEASUREITEM: if (SHORT1FROMMP(mp1) == DID_CONTENTS_LB) { return MRFROM2SHORT(9, 9); } break; case WM_DRAWITEM: if (SHORT1FROMMP(mp1) == DID_CONTENTS_LB) { OWNERITEM *item = (OWNERITEM*)mp2; RECTL *rcl = &(item->rclItem); if (rcl->yTop-rcl->yBottom == 9) { image_contents_screencode_t *line = (image_contents_screencode_t *)WinLboxItemHandle(item->hwnd, item->idItem); if (line) { LboxDrawLine(hwnd, item, rcl, line); } item->fsState = item->fsStateOld = 0; } return (MRESULT)TRUE; } break; case FDM_VALIDATE: // mp1 = PSZ pszPathName // mp2 = USHORT Field name id // mr = TRUE -> Valid name { const int sact = WinDlgLboxSelectedItem(hwnd, DID_SUBACTION_CB); const int act = WinDlgLboxSelectedItem(hwnd, DID_ACTION_CB); const FILEDLG *fdlg = (FILEDLG*)WinQueryWindowPtr(hwnd, QWL_USER); char *szpath = (char*)mp1; int rc; char *slash; if (fdlg->fl & FDS_OPEN_DIALOG) { rc = FdmDoLoadAction(hwnd, szpath, act, sact); } else { rc = FdmDoSaveAction(hwnd, szpath, act, sact); } if (rc < 0) { const action_t *action = fdlg->fl & FDS_OPEN_DIALOG ? LoadAction : SaveAction; char *txt = util_concat("The following action couldn't be performed:\n", action[act].type, " ", action[act].subact[sact].action, NULL); HPOINTER hpt = WinLoadPointer(HWND_DESKTOP, NULLHANDLE, 0x101); #ifdef WATCOM_COMPILE struct _MB2D mbtemp; struct _MB2INFO mb; mb.cb = sizeof(MB2INFO); mb.hIcon = hpt; mb.cButtons = 1; mb.flStyle = MB_CUSTOMICON|WS_VISIBLE; mb.hwndNotify = NULLHANDLE; sprintf(mbtemp.achText," OK "); mbtemp.idButton = 0; mbtemp.flStyle = BS_DEFAULT; mb.mb2d[0] = mbtemp; #else MB2INFO mb = { sizeof(MB2INFO), hpt, 1, MB_CUSTOMICON | WS_VISIBLE, NULLHANDLE, " OK ", 0, BS_DEFAULT}; #endif WinMessageBox2(HWND_DESKTOP, hwnd, txt, "VICE/2 Error", 0, &mb); lib_free(txt); return FALSE; } // // FIXME! Better solution? // slash = strrchr(szpath, '\\'); if (slash) { *slash = '\0'; } chdir(szpath); } return (MRESULT)TRUE; } return WinDefFileDlgProc(hwnd, msg, mp1, mp2); }