static geBoolean GENESISCC FSDos_RenameFile(geVFile *FS, void *Handle, const char *Name, const char *NewName) { DosFile * File; char Old[_MAX_PATH]; char New[_MAX_PATH]; File = Handle; if (File && File->IsDirectory == GE_FALSE) return GE_FALSE; if (BuildFileName(File, Name, Old, NULL, sizeof(Old)) == GE_FALSE) return GE_FALSE; if (BuildFileName(File, NewName, New, NULL, sizeof(New)) == GE_FALSE) return GE_FALSE; if (MoveFile(Old, New) == FALSE) return GE_FALSE; return GE_TRUE; }
static geBoolean GENESISCC FSDos_DeleteFile(geVFile *FS, void *Handle, const char *Name) { DosFile * File; char Buff[_MAX_PATH]; File = Handle; if (File && File->IsDirectory == GE_FALSE) return GE_FALSE; if (BuildFileName(File, Name, Buff, NULL, sizeof(Buff)) == GE_FALSE) return GE_FALSE; if (DeleteFile(Buff) == FALSE) return GE_FALSE; return GE_TRUE; }
static geBoolean GENESISCC FSDos_FileExists(geVFile *FS, void *Handle, const char *Name) { DosFile * File; char Buff[_MAX_PATH]; File = Handle; if (File && File->IsDirectory == GE_FALSE) return GE_FALSE; if (BuildFileName(File, Name, Buff, NULL, sizeof(Buff)) == GE_FALSE) return GE_FALSE; if (GetFileAttributes(Buff) == 0xffffffff) return GE_FALSE; return GE_TRUE; }
static void * GENESISCC FSDos_FinderCreate( geVFile * FS, void * Handle, const char * FileSpec) { DosFinder * Finder; DosFile * File; char * NamePtr; char Buff[_MAX_PATH]; assert(FileSpec != NULL); File = Handle; CHECK_HANDLE(File); Finder = geRam_Allocate(sizeof(*Finder)); if (!Finder) return NULL; memset(Finder, 0, sizeof(*Finder)); if (BuildFileName(File, FileSpec, Buff, &NamePtr, sizeof(Buff)) == GE_FALSE) { geRam_Free(Finder); return NULL; } Finder->OffsetToName = NamePtr - Buff; Finder->FindHandle = FindFirstFile(Buff, &Finder->FindData); Finder->FirstStillCached = GE_TRUE; Finder->Signature = DOSFINDER_SIGNATURE; return (void *)Finder; }
void CEOSSPropertySheet::WriteToFile(int ToWhom, int Type, CJulianTime* Time, char* Msg) { FILE *File; char Message[256]; fpos_t position; Message[0] = NULL; COleDateTime TC = COleDateTime::GetCurrentTime(); COleDateTime TG; COleDateTimeSpan TS; CString ArchiveFileName; // if (m_pParent->m_bBlockWrite) // return; //default to the provided EOSS time if (Time) { int Year,Month,Day,Hour,Minute,Second; Year = Time->Year(); Month = Time->Month(); Day = Time->Day(); Hour = Time->Hour(); Minute = Time->Minute(); Second = Time->Second(); if (Year < 100) Year = 1900;//COleDateTime limits year 100-9999 if (Year > 9999) Year = 9999;//COleDateTime limits year 100-9999 if (Month < 1) Month = 1; if (Day < 1) Day = 1; if (Hour < 0) Hour = 0; if (Minute < 0) Minute = 0; if (Second < 0) Second = 0; TG = COleDateTime(Year, Month, Day, Hour, Minute, Second); } //if that wasn't available then get the computer time //this is the case in all TYPE_COMP messages else { TG = COleDateTime::GetCurrentTime(); } if (ToWhom == TO_DMP) { // build new file name and save it if (m_pParent->m_bUseShortFilename) { char cYear; int iYear = TC.GetYear(); if ((iYear < 1990) || (iYear > 2025)) cYear = '#'; else if (iYear < 2000) cYear = (char)('0' + iYear - 1990); else cYear = (char)('A' + iYear - 2000); sprintf(m_szCurrentFileName,"%s\\%s%c%c%c%c%02d.", m_pParent->m_szSaveLoc, m_pParent->m_pID, // ((TC.GetYear()-1990)<10)? // ((TC.GetYear()-1990<0)?'#':'0'+(TC.GetYear()-1990)): // 'A'+(TC.GetYear()-2000), cYear, ((TC.GetMonth()<10)? '0'+(TC.GetMonth()): 'A'+(TC.GetMonth()-10)), ((TC.GetDay() <10)? '0'+(TC.GetDay()): 'A'+(TC.GetDay() -10)), 'A',0); } else { CString cResult; BuildFileName(cResult, m_pParent->m_csLongNameFormatString, m_pParent->m_szSaveLoc,"EO", m_pParent->m_pID,TC.GetYear(),TC.GetMonth(),TC.GetDay(),0,0,0,"","."); strcpy(m_szCurrentFileName,cResult); } } else { if (m_pParent->m_bUseShortFilename) { // build new file name and save it char cYear; int iYear = TG.GetYear(); if ((iYear < 1990) || (iYear > 2025)) cYear = '#'; else if (iYear < 2000) cYear = (char)('0' + iYear - 1990); else cYear = (char)('A' + iYear - 2000); sprintf(m_szCurrentFileName,"%s\\%s%c%c%c%c%02d.", ((CEOSSInstrument*)m_pParent)->m_szSaveLoc, ((CEOSSInstrument*)m_pParent)->m_pID, cYear, ((TG.GetMonth()<10)? '0'+(TG.GetMonth()): 'A'+(TG.GetMonth()-10)), ((TG.GetDay() <10)? '0'+(TG.GetDay()): 'A'+(TG.GetDay() -10)), 'A',0); } else { CString cResult; BuildFileName(cResult, m_pParent->m_csLongNameFormatString, m_pParent->m_szSaveLoc,"EO", m_pParent->m_pID,TG.GetYear(),TG.GetMonth(),TG.GetDay(),0,0,0,"","."); strcpy(m_szCurrentFileName,cResult); } } //format string to send switch (Type){ case TYPE_DUMP: sprintf(Message,"%4d.%02d.%02d %02d:%02d:%02d %s\n", TC.GetYear(),TC.GetMonth(),TC.GetDay(), TC.GetHour(),TC.GetMinute(),TC.GetSecond(), Msg); // strcpy(Message,Msg); break; case TYPE_INST: // message = Time::YY.MM.DD HH:MM:SS G (MESSAGE==NULL)?\r:MESSAGE sprintf(Message,"%04d.%02d.%02d %02d:%02d:%02d E %s\n", TG.GetYear(), TG.GetMonth(), TG.GetDay(), TG.GetHour(), TG.GetMinute(), TG.GetSecond(), Msg[0]==NULL?"":Msg); break; case TYPE_COMP: // message = MICTIME::YY.MM.DD HH:MM:SS C (MESSAGE==NULL)?\r:MESSAGE sprintf(Message,"%04d.%02d.%02d %02d:%02d:%02d C %s\n", TC.GetYear(), TC.GetMonth(), TC.GetDay(), TC.GetHour(),TC.GetMinute(),TC.GetSecond(),Msg[0]==NULL?"":Msg); break; case TYPE_GID2: case TYPE_TIME: // message = Time::YY.MM.DD HH:MM:SS EOSS Time "+ // "YY.MM.DD HH:MM:SS Computer Time C - E = xxxx\r" //computer time //EOSS time TS = TC - TG; // Subtract 2 COleDateTimes TS += HALF_SECOND; sprintf(Message,"%04d.%02d.%02d %02d:%02d:%02d E 47326 EOSS Time %04d.%02d.%02d %02d:%02d:%02d Computer Time C - E = %.0f seconds\n", TG.GetYear(), TG.GetMonth(), TG.GetDay(), TG.GetHour(), TG.GetMinute(), TG.GetSecond(), TC.GetYear(), TC.GetMonth(), TC.GetDay(), TC.GetHour(), TC.GetMinute(), TC.GetSecond(), TS.GetTotalSeconds()); break; case TYPE_INVTIME: // message = "INVALID TIME "+ // "Previous Record Time Saved::YY.MM.DD HH:MM:SS "+ // "Current Record Time Time::YY.MM.DD HH:MM:SS\r" sprintf(Message,"%04d.%02d.%02d %02d:%02d:%02d I 47327 EOSS INVALID TIME %04d.%02d.%02d %02d:%02d:%02d\n", ((CJulianTime*)Msg)->Year(), ((CJulianTime*)Msg)->Month(), ((CJulianTime*)Msg)->Day(), ((CJulianTime*)Msg)->Hour(), ((CJulianTime*)Msg)->Minute(), ((CJulianTime*)Msg)->Second(), TG.GetYear(), TG.GetMonth(), TG.GetDay(), TG.GetHour(), TG.GetMinute(), TG.GetSecond()); break; case TYPE_START: // message = MICTIME::YY.MM.DD HH:MM:SS C EOSS COLLECT Version %s<VERSION> started\r" sprintf(Message,"%04d.%02d.%02d %02d:%02d:%02d C 47411 EOSS COLLECT Version %s started\n", TC.GetYear(), TC.GetMonth(), TC.GetDay(), TC.GetHour(), TC.GetMinute(), TC.GetSecond(), m_pParent->m_csVersion); break; case TYPE_ABNORMAL: // message = MICTIME::YY.MM.DD HH:MM:SS C EOSS COLLECT Version %s<VERSION> started\r" sprintf(Message,"%04d.%02d.%02d %02d:%02d:%02d C 47412 EOSS COLLECT Version %s started from abnormal shutdown\n", TC.GetYear(), TC.GetMonth(), TC.GetDay(), TC.GetHour(), TC.GetMinute(), TC.GetSecond(), m_pParent->m_csVersion); break; case TYPE_DELETE: // message = MICNOW::YY.MM.DD HH:MM:SS C file %s<MESSAGE> deleted\r" sprintf(Message,"%04d.%02d.%02d %02d:%02d:%02d C 47413 EOSS File %s deleted\n", TC.GetYear(), TC.GetMonth(), TC.GetDay(), TC.GetHour(), TC.GetMinute(), TC.GetSecond(), Msg); break; //just in case default: sprintf(Message,"%04d.%02d.%02d %02d:%02d:%02d C 47328 EOSS Unknown TYPE %s\n", TC.GetYear(), TC.GetMonth(), TC.GetDay(), TC.GetHour(), TC.GetMinute(), TC.GetSecond(), Msg); } //if to dmp do the write to todays file and get out if (ToWhom == TO_DMP) { // open filename+dmp CString fn(m_szCurrentFileName); fn += DMP_SUFFIX; // CString ArchiveFileNameEx = ArchiveFileName + DMP_SUFFIX; if (_access(fn,0) != 0) { // if (_access(ArchiveFileNameEx,0)!=-1) // MoveFileEx(ArchiveFileNameEx,fn, // MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH ); //make sure path exists MakeMyPath(fn); } if ((File = fopen(fn,"at+")) != NULL) { // send string fprintf(File,Message); // close cev fclose(File); } return; } //if to cev if (ToWhom & TO_CEV) { // open filename+cev CString fn(m_szCurrentFileName); fn += CEV_SUFFIX; //if fn does not exist (it may have been moved or we have a new day) if (_access(fn,0) != 0) { //make sure path exists MakeMyPath(fn); if (m_pParent->m_bUseShortFilename) { //build archive path\name char cYear; int iYear = TC.GetYear(); if ((iYear < 1990) || (iYear > 2025)) cYear = '#'; else if (iYear < 2000) cYear = (char)('0' + iYear - 1990); else cYear = (char)('A' + iYear - 2000); ArchiveFileName.Format("%s\\archive\\%s%c%c%c%c%02d.%s", ((CEOSSInstrument*)m_pParent)->m_szSaveLoc, ((CEOSSInstrument*)m_pParent)->m_pID, cYear, // ((TC.GetYear()-1990)<10)? // ((TC.GetYear()-1990<0)?'#':'0'+(TC.GetYear()-1990)): // 'A'+(TC.GetYear()-2000), ((TC.GetMonth()<10)? '0'+(TC.GetMonth()): 'A'+(TC.GetMonth()-10)), ((TC.GetDay() <10)? '0'+(TC.GetDay()): 'A'+(TC.GetDay() -10)), 'A',0,CEV_SUFFIX); } else { CString cTemp; cTemp = m_pParent->m_szSaveLoc; cTemp += "\\archive\\"; BuildFileName(ArchiveFileName, m_pParent->m_csLongNameFormatString, cTemp,"EO", m_pParent->m_pID,TC.GetYear(),TC.GetMonth(),TC.GetDay(),0,0,0,"",CEV_SUFFIX); } //if it exists in the subdirectory "archive" then move it and use it if (_access(ArchiveFileName,0)==0) MoveFileEx(ArchiveFileName,fn, MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH ); } if ((File = fopen(fn,"at+")) != NULL) { //if new file do stuff fseek(File,0,SEEK_END); fgetpos(File,&position); if (position==0) { m_bStartOfFile = true; } // send string fprintf(File,Message); // close cev fclose(File); } } //if to pfm if (ToWhom & TO_PFM) { // open filename+pfm CString fn(m_szCurrentFileName); fn += PFM_SUFFIX; // CString ArchiveFileNameExt = ArchiveFileName + PFM_SUFFIX; //if fn does not exist (it may have been moved or we have a new day) if (_access(fn,0) != 0) { //make sure path exists MakeMyPath(fn); //check if it is in the archive directory //build file name if (m_pParent->m_bUseShortFilename) { char cYear; int iYear = TC.GetYear(); if ((iYear < 1990) || (iYear > 2025)) cYear = '#'; else if (iYear < 2000) cYear = (char)('0' + iYear - 1990); else cYear = (char)('A' + iYear - 2000); ArchiveFileName.Format("%s\\archive\\%s%c%c%c%c%02d.%s", m_pParent->m_szSaveLoc, m_pParent->m_pID, cYear, // ((TC.GetYear()-1990)<10)? // ((TC.GetYear()-1990<0)?'#':'0'+(TC.GetYear()-1990)): // 'A'+(TC.GetYear()-2000), ((TC.GetMonth()<10)? '0'+(TC.GetMonth()): 'A'+(TC.GetMonth()-10)), ((TC.GetDay() <10)? '0'+(TC.GetDay()): 'A'+(TC.GetDay() -10)), 'A',0,PFM_SUFFIX); } else { CString cTemp; cTemp = ((CEOSSInstrument*)m_pParent)->m_szSaveLoc; cTemp += "\\archive\\"; BuildFileName(ArchiveFileName, m_pParent->m_csLongNameFormatString, cTemp,"EO", m_pParent->m_pID,TC.GetYear(),TC.GetMonth(),TC.GetDay(),0,0,0,"",PFM_SUFFIX); } //if it exists in the subdirectory "archive" then move it and use it if (_access(ArchiveFileName,0)==0) MoveFileEx(ArchiveFileName,fn, MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH ); } if ((File = fopen(fn,"at+")) != NULL) { //if new file do stuff fseek(File,0,SEEK_END); fgetpos( File, &position ); if (position==0) { m_bStartOfFile = true; } // send string fprintf(File,Message); // close pfm fclose(File); } } }
static void * GENESISCC FSDos_Open( geVFile * FS, void * Handle, const char * Name, void * Context, unsigned int OpenModeFlags) { DosFile * DosFS; DosFile * NewFile; char Buff[_MAX_PATH]; int Length; char * NamePtr; DosFS = Handle; if (DosFS && DosFS->IsDirectory != GE_TRUE) return NULL; NewFile = geRam_Allocate(sizeof(*NewFile)); if (!NewFile) return NewFile; memset(NewFile, 0, sizeof(*NewFile)); if (BuildFileName(DosFS, Name, Buff, &NamePtr, sizeof(Buff)) == GE_FALSE) goto fail; Length = strlen(Buff); NewFile->FullPath = geRam_Allocate(Length + 1); if (!NewFile->FullPath) goto fail; NewFile->Name = NewFile->FullPath + (NamePtr - &Buff[0]); memcpy(NewFile->FullPath, Buff, Length + 1); if (OpenModeFlags & GE_VFILE_OPEN_DIRECTORY) { WIN32_FIND_DATA FileInfo; HANDLE FindHandle; geBoolean IsDirectory; assert(!DosFS || DosFS->IsDirectory == GE_TRUE); memset(&FileInfo, 0, sizeof(FileInfo)); FindHandle = FindFirstFile(NewFile->FullPath, &FileInfo); if (FindHandle != INVALID_HANDLE_VALUE && FileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { IsDirectory = GE_TRUE; } else { IsDirectory = IsRootDirectory(NewFile->FullPath); } FindClose (FindHandle); if (OpenModeFlags & GE_VFILE_OPEN_CREATE) { if (IsDirectory == GE_TRUE) goto fail; if (CreateDirectory(NewFile->FullPath, NULL) == FALSE) goto fail; } else { if (IsDirectory != GE_TRUE) goto fail; } NewFile->IsDirectory = GE_TRUE; NewFile->FileHandle = INVALID_HANDLE_VALUE; } else { DWORD ShareMode=0; DWORD CreationMode; DWORD Access=0; DWORD LastError; CreationMode = OPEN_EXISTING; switch (OpenModeFlags & (GE_VFILE_OPEN_READONLY | GE_VFILE_OPEN_UPDATE | GE_VFILE_OPEN_CREATE)) { case GE_VFILE_OPEN_READONLY: Access = GENERIC_READ; ShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; break; case GE_VFILE_OPEN_CREATE: CreationMode = CREATE_ALWAYS; // Fall through case GE_VFILE_OPEN_UPDATE: Access = GENERIC_READ | GENERIC_WRITE; ShareMode = FILE_SHARE_READ; break; default: assert(!"Illegal open mode flags"); break; } NewFile->FileHandle = CreateFile(NewFile->FullPath, Access, ShareMode, NULL, CreationMode, 0, NULL); if (NewFile->FileHandle == INVALID_HANDLE_VALUE) { LastError = GetLastError(); goto fail; } } NewFile->Signature = DOSFILE_SIGNATURE; return (void *)NewFile; fail: if (NewFile->FullPath) geRam_Free(NewFile->FullPath); geRam_Free(NewFile); return NULL; }
INT cmd_copy(LPTSTR param) { LPTSTR *arg; INT argc, i, nFiles, nOverwrite = 0, nSrc = -1, nDes = -1; /* this is the path up to the folder of the src and dest ie C:\windows\ */ TCHAR szDestPath[MAX_PATH]; TCHAR szSrcPath[MAX_PATH]; DWORD dwFlags = 0; /* If this is the type of copy where we are adding files */ BOOL bAppend = FALSE; WIN32_FIND_DATA findBuffer; HANDLE hFile = NULL; BOOL bTouch = FALSE; /* Used when something like "copy c*.exe d*.exe" during the process of figuring out the new name */ /* Pointer to keep track of how far through the append input(file1+file2+file3) we are */ TCHAR * appendPointer = _T("\0"); /* The full path to src and dest. This has drive letter, folders, and filename */ TCHAR tmpDestPath[MAX_PATH]; TCHAR tmpSrcPath[MAX_PATH]; /* A bool on weather or not the destination name will be taking from the input */ BOOL bSrcName = FALSE; /* Seems like a waste but it is a pointer used to copy from input to PreserveName */ TCHAR * UseThisName; /* for CMDCOPY env */ TCHAR *evar; int size; TCHAR * szTouch; BOOL bHasWildcard, bDone = FALSE, bMoreFiles = FALSE; BOOL bMultipleSource = FALSE, bMultipleDest = FALSE; /* Show help/usage info */ if (!_tcsncmp(param, _T("/?"), 2)) { ConOutResPaging(TRUE, STRING_COPY_HELP2); return 0; } nErrorLevel = 0; /* Get the envor value if it exists */ evar = cmd_alloc(512 * sizeof(TCHAR)); if (evar == NULL) size = 0; else size = GetEnvironmentVariable (_T("COPYCMD"), evar, 512); if (size > 512) { TCHAR *old_evar = evar; evar = cmd_realloc(evar,size * sizeof(TCHAR) ); if (evar!=NULL) size = GetEnvironmentVariable (_T("COPYCMD"), evar, size); else { size=0; evar = old_evar; } } /* check see if we did get any env variable */ if (size != 0) { int t = 0; /* scan and set the flags */ for (t = 0; t < size; t++) { if (_tcsncicmp(_T("/A"),&evar[t],2) == 0) { dwFlags |=COPY_ASCII; t++; } else if (_tcsncicmp(_T("/B"),&evar[t],2) == 0) { dwFlags |= COPY_BINARY; t++; } else if (_tcsncicmp(_T("/D"),&evar[t],2) == 0) { dwFlags |= COPY_DECRYPT; t++; } else if (_tcsncicmp(_T("/V"),&evar[t],2) == 0) { dwFlags |= COPY_VERIFY; t++; } else if (_tcsncicmp(_T("/N"),&evar[t],2) == 0) { dwFlags |= COPY_SHORTNAME; t++; } else if (_tcsncicmp(_T("/Y"),&evar[t],2) == 0) { dwFlags |= COPY_NO_PROMPT; t++; } else if (_tcsncicmp(_T("/-Y"),&evar[t],3) == 0) { dwFlags |= COPY_PROMPT; t+=2; } else if (_tcsncicmp(_T("/Z"),&evar[t],2) == 0) { dwFlags |= COPY_PROMPT; t++; } } } cmd_free(evar); /* Split the user input into array */ arg = split(param, &argc, FALSE, TRUE); nFiles = argc; /* Read switches and count files */ for (i = 0; i < argc; i++) { if (*arg[i] == _T('/')) { if (_tcslen(arg[i]) >= 2) { switch (_totupper(arg[i][1])) { case _T('A'): dwFlags |= COPY_ASCII; break; case _T('B'): dwFlags |= COPY_BINARY; break; case _T('D'): dwFlags |= COPY_DECRYPT; break; case _T('V'): dwFlags |= COPY_VERIFY; break; case _T('N'): dwFlags |= COPY_SHORTNAME; break; case _T('Y'): dwFlags |= COPY_NO_PROMPT; dwFlags &= ~COPY_PROMPT; break; case _T('-'): if (_tcslen(arg[i]) >= 3) if (_totupper(arg[i][2]) == _T('Y')) { dwFlags &= ~COPY_NO_PROMPT; dwFlags |= COPY_PROMPT; } break; case _T('Z'): dwFlags |= COPY_RESTART; break; default: /* Invalid switch */ ConOutResPrintf(STRING_ERROR_INVALID_SWITCH, _totupper(arg[i][1])); nErrorLevel = 1; freep (arg); return 1; break; } } /* If it was a switch, subtract from total arguments */ nFiles--; } else { /* If it isn't a switch then it is the source or destination */ if (nSrc == -1) { nSrc = i; } else if (*arg[i] == _T('+')) { /* Next file should be appended */ bMoreFiles = TRUE; nFiles -= 1; } else if (bMoreFiles) { /* Add this file to the source string this way we can do all checks directly on source string later on */ TCHAR * ptr; int length = (_tcslen(arg[nSrc]) + _tcslen(arg[i]) + 2) * sizeof(TCHAR); ptr = cmd_alloc(length); if (ptr) { _tcscpy(ptr, arg[nSrc]); _tcscat(ptr, _T("|")); _tcscat(ptr, arg[i]); cmd_free(arg[nSrc]); arg[nSrc] = ptr; nFiles -= 1; } bMoreFiles = FALSE; } else if (nDes == -1) { nDes = i; } } } /* keep quiet within batch files */ if (bc != NULL) { dwFlags |= COPY_NO_PROMPT; dwFlags &= ~COPY_PROMPT; } if (nFiles < 1) { /* There are not enough files, there has to be at least 1 */ ConOutResPuts(STRING_ERROR_REQ_PARAM_MISSING); freep(arg); return 1; } if (nFiles > 2) { /* There are too many file names in command */ ConErrResPrintf(STRING_ERROR_TOO_MANY_PARAMETERS,_T("")); nErrorLevel = 1; freep(arg); return 1; } if ((_tcschr(arg[nSrc], _T('|')) != NULL) || (_tcschr(arg[nSrc], _T('*')) != NULL) || (_tcschr(arg[nSrc], _T('?')) != NULL) || IsExistingDirectory(arg[nSrc])) { bMultipleSource = TRUE; } /* Reusing the number of files variable */ nFiles = 0; /* Check if no destination argument is passed */ if (nDes == -1) { /* If no destination was entered then just use the current directory as the destination */ GetCurrentDirectory(MAX_PATH, szDestPath); } else { /* Check if the destination is 'x:' */ if ((arg[nDes][1] == _T(':')) && (arg[nDes][2] == _T('\0'))) { GetRootPath(arg[nDes], szDestPath, MAX_PATH); } else { /* If the user entered two file names then form the full string path */ GetFullPathName(arg[nDes], MAX_PATH, szDestPath, NULL); } /* Make sure there is an ending slash to the path if the dest is a folder */ if ((_tcschr(szDestPath, _T('*')) == NULL) && IsExistingDirectory(szDestPath)) { bMultipleDest = TRUE; if (szDestPath[_tcslen(szDestPath) - 1] != _T('\\')) _tcscat(szDestPath, _T("\\")); } /* Check if the destination uses wildcards */ if ((_tcschr(arg[nDes], _T('*')) != NULL) || (_tcschr(arg[nDes], _T('?')) != NULL)) { bMultipleDest = TRUE; } } if (nDes != -1) /* you can only append files when there is a destination */ { if (bMultipleSource && !bMultipleDest) { /* We have multiple source files, but not multiple destination files. This means we are appending the soruce files. */ bAppend = TRUE; if (_tcschr(arg[nSrc], _T('|')) != NULL) appendPointer = arg[nSrc]; } } /* Save the name the user entered */ UseThisName = _tcsrchr(szDestPath,_T('\\')); if (UseThisName) { /* Split the name from the path */ *UseThisName++ = _T('\0'); /* Check if the dest path ends with '\*' or '\' */ if (((UseThisName[0] == _T('*')) && (UseThisName[1] == _T('\0'))) || (UseThisName[0] == _T('\0'))) { /* In this case we will be using the same name as the source file for the destination file because destination is a folder */ bSrcName = TRUE; UseThisName = NULL; } } else { /* Something's seriously wrong! */ UseThisName = szDestPath; } do { /* Get the full string of the path to the source file */ if (_tcschr(arg[nSrc], _T('|')) != NULL) { /* Reset the source path */ szSrcPath[0] = _T('\0'); /* Loop through the source file name and copy all the chars one at a time until it gets too + */ while(TRUE) { if (appendPointer[0] == _T('|')) { /* Skip the | and go to the next file name */ appendPointer++; break; } else if (appendPointer[0] == _T('\0')) { bDone = TRUE; break; } _tcsncat(szSrcPath, appendPointer, 1); appendPointer++; } if (_tcschr(arg[nSrc], _T(',')) != NULL) { /* Only time there is a , in the source is when they are using touch Cant have a destination and can only have on ,, at the end of the string Cant have more then one file name */ szTouch = _tcsstr(arg[nSrc], _T("|")); if (_tcsncmp(szTouch,_T("|,,\0"), 4) || (nDes != -1)) { ConErrResPrintf(STRING_ERROR_INVALID_PARAM_FORMAT,arg[nSrc]); nErrorLevel = 1; freep (arg); return 1; } bTouch = TRUE; bDone = TRUE; } } else { bDone = TRUE; _tcscpy(szSrcPath, arg[nSrc]); } /* "x:" is not a valid source path format. */ if ((szSrcPath[1] == _T(':')) && (szSrcPath[2] == _T('\0'))) { ConOutPrintf(_T("%s\n"), szSrcPath); ConOutFormatMessage(ERROR_FILE_NOT_FOUND, szSrcPath); nErrorLevel = 1; break; } /* From this point on, we can assume that the shortest path is 3 letters long and that would be [DriveLetter]:\ */ /* Check if the path has a wildcard */ bHasWildcard = (_tcschr(szSrcPath, _T('*')) != NULL); /* If there is no * in the path name and it is a folder then we will need to add a wildcard to the pathname so FindFirstFile comes up with all the files in that folder */ if (!bHasWildcard && IsExistingDirectory(szSrcPath)) { /* If it doesnt have a \ at the end already then on needs to be added */ if (szSrcPath[_tcslen(szSrcPath) - 1] != _T('\\')) _tcscat(szSrcPath, _T("\\")); _tcscat(szSrcPath, _T("*")); bHasWildcard = TRUE; } /* If the path ends with '\' add a wildcard at the end */ if (szSrcPath[_tcslen(szSrcPath) - 1] == _T('\\')) { _tcscat(szSrcPath, _T("*")); bHasWildcard = TRUE; } /* Get a list of all the files */ hFile = FindFirstFile(szSrcPath, &findBuffer); /* If it couldnt open the file handle, print out the error */ if (hFile == INVALID_HANDLE_VALUE) { /* only print source name when more then one file */ if (bMultipleSource) ConOutPrintf(_T("%s\n"), szSrcPath); ConOutFormatMessage(GetLastError(), szSrcPath); freep(arg); nErrorLevel = 1; return 1; } /* Strip the paths back to the folder they are in */ for (i = (_tcslen(szSrcPath) - 1); i > -1; i--) if (szSrcPath[i] != _T('\\')) szSrcPath[i] = _T('\0'); else break; do { /* Check Breaker */ if (CheckCtrlBreak(BREAK_INPUT)) { FindClose(hFile); freep(arg); return 1; } /* Set the override to yes each new file */ nOverwrite = 1; /* Ignore the . and .. files */ if (!_tcscmp(findBuffer.cFileName, _T(".")) || !_tcscmp(findBuffer.cFileName, _T("..")) || findBuffer.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { continue; } /* Copy the base folder over to a tmp string */ _tcscpy(tmpDestPath, szDestPath); _tcscat(tmpDestPath, _T("\\")); /* Can't put a file into a folder that isn't there */ if (_tcscmp(tmpDestPath, _T("\\\\.\\")) && !IsExistingDirectory(tmpDestPath)) { FindClose(hFile); ConOutFormatMessage(GetLastError(), szSrcPath); freep(arg); nErrorLevel = 1; return 1; } /* Copy over the destination path name */ if (bSrcName) _tcscat(tmpDestPath, findBuffer.cFileName); else { /* If there is no wildcard you can use the name the user entered */ if ((_tcschr(UseThisName, _T('*')) == NULL) && (_tcschr(UseThisName, _T('?')) == NULL)) { _tcscat(tmpDestPath, UseThisName); } else { TCHAR DoneFile[MAX_PATH]; BuildFileName(findBuffer.cFileName, UseThisName, DoneFile); /* Add the filename to the tmp string path */ _tcscat(tmpDestPath, DoneFile); } } /* Build the string path to the source file */ _tcscpy(tmpSrcPath,szSrcPath); _tcscat (tmpSrcPath, findBuffer.cFileName); /* Check to see if the file is the same file */ if (!bTouch && !_tcscmp(tmpSrcPath, tmpDestPath)) { ConOutResPrintf(STRING_COPY_ERROR2); nErrorLevel = 1; break; } /* only print source name when more then one file */ if (bMultipleSource) ConOutPrintf(_T("%s\n"), tmpSrcPath); /* Handle any overriding / prompting that needs to be done */ if (((!(dwFlags & COPY_NO_PROMPT) && IsExistingFile (tmpDestPath)) || dwFlags & COPY_PROMPT) && !bTouch) nOverwrite = CopyOverwrite(tmpDestPath); if (nOverwrite == PROMPT_NO || nOverwrite == PROMPT_BREAK) continue; if (nOverwrite == PROMPT_ALL || (nOverwrite == PROMPT_YES && bAppend)) dwFlags |= COPY_NO_PROMPT; /* Tell weather the copy was successful or not */ if (copy(tmpSrcPath,tmpDestPath, bAppend, dwFlags, bTouch)) { nFiles++; //LoadString(CMD_ModuleHandle, STRING_MOVE_ERROR1, szMsg, RC_STRING_MAX_SIZE); } else { /* print out the error message */ ConOutResPrintf(STRING_COPY_ERROR3); ConOutFormatMessage (GetLastError(), szSrcPath); nErrorLevel = 1; } /* Loop through all wildcard files */ } while (FindNextFile(hFile, &findBuffer)); /* Loop through all files in src string with a + */ } while(!bDone); /* print out the number of files copied */ ConOutResPrintf(STRING_COPY_FILE, bAppend ? 1 : nFiles); if (hFile) FindClose(hFile); if (arg != NULL) freep(arg); return 0; }