00001
00002 #include "FilesAssociations.h"
00003 #include "Messages.h"
00004 #include "Warnings.h"
00005 #include "Errors.h"
00006
00007 #include "win_mem_alloc.h"
00008
00009 extern void ReplaceSlash(char *pathout,char *pathin);
00010 extern void PrintFile(char *filename);
00011 extern BOOL SendCommandToAnotherScilab(char *ScilabWindowNameSource,char *ScilabWindowNameDestination,char *CommandLine);
00012 extern BOOL HaveAnotherWindowScilab(void);
00013 extern char * ChooseAnotherWindowScilab(void);
00014
00015
00016
00017 BOOL IsAFile(char *chainefichier)
00018 {
00019 BOOL retour=FALSE;
00020
00021 WIN32_FIND_DATA FindFileData;
00022 HANDLE handle = FindFirstFile (chainefichier, &FindFileData);
00023 if (handle != INVALID_HANDLE_VALUE)
00024 {
00025 FindClose (handle);
00026 retour=TRUE;
00027 }
00028 else retour=FALSE;
00029
00030 return retour;
00031 }
00032
00033
00034
00035 BOOL IsABinOrSavFile(char *chainefichier)
00036 {
00037 BOOL retour=FALSE;
00038 char *ExtensionFilename=NULL;
00039
00040 ExtensionFilename=PathFindExtension(chainefichier);
00041
00042
00043 if ( (_stricmp(ExtensionFilename,".BIN")==0) || (_stricmp(ExtensionFilename,".SAV")==0) ) retour=TRUE;
00044
00045 if (ExtensionFilename) {FREE(ExtensionFilename);ExtensionFilename=NULL;}
00046 return retour;
00047
00048 }
00049
00050 BOOL IsAGraphFile(char *chainefichier)
00051 {
00052 BOOL retour=FALSE;
00053
00054 if ( IsAGraphFilegraphb(chainefichier) || IsAGraphFilegraph(chainefichier) ) retour=TRUE;
00055
00056 return retour;
00057 }
00058
00059 BOOL IsAGraphFilegraph(char *chainefichier)
00060 {
00061 BOOL retour=FALSE;
00062 char *ExtensionFilename=NULL;
00063
00064 ExtensionFilename=PathFindExtension(chainefichier);
00065
00066
00067 if (_stricmp(ExtensionFilename,".GRAPH")==0) retour=TRUE;
00068
00069 if (ExtensionFilename) {FREE(ExtensionFilename);ExtensionFilename=NULL;}
00070 return retour;
00071 }
00072
00073 BOOL IsAGraphFilegraphb(char *chainefichier)
00074 {
00075 BOOL retour=FALSE;
00076 char *ExtensionFilename=NULL;
00077
00078 ExtensionFilename=PathFindExtension(chainefichier);
00079
00080
00081 if (_stricmp(ExtensionFilename,".GRAPHB")==0) retour=TRUE;
00082
00083 if (ExtensionFilename) {FREE(ExtensionFilename);ExtensionFilename=NULL;}
00084 return retour;
00085 }
00086
00087 BOOL IsAScicosFile(char *chainefichier)
00088 {
00089 BOOL retour=FALSE;
00090
00091 if ( IsAScicosFileCOS(chainefichier) || IsAScicosFileCOSF(chainefichier) ) retour=TRUE;
00092
00093 return retour;
00094 }
00095
00096 BOOL IsAScicosFileCOS(char *chainefichier)
00097 {
00098 BOOL retour=FALSE;
00099 char *ExtensionFilename=NULL;
00100
00101 ExtensionFilename=PathFindExtension(chainefichier);
00102
00103
00104 if (_stricmp(ExtensionFilename,".COS")==0) retour=TRUE;
00105
00106 if (ExtensionFilename) {FREE(ExtensionFilename);ExtensionFilename=NULL;}
00107 return retour;
00108 }
00109
00110 BOOL IsAScicosFileCOSF(char *chainefichier)
00111 {
00112 BOOL retour=FALSE;
00113 char *ExtensionFilename=NULL;
00114
00115 ExtensionFilename=PathFindExtension(chainefichier);
00116
00117
00118 if (_stricmp(ExtensionFilename,".COSF")==0) retour=TRUE;
00119
00120 if (ExtensionFilename) {FREE(ExtensionFilename);ExtensionFilename=NULL;}
00121 return retour;
00122 }
00123
00124 int CommandByFileExtension(char *fichier,int OpenCode,char *Cmd)
00125 {
00126 int Retour=FALSE;
00127 char FinalFileName[MAX_PATH];
00128 char ShortPath[MAX_PATH];
00129 char PathWScilex[MAX_PATH];
00130
00131 if (fichier[0]=='\"')
00132 {
00133 char buffertemp[MAX_PATH];
00134 int i=1;
00135
00136 while (fichier[i] != '"')
00137 {
00138 buffertemp[i-1]=fichier[i];
00139 i++;
00140 if (i> (int)strlen(fichier))
00141 {
00142 i=(int)strlen(fichier);
00143 break;
00144 }
00145 }
00146 buffertemp[i-1]='\0';
00147 strcpy(fichier,buffertemp);
00148 }
00149 if (fichier[strlen(fichier)-1]=='\"') fichier[strlen(fichier)-1]='\0';
00150
00151 if (IsAFile(fichier))
00152 {
00153 GetShortPathName(fichier,ShortPath,MAX_PATH);
00154 ReplaceSlash(FinalFileName,ShortPath);
00155 GetModuleFileName ((HINSTANCE)GetModuleHandle(NULL), PathWScilex, MAX_PATH);
00156 Retour=TRUE;
00157
00158 switch (OpenCode)
00159 {
00160 case 1:
00161 {
00162 if ( IsABinOrSavFile(FinalFileName)== TRUE )
00163 {
00164
00165 wsprintf(Cmd,MSG_SCIMSG1,PathWScilex,FinalFileName,FinalFileName);
00166 }
00167 else
00168 if ( IsAScicosFile(fichier)== TRUE )
00169 {
00170 ExtensionFileIntoLowerCase(FinalFileName);
00171 wsprintf(Cmd,MSG_SCIMSG2,PathWScilex,FinalFileName);
00172 }
00173 else
00174 if ( IsAGraphFile(fichier)== TRUE )
00175 {
00176 ExtensionFileIntoLowerCase(FinalFileName);
00177 wsprintf(Cmd,MSG_SCIMSG3,PathWScilex,FinalFileName);
00178 }
00179 else wsprintf(Cmd,MSG_SCIMSG4,PathWScilex,FinalFileName);
00180 }
00181 break;
00182 case 2:
00183 {
00184 PrintFile(fichier);
00185 strcpy(Cmd," ");
00186 exit(0);
00187 }
00188 break;
00189 case 0:default:
00190 {
00191 if (! HaveAnotherWindowScilab())
00192 {
00193 wsprintf(Cmd,MSG_SCIMSG5,PathWScilex,FinalFileName);
00194 }
00195 else
00196 {
00197 char *ScilabDestination=NULL;
00198 wsprintf(Cmd,MSG_SCIMSG6,FinalFileName);
00199
00200 ScilabDestination=(char*)ChooseAnotherWindowScilab();
00201 if (ScilabDestination)
00202 {
00203 SendCommandToAnotherScilab(MSG_SCIMSG7,ScilabDestination,Cmd);
00204 FREE(ScilabDestination);
00205 exit(0);
00206 }
00207 else
00208 {
00209 wsprintf(Cmd,MSG_SCIMSG8,PathWScilex,FinalFileName);
00210 }
00211
00212 }
00213 }
00214 break;
00215
00216 }
00217
00218 }
00219
00220
00221 return Retour;
00222 }
00223
00224 void ExtensionFileIntoLowerCase(char *fichier)
00225 {
00226 char *tmpfile=NULL;
00227 char *buffer=NULL;
00228 char *lastdot=NULL;
00229 char *ext=NULL;
00230
00231 tmpfile=(char*)MALLOC(strlen(fichier)*sizeof(char));
00232 strcpy(tmpfile,fichier);
00233
00234 buffer=strtok(tmpfile,".");
00235 while ( buffer = strtok(NULL,"."))
00236 {
00237 lastdot=buffer;
00238 }
00239
00240 ext=_strlwr(lastdot);
00241
00242 strcpy(&fichier[strlen(fichier)-strlen(ext)],ext);
00243
00244 FREE(tmpfile);
00245 }
00246