Esempio n. 1
0
unsigned char* FileSystem::LoadFileContents(std::string filename, bool path_is_absolute) {
	
	std::string filepath = filename;
	if (!path_is_absolute) {
		filepath = getFullFilePath(filename);
	}

	std::ifstream file;
	file.open(filepath, std::ios::in);
	unsigned long len = getFileLength(file);

	unsigned char* shaderSrc = (unsigned char*) new char[len+1];
	shaderSrc[len] = 0;  // len isn't always strlen cause some characters are stripped in ascii read...
	// it is important to 0-terminate the real length later, len is just max possible value...

	unsigned int i=0;
	while (file.good())
	{
		shaderSrc[i++] = file.get();       // get character from file
		if (i>len) i=len;				   // coding guidelines...
	}

	shaderSrc[i] = 0;  // 0 terminate it.
	file.close();

	return shaderSrc;
}
Esempio n. 2
0
veFileData* veFileAndroid::readFileToBuffer(const std::string &filePath) {
    if (!veFileAndroid::ASSET_MANAGER)
        return nullptr;
    std::string fullPath = getFullFilePath(filePath);
    if (!isFileExist(fullPath))
        return nullptr;
    auto fileIter = _fileDataCache.find(fullPath);
    if (fileIter != _fileDataCache.end())
        return fileIter->second;

    const char* str = fullPath.c_str() + strlen("assets/");
    AAsset* asset = AAssetManager_open(veFileAndroid::ASSET_MANAGER, str, AASSET_MODE_UNKNOWN);
    if (asset) {
        off_t fileSize = AAsset_getLength(asset);
        char *buffer = new char[fileSize + 1];
        buffer[fileSize] = '\0';
        int bytesread = AAsset_read(asset, (void*)buffer, fileSize);
        auto fileData = new veFileData();
        fileData->buffer = buffer;
        fileData->size = fileSize + 1;
        //veLog("filebuffer: %s, size: %d", buffer, fileSize);
        _fileDataCache[fullPath] = fileData;
        AAsset_close(asset);
        return fileData;
    }
    return nullptr;
}
Esempio n. 3
0
   INT32 dpsArchiveFileMgr::deleteFilesByTime( UINT32 minFileId,
                                               UINT32 maxFileId,
                                               time_t time )
   {
      INT32 rc = SDB_OK ;

      for ( UINT32 fileId = minFileId ; fileId <= maxFileId ; fileId++ )
      {
         BOOLEAN continued = FALSE ;
         string movedPath = getMovedFilePath( fileId ) ;
         string partialPath = getPartialFilePath( fileId ) ;
         string fullPath = getFullFilePath( fileId ) ;

         rc = _deleteFileByTime( movedPath, time, continued ) ;
         if ( SDB_OK != rc )
         {
            PD_LOG( PDERROR, "Failed to delete file[%s] if expired, rc=%d",
                    movedPath.c_str(), rc ) ;
            goto error ;
         }

         if ( !continued )
         {
            break ;
         }

         rc = _deleteFileByTime( partialPath, time, continued ) ;
         if ( SDB_OK != rc )
         {
            PD_LOG( PDERROR, "Failed to delete file[%s] if expired, rc=%d",
                    partialPath.c_str(), rc ) ;
            goto error ;
         }

         if ( !continued )
         {
            break ;
         }

         rc = _deleteFileByTime( fullPath, time, continued ) ;
         if ( SDB_OK != rc )
         {
            PD_LOG( PDERROR, "Failed to delete file[%s] if expired, rc=%d",
                    fullPath.c_str(), rc ) ;
            goto error ;
         }

         if ( !continued )
         {
            break ;
         }
      }

   done:
      return rc ;
   error:
      goto done ;
   }
