Changeset 8048 for trunk/src/shell32/shell32_odin.cpp
- Timestamp:
- Mar 8, 2002, 12:01:03 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/shell32/shell32_odin.cpp
r7904 r8048 1 /* $Id: shell32_odin.cpp,v 1. 3 2002-02-14 12:10:10 sandervl Exp $ */1 /* $Id: shell32_odin.cpp,v 1.4 2002-03-08 11:01:00 sandervl Exp $ */ 2 2 3 3 /* … … 55 55 #include <ctype.h> 56 56 #include <module.h> 57 58 #include "os2_integration.h" 59 57 60 58 61 /***************************************************************************** … … 982 985 LPCSTR lpDirectory, 983 986 INT iShowCmd ) 984 { HINSTANCE retval=31; 985 char old_dir[1024]; 986 char cmd[256]; 987 988 if (lpFile==NULL) return 0; /* should not happen */ 989 if (lpOperation==NULL) /* default is open */ 990 lpOperation="open"; 991 992 if (lpDirectory) 993 { GetCurrentDirectoryA( sizeof(old_dir), old_dir ); 994 SetCurrentDirectoryA( lpDirectory ); 995 } 996 997 cmd[0] = '\0'; 998 retval = SHELL_FindExecutable( lpFile, lpOperation, cmd ); 999 1000 if (retval > 32) /* Found */ 987 { 988 HINSTANCE retval=31; 989 char old_dir[1024]; 990 char cmd[256]; 991 LONG cmdlen = sizeof( cmd ); 992 LPSTR tok; 993 994 if (lpFile==NULL) 995 return 0; /* should not happen */ 996 997 if (lpOperation==NULL) /* default is open */ 998 lpOperation="open"; 999 1000 if (lpDirectory) 1001 { 1002 // @@@PH 2002-02-26 might throw whole process off track 1003 // in case of concurrency 1004 GetCurrentDirectoryA( sizeof(old_dir), old_dir ); 1005 SetCurrentDirectoryA( lpDirectory ); 1006 } 1007 1008 cmd[0] = '\0'; 1009 retval = SHELL_FindExecutable( lpFile, lpOperation, cmd ); 1010 1011 if (retval > 32) /* Found */ 1012 { 1013 if (lpParameters) 1001 1014 { 1002 if (lpParameters) 1003 { 1004 strcat(cmd," "); 1005 strcat(cmd,lpParameters); 1006 } 1007 1008 dprintf(("starting %s\n",cmd)); 1009 retval = WinExec( cmd, iShowCmd ); 1010 } 1011 else if(PathIsURLA((LPSTR)lpFile)) /* File not found, check for URL */ 1015 strcat(cmd," "); 1016 strcat(cmd,lpParameters); 1017 } 1018 1019 dprintf(("starting %s\n",cmd)); 1020 retval = WinExec( cmd, iShowCmd ); 1021 } 1022 else 1023 { 1024 // - path might be an URL 1025 // - argument might be associated with some class / app 1026 1027 // 2002-02-26 PH 1028 // File Extension Association is missing. We'd have to lookup 1029 // i. e. ".doc" and create the command. 1030 // @@@PH 1031 1032 // build lookup key 1033 char lpstrShellSubkey[256] = "\\shell\\"; 1034 /* Looking for ...protocol\shell\lpOperation\command */ 1035 strcat( lpstrShellSubkey, lpOperation ); 1036 strcat( lpstrShellSubkey, "\\command" ); 1037 1038 // First, check for URL association 1039 if(PathIsURLA((LPSTR)lpFile)) /* File not found, check for URL */ 1012 1040 { 1013 char lpstrProtocol[256];1014 LONG cmdlen = 512;1015 1041 LPSTR lpstrRes; 1016 1042 INT iSize; 1017 1043 1018 1044 lpstrRes = strchr(lpFile,':'); 1019 iSize = lpstrRes - lpFile; 1020 1021 /* Looking for ...protocol\shell\lpOperation\command */ 1022 strncpy(lpstrProtocol,lpFile,iSize); 1023 lpstrProtocol[iSize]='\0'; 1024 strcat( lpstrProtocol, "\\shell\\" ); 1025 strcat( lpstrProtocol, lpOperation ); 1026 strcat( lpstrProtocol, "\\command" ); 1027 1028 /* Remove File Protocol from lpFile */ 1029 /* In the case file://path/file */ 1030 if(!strnicmp(lpFile,"file",iSize)) 1045 if (NULL != lpstrRes) 1031 1046 { 1032 lpFile += iSize; 1033 while(*lpFile == ':') lpFile++; 1034 } 1035 1036 1037 /* Get the application for the protocol and execute it */ 1038 if (RegQueryValueA( HKEY_CLASSES_ROOT, lpstrProtocol, cmd, 1047 char szProtocol[256]; 1048 1049 iSize = lpstrRes - lpFile; 1050 1051 strncpy(szProtocol, 1052 lpFile, 1053 min( sizeof( szProtocol ), iSize) ); 1054 1055 /* Remove File Protocol from lpFile */ 1056 /* In the case file://path/file */ 1057 if(!strnicmp(lpFile,"file",iSize)) 1058 { 1059 lpFile += iSize; 1060 while(*lpFile == ':') lpFile++; 1061 } 1062 1063 /* Get the application for the protocol and execute it */ 1064 if (RegQueryValueA(HKEY_CLASSES_ROOT, 1065 szProtocol, 1066 cmd, 1039 1067 &cmdlen ) == ERROR_SUCCESS ) 1040 { 1041 LPSTR tok; 1068 { 1042 1069 LPSTR tmp; 1043 1070 char param[256] = ""; 1044 1071 LONG paramlen = 256; 1045 1072 1046 1073 /* Get the parameters needed by the application 1047 1074 from the associated ddeexec key */ 1048 tmp = strstr( lpstrProtocol,"command");1075 tmp = strstr(szProtocol,"command"); 1049 1076 tmp[0] = '\0'; 1050 strcat(lpstrProtocol,"ddeexec"); 1051 1052 if(RegQueryValueA( HKEY_CLASSES_ROOT, lpstrProtocol, param,¶mlen ) == ERROR_SUCCESS) 1077 strcat(szProtocol,"ddeexec"); 1078 1079 if(RegQueryValueA(HKEY_CLASSES_ROOT, 1080 szProtocol, 1081 param, 1082 ¶mlen ) == ERROR_SUCCESS) 1053 1083 { 1054 1084 strcat(cmd," "); … … 1056 1086 cmdlen += paramlen; 1057 1087 } 1058 1059 /* Is there a replace() function anywhere? */ 1060 cmd[cmdlen]='\0'; 1061 tok=strstr( cmd, "%1" ); 1062 if (tok != NULL) 1088 } 1089 } 1090 } 1091 1092 1093 // Second, check for filename extension association 1094 if (0 == cmd[0]) 1095 { 1096 LPSTR lpstrRDot = strrchr(lpFile, '.'); 1097 if (NULL != lpstrRDot) 1098 { 1099 char szAssociation[256]; 1100 LONG lAssociationLen = sizeof( szAssociation ); 1101 1102 // lookup associated application (or COM object) for 1103 // this extension 1104 if (RegQueryValueA(HKEY_CLASSES_ROOT, 1105 lpstrRDot, 1106 szAssociation, 1107 &lAssociationLen) == ERROR_SUCCESS) 1108 { 1109 // append the shell subkey 1110 strcat(szAssociation, lpstrShellSubkey); 1111 lAssociationLen = sizeof( szAssociation ); 1112 1113 // lookup application for retrieved association 1114 if (RegQueryValueA(HKEY_CLASSES_ROOT, 1115 szAssociation, 1116 cmd, 1117 &cmdlen) == ERROR_SUCCESS) 1063 1118 { 1064 tok[0]='\0'; /* truncate string at the percent */ 1065 strcat( cmd, lpFile ); /* what if no dir in xlpFile? */ 1066 tok=strstr( cmd, "%1" ); 1067 if ((tok!=NULL) && (strlen(tok)>2)) 1068 { 1069 strcat( cmd, &tok[2] ); 1070 } 1071 } 1072 1073 retval = WinExec( cmd, iShowCmd ); 1119 // received cmd now 1120 } 1121 } 1074 1122 } 1075 1123 } 1076 /* Check if file specified is in the form www.??????.*** */ 1077 else if(!strnicmp(lpFile,"www",3)) 1124 1125 1126 #ifdef __WIN32OS2__ 1127 if (0 == cmd[0]) 1078 1128 { 1079 /* if so, append lpFile http:// and call ShellExecute */ 1080 char lpstrTmpFile[256] = "http://" ; 1081 strcat(lpstrTmpFile,lpFile); 1082 retval = ShellExecuteA(hWnd,lpOperation,lpstrTmpFile,NULL,NULL,0); 1083 } 1129 // OS/2 specific addon: 1130 // if no windows association is found, pass on to the workplace shell 1131 // eventually. 1132 retval = ShellExecuteOS2(hWnd, 1133 lpOperation, 1134 lpFile, 1135 lpParameters, 1136 lpDirectory, 1137 iShowCmd); 1138 } 1139 #endif 1140 1141 if (0 != cmd[0]) 1142 { 1143 // resolve the parameters 1144 // @@@PH 2002-02-26 there might be more than one parameter only 1145 /* Is there a replace() function anywhere? */ 1146 tok=strstr( cmd, "%1" ); 1147 if (tok != NULL) 1148 { 1149 tok[0]='\0'; /* truncate string at the percent */ 1150 strcat( cmd, lpFile ); /* what if no dir in xlpFile? */ 1151 tok=strstr( cmd, "%1" ); 1152 if ((tok!=NULL) && (strlen(tok)>2)) 1153 { 1154 strcat( cmd, &tok[2] ); 1155 } 1156 } 1157 } 1158 1084 1159 /* Nothing was done yet, try to execute the cmdline directly, 1085 1086 else1160 maybe it's an OS/2 program */ 1161 if (0 == cmd[0]) 1087 1162 { 1088 1163 strcpy(cmd,lpFile); 1089 1164 strcat(cmd,lpParameters ? lpParameters : ""); 1090 retval = WinExec( cmd, iShowCmd ); 1091 } 1092 1093 if (lpDirectory) 1094 SetCurrentDirectoryA( old_dir ); 1095 return retval; 1165 } 1166 1167 // now launch ... something :) 1168 retval = WinExec( cmd, iShowCmd ); 1169 } 1170 1171 if (lpDirectory) 1172 SetCurrentDirectoryA( old_dir ); 1173 1174 return retval; 1096 1175 } 1097 1176
Note:
See TracChangeset
for help on using the changeset viewer.