void DBIO_SaveAllToFile( VDinfoP *VDptrs, long count, char *filename ) { long i, ret; VDinfoP VD; if ( VDptrs && filename ){ char dbpath[512]; char dbname[512]; PathFromFullPath( filename, dbpath ); // only attach a .fdb if the file hasnt got a .fdb if ( strstr( filename, ".fdb" ) ) sprintf( dbname , FileFromPath( filename, 0 ) ); else sprintf( dbname , "%s.fdb", FileFromPath( filename, 0 ) ); strcat( dbpath , dbname ); for( i=0; i<=count; i++){ VD = VDptrs[i]; ret = DBIO_SaveVhost( VD, dbpath, TRUE ); } DBIO_SaveClose( ret ); } }
short SaveLangFileAs( char *filename ) { char fileWithPath[1024]; // Check the exe directory first - as this is where users should have their lang directory GetLangV41File( fileWithPath, gPath, PATHSEPSTR, 0 ); if ( ValidatePath( fileWithPath ) ) { // Now check for a lang directory which is located back a directory - this where we have our lang directory GetLangV41File( fileWithPath, gPath, PATHBACKDIR, 0 ); } if ( ValidatePath( fileWithPath ) ) { // Try the current directory - basically, a last resort... GetLangV41File( fileWithPath, 0, 0, 0 ); } if ( GetLangSaveFolderName( fileWithPath, filename ) ) { ReadNewLangStringsFromLangList(); char *pos; pos = strstri( fileWithPath, LANG_EXT ); if ( !pos ) mystrcat( fileWithPath, LANG_EXT ); if ( SaveNewLangStringsToLangFile( fileWithPath ) ) { FileFromPath( fileWithPath, MyPrefStruct.language ); strcpyuntil( MyPrefStruct.language, MyPrefStruct.language, '.' ); return 1; } } return 0; }
short SaveNewLangStringsToLangFile( char *filename ) { FILE *fp; fp = CreateNewLang( filename ); fp = fopen( filename, "wb" ); if ( !fp ) { MessageBox( GetFocus(), "Unable to save language file!", "File Save Error!", MB_OK|MB_ICONERROR ); return 0; } char szFile[256], *p; FileFromPath( filename, szFile ); p = strstr( szFile, "." ); if ( p ) *p = 0; time_t jd; char dateStr[64]; TimeStringToDays( "now", &jd ); CTimeToDateTimeStr( jd, dateStr ); fprintf( fp, "// A couple of lines for top of lang file\n// %s File\n// Date %s\n\n", szFile, dateStr ); for( int i = SUMM_BEGIN; i < END_OF_STRINGS; i++ ) { WriteNewLangString( fp, i ); ClearNewLangString( i ); } fclose( fp ); return 1; }
void DBIO_SaveToFile( VDinfoP VDptr, char *filename ) { long ret; if ( VDptr && filename ){ char dbpath[512]; char dbname[512]; PathFromFullPath( filename, dbpath ); // only attach a .fdb if the file hasnt got a .fdb if ( strstr( filename, ".fdb" ) ) sprintf( dbname , FileFromPath( filename, 0 ) ); else sprintf( dbname , "%s.fdb", FileFromPath( filename, 0 ) ); strcat( dbpath , dbname ); ret = DBIO_SaveVhost( VDptr, dbpath, 0 ); DBIO_SaveClose( ret ); } }
// ---------------------------------- Init / Close options for lists void CorrectVirtualName( char *name, char *vname, char nameisfile ) { long i; if ( nameisfile ){ mystrcpylower( vname, FileFromPath( name, NULL ) ); } else if ( *name ){ #if _SUNOS CopyDomainName_Safely( vname, name ); #else CopyDomainName( vname, name ); #endif } else i = mystrcpylower( vname, ErrVhostStr ); }
// ShowProgress( 0, TRUE, buf2 ); // archive the report into ONE big ZIP file void PostProc_ZipReport( char *reportLocation, char *zipfilename, int deletereport ) { if ( gFopenHistoryPtr ){ char newfilename[256]; char sourcepath[256], msg[128]; long count=0,filenum,perc = 0; LLStructRecPtr next = gFopenHistoryPtr; filenum = LListGetTotal( gFopenHistoryPtr ); PathFromFullPath( reportLocation, sourcepath ); DateFixFilename( sourcepath, 0 ); if ( !strstr( reportLocation, ".zip" ) ) { char *p; mystrcpy( newfilename, reportLocation ); DateFixFilename( newfilename, 0 ); p = strrchr( newfilename, '.' ); if ( p ) mystrcpy( p, ".zip" ); else return; mystrcpy( zipfilename, newfilename ); sprintf( msg, "Making ZIP %s", newfilename ); ShowProgress( perc, FALSE, msg ); } #ifdef _zip_H { zipFile zipData; char *source; zipData = zipOpen( (const char *)newfilename, 0 ); while( next && !IsStopped() ) { perc = ((count*100)/filenum); source = (char*)next->data; sprintf( msg, "Adding to zip file %s", FileFromPath( source,0 ) ); ShowProgress( perc, FALSE, msg ); long infilelen = GetFileLength( source ); char *ram = (char*)malloc( infilelen+1 ); if ( ram ) { zip_fileinfo zinfo; memset( &zinfo, 0, sizeof(zip_fileinfo) ); FileToMem( source, ram, infilelen ); zipOpenNewFileInZip( zipData, source, &zinfo, 0, 0, 0, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION ); zipWriteInFileInZip( zipData, ram , infilelen ); zipCloseFileInZip( zipData ); free( ram ); } if( deletereport ) remove( source ); next = next->next; count++; } zipClose( zipData, NULL ); } #endif #if DEF_WINZIP { ZCL zipData; char *source; memset( &zipData, 0, sizeof(ZCL) ); zipData.Stdout = stdout; zipData.fQuiet = TRUE; zipData.fUpdate = TRUE; zipData.lpszZipFN = newfilename; //"C:\install\test.zip"; zipData.fLevel = 1; zipData.FNV = &source; zipData.argc = 1; while( next && !IsStopped() ){ perc = ((count*100)/filenum); source = (char*)next->data; sprintf( msg, "Adding to zip file %s", FileFromPath( source,0 ) ); ShowProgress( perc, FALSE, msg ); ZipUpFiles( &zipData ); if( deletereport ) remove( source ); next = next->next; count++; } } #endif } }
int PreProc_FtpDownloadFiles( char *downloadURL, char *tempLocation, int deleteFiles ) { if ( IsURL( downloadURL ) && !IsStopped() ) { char *p; long count=0, filenum; char server[128], path[256], name[64], passwd[32]; #if DEF_WINDOWS WIN32_FIND_DATA lpFindFileData; HINTERNET hFind, fs; char msg[256]; ExtractUserFromURL( downloadURL, server, name, passwd, path ); DateFixFilename( path, 0 ); OutDebugs( "Doing PreProcess Download %s...", path ); fs = (void*)FtpServerOpen( server, name, passwd ); if ( !fs ) { FtpServerOpenError( server ); return -1; } if ( fs ) { long flags = INTERNET_FLAG_NO_CACHE_WRITE; char newpath[512]; // ***************************************************************** // To be more friendly with various FTP servers, we need to break // up the filename from the directory that it is contained in. // We can then change to the directory prior to fetching the file. // The issue here is that some FTP servers can not get a file that // has path information in it (ie: /directory1/dir2/file.dat) // ***************************************************************** int iLen; for (iLen=mystrlen(path);iLen && path[iLen]!='/';--iLen) ; if (!iLen) // then there is no '/' { mystrcpy( newpath, path+1 ); } else { path[iLen] = NULL; // Set the '/' to a NULL so we have a path up to the name. if (!::FtpSetCurrentDirectory(fs,"/")) // Set it to root just to be sure. { // we have a problem, however there is no real way to action this. // so lets just hope that the fetch will still work. } if (!::FtpSetCurrentDirectory(fs,path)) { // again. // we have a problem, however there is no real way to action this. // so lets just hope that the fetch will still work. path[iLen] = '/'; } mystrcpy( newpath, path+iLen+1 ); } hFind = FtpFindFirstFile( fs, newpath, &lpFindFileData, flags , 0 ); if ( !hFind ){ unsigned long len = 512; FtpServerClose( fs ); OutDebugs( "%s Not Found....Trying root level path instead...", newpath ); fs = (void*)FtpServerOpen( server, name, passwd ); if ( fs ) { FtpGetCurrentDirectory( fs, newpath, &len ); strcat( newpath, path ); hFind = FtpFindFirstFile( fs, newpath, &lpFindFileData, flags , 0 ); } else FtpServerOpenError( server ); } if ( hFind ) OutDebugs( "Ftp File Found %s size = %d", lpFindFileData.cFileName, lpFindFileData.nFileSizeLow ); else { ErrorMsg( "Cannot open ftp file ...\n%s\nBecause %s", newpath, NetworkErr(NULL) ); FtpServerClose( fs ); return -1; } filenum = 0; while( hFind && !IsStopped() ) { long ret; char ftpfilename[256], localfilename[256]; if( hFind ) { ftpfilename[0] = 0; if ( !strchr( lpFindFileData.cFileName , '/' ) ){ // only if NEWPATH has a / in it copy it. if ( strchr( newpath , '/' ) ){ mystrcpy( ftpfilename, newpath ); p = strrchr( ftpfilename, '/'); if ( p ) *p = 0; } strcat( ftpfilename, "/" ); strcat( ftpfilename, lpFindFileData.cFileName ); } else mystrcpy( ftpfilename, lpFindFileData.cFileName ); // Figure out local file name if ( *tempLocation == 0 || GetFileAttributes( tempLocation ) != FILE_ATTRIBUTE_DIRECTORY ) { sprintf( msg, "%%TEMP%%\\%s", FileFromPath( ftpfilename,NULL ) ); ExpandEnvironmentStrings( msg, localfilename, 255 ); StatusSetID( IDS_STOREFILEINTEMP ); OutDebugs( "Using system temp location %s", localfilename ); } else { PathFromFullPath( tempLocation, localfilename ); if( strlen( localfilename ) ) { strcat ( localfilename, "\\" ); p = FileFromPath( ftpfilename,NULL ); if ( !p ) p = "temp.log"; strcat ( localfilename, p ); } else mystrcpy( localfilename, "temp.log" ); OutDebugs( "Using user temp location %s", localfilename ); } OutDebugs( "Trying to download %d byte file '%s' into '%s' ...", lpFindFileData.nFileSizeLow, ftpfilename, localfilename ); ret = FtpFileDownload( fs, downloadURL, localfilename, ftpfilename, lpFindFileData.nFileSizeLow ); if ( ret > 0 ) { if ( deleteFiles ){ // delete remote ftp file after downloading StatusSetID( IDS_DELETEFTP, ftpfilename ); FtpDelFile( fs, ftpfilename ); } AddFileToLogQ( localfilename, filenum++ ); } else { OutDebugs( "error downloading (%d)", ret ); ErrorMsg( "Cannot download file %s\n%s", NetworkErr(NULL) ); hFind = NULL; FtpServerClose( fs ); return -2; } //------------------------ } //if( hFind ) if ( hFind ) { if( InternetFindNextFile( hFind, &lpFindFileData ) == FALSE ) hFind = NULL; } } //while FtpServerClose( fs ); } #endif } return IsStopped(); }
/******************************************************************** CabOperation - helper function that enumerates or extracts files from cabinet NOTE: wzCabinet must be full path to cabinet file wzExtractFile can be a single file id or "*" to extract all files wzExttractDir must be normalized (end in a "\") if pfnBeginFile is NULL pfnEndFile must be NULL and vice versa pfnNotify is callback function to get notified for each file in the cabinet. If it's NULL, files will be extracted. ********************************************************************/ static HRESULT DAPI CabOperation( __in LPCWSTR wzCabinet, __in LPCWSTR wzExtractFile, __in_opt LPCWSTR wzExtractDir, __in_opt CAB_CALLBACK_PROGRESS pfnProgress, __in_opt LPVOID pvContext, __in_opt STDCALL_PFNFDINOTIFY pfnNotify, __in DWORD64 dw64EmbeddedOffset ) { HRESULT hr = S_OK; BOOL fResult; LPWSTR sczCabinet = NULL; LPWSTR pwz = NULL; CHAR szCabDirectory[MAX_PATH * 4]; // Make sure these are big enough for UTF-8 strings CHAR szCabFile[MAX_PATH * 4]; CAB_CALLBACK_STRUCT ccs; PFNFDINOTIFY pfnFdiNotify; // // ensure the cabinet.dll is loaded // if (!vhfdi) { hr = LoadCabinetDll(); ExitOnFailure(hr, "failed to load CABINET.DLL"); } hr = StrAllocString(&sczCabinet, wzCabinet, 0); ExitOnFailure1(hr, "Failed to make copy of cabinet name:%ls", wzCabinet); // // split the cabinet full path into directory and filename and convert to multi-byte (ick!) // pwz = FileFromPath(sczCabinet); ExitOnNull1(pwz, hr, E_INVALIDARG, "failed to process cabinet path: %ls", wzCabinet); if (!::WideCharToMultiByte(CP_UTF8, 0, pwz, -1, szCabFile, countof(szCabFile), NULL, NULL)) { ExitWithLastError1(hr, "failed to convert cabinet filename to ASCII: %ls", pwz); } *pwz = '\0'; // If a full path was not provided, use the relative current directory. if (wzCabinet == pwz) { hr = ::StringCchCopyA(szCabDirectory, countof(szCabDirectory), ".\\"); ExitOnFailure(hr, "Failed to copy relative current directory as cabinet directory."); } else { if (!::WideCharToMultiByte(CP_UTF8, 0, sczCabinet, -1, szCabDirectory, countof(szCabDirectory), NULL, NULL)) { ExitWithLastError1(hr, "failed to convert cabinet directory to ASCII: %ls", sczCabinet); } } // // iterate through files in cabinet extracting them to the callback function // ccs.fStopExtracting = FALSE; ccs.pwzExtract = wzExtractFile; ccs.pwzExtractDir = wzExtractDir; ccs.pfnProgress = pfnProgress; ccs.pvContext = pvContext; vdw64EmbeddedOffset = dw64EmbeddedOffset; // if pfnNotify is given, use it, otherwise use default callback if (NULL == pfnNotify) { pfnFdiNotify = CabExtractCallback; } else { v_pfnNetFx11Notify = pfnNotify; pfnFdiNotify = FDINotify; } fResult = vpfnFDICopy(vhfdi, szCabFile, szCabDirectory, 0, pfnFdiNotify, NULL, static_cast<void*>(&ccs)); if (!fResult && !ccs.fStopExtracting) // if something went wrong and it wasn't us just stopping the extraction, then return a failure { ExitWithLastError1(hr, "failed to extract cabinet file: %ls", sczCabinet); } LExit: ReleaseStr(sczCabinet); v_pfnNetFx11Notify = NULL; return hr; }