Esempio n. 4
0
   INT32 dpsArchiveFileMgr::deleteFilesBySize( UINT32 minFileId,
                                               UINT32 maxFileId,
                                               INT64 deletedSize )
   {
      INT32 rc = SDB_OK ;

      for ( UINT32 fileId = minFileId ; fileId <= maxFileId ; fileId++ )
      {
         INT64 fileSize = 0 ;
         string movedPath = getMovedFilePath( fileId ) ;
         string partialPath = getPartialFilePath( fileId ) ;
         string fullPath = getFullFilePath( fileId ) ;

         rc = _deleteFileBySize( movedPath, fileSize ) ;
         if ( SDB_OK != rc )
         {
            PD_LOG( PDERROR, "Failed to delete file[%s] if expired, rc=%d",
                    movedPath.c_str(), rc ) ;
            goto error ;
         }

         deletedSize -= fileSize ;

         rc = _deleteFileBySize( partialPath, fileSize ) ;
         if ( SDB_OK != rc )
         {
            PD_LOG( PDERROR, "Failed to delete file[%s] if expired, rc=%d",
                    partialPath.c_str(), rc ) ;
            goto error ;
         }

         deletedSize -= fileSize ;

         rc = _deleteFileBySize( fullPath, fileSize ) ;
         if ( SDB_OK != rc )
         {
            PD_LOG( PDERROR, "Failed to delete file[%s] if expired, rc=%d",
                    fullPath.c_str(), rc ) ;
            goto error ;
         }

         deletedSize -= fileSize ;

         if ( deletedSize <= 0 )
         {
            break ;
         }
      }

   done:
      return rc ;
   error:
      goto done ;
   }
Esempio n. 5
0
File: file.c Progetto: inilabs/caer
static bool caerOutputFileInit(caerModuleData moduleData) {
	// First, always create all needed setting nodes, set their default values
	// and add their listeners.
	char *userHomeDir = getUserHomeDirectory(moduleData);
	if (userHomeDir == NULL) {
		// caerModuleLog() called inside getUserHomeDirectory().
		return (false);
	}

	sshsNodeCreateString(moduleData->moduleNode, "directory", userHomeDir, 1, (PATH_MAX - MAX_PREFIX_LENGTH),
		SSHS_FLAGS_NORMAL, "Directory to write output data files in.");
	free(userHomeDir);

	// Support file-chooser in GUI, select any directory.
	sshsNodeCreateAttributeFileChooser(moduleData->moduleNode, "directory", "DIRECTORY");

	sshsNodeCreateString(moduleData->moduleNode, "prefix", DEFAULT_PREFIX, 1, MAX_PREFIX_LENGTH, SSHS_FLAGS_NORMAL,
		"Output data files name prefix.");

	// Generate current file name and open it.
	char *directory = sshsNodeGetString(moduleData->moduleNode, "directory");
	char *prefix    = sshsNodeGetString(moduleData->moduleNode, "prefix");

	char *filePath = getFullFilePath(moduleData, directory, prefix);
	free(directory);
	free(prefix);

	if (filePath == NULL) {
		// caerModuleLog() called inside getFullFilePath().
		return (false);
	}

	int fileFd = open(filePath, O_WRONLY | O_CREAT, S_IWUSR | S_IRUSR | S_IRGRP);
	if (fileFd < 0) {
		caerModuleLog(moduleData, CAER_LOG_CRITICAL,
			"Could not create or open output file '%s' for writing. Error: %d.", filePath, errno);
		free(filePath);

		return (false);
	}

	caerModuleLog(moduleData, CAER_LOG_INFO, "Opened output file '%s' successfully for writing.", filePath);
	free(filePath);

	if (!caerOutputCommonInit(moduleData, fileFd, NULL)) {
		close(fileFd);

		return (false);
	}

	return (true);
}
Esempio n. 6
0
std::string repo::core::RepoLogger::getFilename(
        const std::string &extension)
{
    std::stringstream fileNameStream;
    time_t t = time(0);
    const struct tm *now = localtime(&t);
    fileNameStream << (now->tm_year + 1900);
    fileNameStream << "-";
    fileNameStream << normalize(now->tm_mon + 1);
    fileNameStream << "-";
    fileNameStream << normalize(now->tm_mday);
    fileNameStream << extension;

    std::string generated = fileNameStream.str();
    if (generated != filename)
    {
        filename = generated;
        log("Log: " + getFullFilePath(),
            RepoSeverity::REPO_NOTICE);
    }
    return filename;
}
Esempio n. 7
0
void repo::core::RepoLogger::log(
        const std::string &msg,
        const RepoSeverity &severity)
{
    std::string filename = getFilename();
    std::string formattedMessage = getHtmlFormattedMessage(msg, severity);

    notifyListeners(formattedMessage);

    std::ofstream file(filename, std::ios::app);
    if (!file.is_open())
    {
        notifyListeners(
                    getHtmlFormattedMessage(
                        "Cannot write to log file: " + getFullFilePath(),
                        RepoSeverity::REPO_CRITICAL));
    }
    else
    {
        file << formattedMessage << std::endl;
        file.close();
    }
}
Esempio n. 8
0
   INT32 dpsArchiveFileMgr::deleteArchiveFile( UINT32 fileId )
   {
      INT32 rc = SDB_OK ;

      string partialPath = getPartialFilePath( fileId ) ;
      string fullPath = getFullFilePath( fileId ) ;

      rc = deleteFile( partialPath ) ;
      if ( SDB_OK != rc )
      {
         goto error ;
      }

      rc = deleteFile( fullPath ) ;
      if ( SDB_OK != rc )
      {
         goto error ;
      }

   done:
      return rc ;
   error:
      goto done ;
   }
