Changeset 1829 for trunk/dll/misc.c
- Timestamp:
- Jul 13, 2015, 12:01:22 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/misc.c
r1795 r1829 72 72 12 Nov 11 GKY Fixed HelpViewer's failure to open help files and subsequent failure with files with spaces. 73 73 28 Jun 14 GKY Fix errors identified with CPPCheck 74 12 Jul 15 GKY Fix CN_REALLOCPSZ file name editing code to: 1) Actually reallocate the buffer. 75 2) Point pci->pszDisplayName into the new buffer 3) Eliminate the possibility 76 of updating the container before CN_ENDEDIT is called. 4) Only call RemoveCnrItems 77 for tree container and collector. 74 78 75 79 ***********************************************************************/ … … 118 122 #include "fortify.h" 119 123 #include "info.h" // driveflags 124 #if 0 125 #define __PMPRINTF__ 126 #include "PMPRINTF.H" 127 #endif 120 128 121 129 #define CONTAINER_COLUMNS 13 // Number of columns in details view … … 821 829 MRESULT CnrDirectEdit(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) 822 830 { 831 static CHAR oldname[CCHMAXPATH]; 832 static CHAR newname[CCHMAXPATH]; 833 static BOOL fPostName = FALSE; 834 823 835 switch (SHORT2FROMMP(mp1)) { 824 836 case CN_BEGINEDIT: … … 848 860 PFIELDINFO pfi = ((PCNREDITDATA) mp2)->pFieldInfo; 849 861 PCNRITEM pci = (PCNRITEM) ((PCNREDITDATA) mp2)->pRecord; 850 CHAR szData[CCHMAXPATH],testname[CCHMAXPATH];862 CHAR testname[CCHMAXPATH]; 851 863 HWND hwndMLE = WinWindowFromID(hwnd, CID_MLE); 852 864 BOOL fResetVerify = FALSE; 865 PSZ psz; 866 LONG retlen; 867 APIRET rc; 853 868 854 869 if (pci && (INT) pci != -1 && !IsRoot(pci->pszFileName)) { 855 870 if (pfi && pfi->offStruct == FIELDOFFSET(CNRITEM, pszSubject)) { 856 857 APIRET rc;858 871 EAOP2 eaop; 859 872 PFEA2LIST pfealist = NULL; … … 862 875 USHORT len; 863 876 CHAR *eaval; 864 LONG retlen;865 PSZ psz;866 877 867 878 retlen = WinQueryWindowText(hwndMLE, sizeof(szSubject), szSubject); … … 879 890 pci->pszSubject = psz; 880 891 else { 881 free(pci->pszSubject);892 xfree(pci->pszSubject, pszSrcFile, __LINE__); 882 893 pci->pszSubject = NullStr; 883 894 return FALSE; // out of memory … … 925 936 } 926 937 else if (pfi && pfi->offStruct == FIELDOFFSET(CNRITEM, pszLongName)) { 927 928 938 CHAR longname[CCHMAXPATHCOMP]; 929 LONG retlen;930 PSZ psz;931 939 932 940 *longname = 0; … … 947 955 pci->pszLongName = psz; 948 956 else { 949 free(pci->pszLongName);957 xfree(pci->pszLongName, pszSrcFile, __LINE__); 950 958 pci->pszLongName = NullStr; 951 959 return FALSE; // out of memory … … 961 969 } 962 970 else { 963 PSZ psz; 964 965 WinQueryWindowText(hwndMLE, sizeof(szData), szData); 966 if (strchr(szData, '?') || 967 strchr(szData, '*') || IsRoot(pci->pszFileName)) 971 WinQueryWindowText(hwndMLE, sizeof(testname), testname); 972 // fixme to check for other illegal chars? GKY 11 Jul 15 973 if (strchr(testname, '?') || strchr(testname, '*')) 968 974 return (MRESULT) FALSE; 969 975 // If the text changed, rename the file system object. 970 chop_at_crnl( szData);971 bstrip( szData);972 if (!IsFullName( szData))976 chop_at_crnl(testname); 977 bstrip(testname); 978 if (!IsFullName(testname)) 973 979 Runtime_Error(pszSrcFile, __LINE__, "bad name"); 974 else { 975 if (DosQueryPathInfo(szData, 976 FIL_QUERYFULLNAME, 977 testname, sizeof(testname))) 980 else { 981 DIRCNRDATA *dcd; 982 FILEFINDBUF4L ffb; 983 HDIR hDir = HDIR_CREATE; 984 ULONG nm = 1; 985 CHAR *p; 986 987 if (DosQueryPathInfo(testname, //Why does this return 0 when the file doesn't exist? 988 FIL_QUERYFULLNAME, // No new directory creation? 989 newname, sizeof(newname))) 978 990 return FALSE; 979 991 if (DosQueryPathInfo(pci->pszFileName, 980 992 FIL_QUERYFULLNAME, 981 szData, 982 sizeof(szData))) 983 { 984 psz = xrealloc(pci->pszFileName, sizeof(szData), pszSrcFile, __LINE__); 985 if (psz) 986 pci->pszFileName = psz; 987 else { 988 free(pci->pszFileName); 989 pci->pszFileName = NullStr; 990 return FALSE; // out of memory 993 oldname, sizeof(oldname))) 994 strcpy(oldname, pci->pszFileName); 995 psz = xrealloc(pci->pszFileName, sizeof(oldname), pszSrcFile, __LINE__); 996 if (psz) 997 pci->pszFileName = psz; 998 else { 999 xfree(pci->pszFileName, pszSrcFile, __LINE__); 1000 pci->pszFileName = NullStr; 1001 return FALSE; // out of memory 1002 } 1003 if (!dcd) // Point pci->pszDisplayName into the realloc pci->pszFileName 1004 dcd = INSTDATA(hwnd); 1005 rc = xDosFindFirst(pci->pszFileName, 1006 &hDir, 1007 FILE_NORMAL | FILE_DIRECTORY | 1008 FILE_ARCHIVED | FILE_READONLY | 1009 FILE_HIDDEN | FILE_SYSTEM, 1010 &ffb, sizeof(ffb), &nm, FIL_QUERYEASIZEL); 1011 if (!rc) { // file exists 1012 DosFindClose(hDir); 1013 if (dcd->type == DIR_FRAME || dcd->type == TREE_FRAME) { 1014 p = strrchr(pci->pszFileName, '\\'); 1015 if (!p) { 1016 p = strrchr(pci->pszFileName, ':'); 1017 if (!p) 1018 p = pci->pszFileName; 1019 else 1020 p++; 1021 } 1022 else if ((dcd && dcd->type == TREE_FRAME) || 1023 !(ffb.attrFile & FILE_DIRECTORY) || !*(p + 1)) 1024 p++; 1025 if (!*p) 1026 p = pci->pszFileName; 991 1027 } 992 strcpy(szData, pci->pszFileName); 1028 else 1029 p = pci->pszFileName; 1030 pci->pszDisplayName = p; 993 1031 } 994 WinSetWindowText(hwndMLE, szData); 995 if (strcmp(szData, testname)) { 996 if (stricmp(szData, testname) && IsFile(testname) != -1) { 1032 else 1033 return FALSE; // nothing to rename 1034 WinSetWindowText(hwndMLE, oldname); 1035 if (strcmp(oldname, newname)) { 1036 if (stricmp(oldname, newname) && IsFile(newname) != -1) { 997 1037 if (!fAlertBeepOff) 998 1038 DosBeep(50, 100); 999 1039 return (MRESULT) FALSE; // exists; disallow 1000 1040 } 1001 if (fVerify && (driveflags[toupper(* szData) - 'A'] & DRIVE_WRITEVERIFYOFF ||1002 driveflags[toupper(* testname) - 'A'] & DRIVE_WRITEVERIFYOFF)) {1041 if (fVerify && (driveflags[toupper(*oldname) - 'A'] & DRIVE_WRITEVERIFYOFF || 1042 driveflags[toupper(*newname) - 'A'] & DRIVE_WRITEVERIFYOFF)) { 1003 1043 DosSetVerify(FALSE); 1004 1044 fResetVerify = TRUE; 1005 1045 } 1006 if (docopyf(MOVE, szData, testname))1046 if (docopyf(MOVE, oldname, newname)) 1007 1047 Runtime_Error(pszSrcFile, __LINE__, "docopyf"); 1008 else { 1009 CHAR *filename; 1010 1011 filename = xstrdup(testname, pszSrcFile, __LINE__); 1012 if (filename) { 1013 if (!PostMsg(hwnd, 1014 UM_FIXEDITNAME, MPVOID, MPFROMP(filename))) 1015 free(filename); 1016 } 1017 if (stricmp(testname, pci->pszFileName)) { 1018 PostMsg(hwnd, UM_FIXEDITNAME, MPFROMLONG(-1), MPFROMP(pci)); 1019 filename = xstrdup(pci->pszFileName, pszSrcFile, __LINE__); 1020 if (filename) { 1021 if (!PostMsg(hwnd, 1022 UM_FIXEDITNAME, MPVOID, MPFROMP(filename))) 1023 free(filename); 1024 } 1025 } 1048 else { 1049 fPostName = TRUE; 1026 1050 } 1027 1051 if (fResetVerify) { … … 1041 1065 PCNRITEM pci = (PCNRITEM) ((PCNREDITDATA) mp2)->pRecord; 1042 1066 1067 if (fPostName) { 1068 CHAR *filename; 1069 DIRCNRDATA *dcd; 1070 1071 if (!dcd) 1072 dcd = INSTDATA(hwnd); 1073 filename = xstrdup(oldname, pszSrcFile, __LINE__); 1074 if (filename) { 1075 if (!PostMsg(hwnd,UM_FIXEDITNAME, MPVOID, MPFROMP(filename))) 1076 free(filename); 1077 } 1078 if (dcd && (dcd->type == TREE_FRAME || dcd->type == COLLECTOR_FRAME)) 1079 PostMsg(hwnd, UM_FIXEDITNAME, MPFROMLONG(-1), MPFROMP(pci)); 1080 filename = xstrdup(newname, pszSrcFile, __LINE__); 1081 if (filename) { 1082 if (!PostMsg(hwnd, UM_FIXEDITNAME, MPVOID, MPFROMP(filename))) 1083 free(filename); 1084 } 1085 fPostName = FALSE; 1086 } 1043 1087 if (pci && (INT) pci != -1 && !IsRoot(pci->pszFileName)) { 1044 1088 WinSendMsg(hwnd,
Note:
See TracChangeset
for help on using the changeset viewer.