BOOL CALLBACK VerticalFileSwitcher::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case WM_INITDIALOG :
        {
			_fileListView.init(_hInst, _hSelf, _hImaLst);
			_fileListView.insertColumn(TEXT("Name"), 150, 0);
			_fileListView.insertColumn(TEXT("Ext."), 50, 1);
			_fileListView.initList();
			_fileListView.display();

            return TRUE;
        }

		case WM_NOTIFY:
		{
			switch (((LPNMHDR)lParam)->code)
			{
				case NM_DBLCLK:
				{
					LPNMITEMACTIVATE lpnmitem = (LPNMITEMACTIVATE) lParam;
					int i = lpnmitem->iItem;
					if (i == -1)
					{
						::SendMessage(_hParent, WM_COMMAND, IDM_FILE_NEW, 0);
					}
					return TRUE;
				}

				case NM_CLICK:
				{
					if ((0x80 & GetKeyState(VK_CONTROL)) || (0x80 & GetKeyState(VK_SHIFT)))
						return TRUE;

					LPNMITEMACTIVATE lpnmitem = (LPNMITEMACTIVATE) lParam;
					int nbItem = ListView_GetItemCount(_fileListView.getHSelf());
					int i = lpnmitem->iItem;
					if (i == -1 || i >= nbItem)
						return TRUE;

					LVITEM item;
					item.mask = LVIF_PARAM;
					item.iItem = i;	
					ListView_GetItem(((LPNMHDR)lParam)->hwndFrom, &item);
					TaskLstFnStatus *tlfs = (TaskLstFnStatus *)item.lParam;

					activateDoc(tlfs);
					return TRUE;
				}

				case NM_RCLICK :
				{
					// Switch to the right document
					LPNMITEMACTIVATE lpnmitem = (LPNMITEMACTIVATE) lParam;
					int nbItem = ListView_GetItemCount(_fileListView.getHSelf());

					if (nbItem == 1)
					{
						int i = lpnmitem->iItem;
						if (i == -1 || i >= nbItem)
 							return TRUE;

						LVITEM item;
						item.mask = LVIF_PARAM;
						item.iItem = i;	
						ListView_GetItem(((LPNMHDR)lParam)->hwndFrom, &item);
						TaskLstFnStatus *tlfs = (TaskLstFnStatus *)item.lParam;

						activateDoc(tlfs);
					}
					// Redirect NM_RCLICK message to Notepad_plus handle
					NMHDR	nmhdr;
					nmhdr.code = NM_RCLICK;
					nmhdr.hwndFrom = _hSelf;
					nmhdr.idFrom = ::GetDlgCtrlID(nmhdr.hwndFrom);
					::SendMessage(_hParent, WM_NOTIFY, nmhdr.idFrom, (LPARAM)&nmhdr);
					return TRUE;
				}

				case LVN_GETINFOTIP:
				{
					LPNMLVGETINFOTIP pGetInfoTip = (LPNMLVGETINFOTIP)lParam;
					int i = pGetInfoTip->iItem;
					if (i == -1)
						return TRUE;
					generic_string fn = getFullFilePath((size_t)i);
					lstrcpyn(pGetInfoTip->pszText, fn.c_str(), pGetInfoTip->cchTextMax);
					return TRUE;
				}

				case LVN_COLUMNCLICK:
				{
					LPNMLISTVIEW pnmLV = (LPNMLISTVIEW)lParam;
					setHeaderOrder(pnmLV);
					ListView_SortItemsEx(pnmLV->hdr.hwndFrom, ListViewCompareProc,(LPARAM)pnmLV);
					return TRUE;
				}
				case LVN_KEYDOWN:
				{
					switch (((LPNMLVKEYDOWN)lParam)->wVKey)
					{
						case VK_RETURN:
						{
							int i = ListView_GetSelectionMark(_fileListView.getHSelf());
							if (i == -1)
								return TRUE;

							LVITEM item;
							item.mask = LVIF_PARAM;
							item.iItem = i;	
							ListView_GetItem(((LPNMHDR)lParam)->hwndFrom, &item);
							TaskLstFnStatus *tlfs = (TaskLstFnStatus *)item.lParam;
							activateDoc(tlfs);
							return TRUE;
						}
						default:
							break;
					}
				}
				break;

				default:
					break;
			}
		}
		return TRUE;

        case WM_SIZE:
        {
            int width = LOWORD(lParam);
            int height = HIWORD(lParam);
			::MoveWindow(_fileListView.getHSelf(), 0, 0, width, height, TRUE);
            break;
        }
        
		case WM_DESTROY:
        {
			_fileListView.destroy();
            break;
        }

        default :
            return DockingDlgInterface::run_dlgProc(message, wParam, lParam);
    }
	return DockingDlgInterface::run_dlgProc(message, wParam, lParam);
}
Esempio n. 10
0
std::string FileSystem::GetResourceFilePath(std::string resource_file) {
	return getFullFilePath(resource_file);			
}
Esempio n. 11
0
   INT32 dpsArchiveFileMgr::moveArchiveFile( UINT32 fileId, BOOLEAN forward )
   {
      INT32 rc = SDB_OK ;
      BOOLEAN existFull = FALSE ;
      BOOLEAN existPartial = FALSE ;
      BOOLEAN existMoved = FALSE ;
      string partialPath = getPartialFilePath( fileId ) ;
      string fullPath = getFullFilePath( fileId ) ;
      string movedPath = getMovedFilePath( fileId ) ;

      rc = ossFile::exists( fullPath, existFull ) ;
      if ( SDB_OK != rc )
      {
         PD_LOG( PDERROR, "Failed to check if file[%s] exists, rc=%d",
                          fullPath.c_str() , rc ) ;
         goto error ;
      }

      rc = ossFile::exists( partialPath, existPartial ) ;
      if ( SDB_OK != rc )
      {
         PD_LOG( PDERROR, "Failed to check if file[%s] exists, rc=%d",
                          partialPath.c_str() , rc ) ;
         goto error ;
      }

      rc = ossFile::exists( movedPath, existMoved ) ;
      if ( SDB_OK != rc )
      {
         PD_LOG( PDERROR, "Failed to check if file[%s] exists, rc=%d",
                          movedPath.c_str() , rc ) ;
         goto error ;
      }

      if ( existMoved && (!forward || existFull || existPartial ) )
      {
         rc = ossFile::deleteFile( movedPath ) ;
         if ( SDB_OK != rc )
         {
            PD_LOG( PDERROR, "Failed to delete file[%s], rc=%d",
                    movedPath.c_str() , rc ) ;
            goto error ;
         }
      }

      if ( existFull )
      {
         rc = ossFile::rename( fullPath, movedPath ) ;
         if ( SDB_OK != rc )
         {
            PD_LOG( PDERROR, "Failed to rename file[%s] to [%s], rc=%d",
                    fullPath.c_str(), movedPath.c_str() , rc ) ;
            goto error ;
         }

         PD_LOG( PDEVENT, "Move archive file[%s]", fullPath.c_str() ) ;

         if ( existPartial )
         {
            rc = ossFile::deleteFile( partialPath ) ;
            if ( SDB_OK != rc )
            {
               PD_LOG( PDERROR, "Failed to delete file[%s], rc=%d",
                       partialPath.c_str() , rc ) ;
               goto error ;
            }
         }
      }
      else if ( existPartial )
      {
         rc = ossFile::rename( partialPath, movedPath ) ;
         if ( SDB_OK != rc )
         {
            PD_LOG( PDERROR, "Failed to rename file[%s] to [%s], rc=%d",
                    partialPath.c_str(), movedPath.c_str() , rc ) ;
            goto error ;
         }

         PD_LOG( PDEVENT, "Move archive file[%s]", partialPath.c_str() ) ;
      }

   done:
      return rc ;
   error:
      goto done ;
   }
Esempio n. 12
0
 INT32 dpsArchiveFileMgr::fullFileExists( UINT32 logicalFileId,
                                          BOOLEAN& exist )
 {
    string path = getFullFilePath( logicalFileId ) ;
    return ossFile::exists( path, exist ) ;
 }