Ejemplo n.º 1
0
// Convert string from ANSI code page to UTF-8
int ansiStringToUtf8(const char *ansiString, int ansiStringLength, char *utf8String)
{
	int wideCharStringLen = ansiStringToWideChar(ansiString, ansiStringLength, NULL);
	wchar_t wideCharString[wideCharStringLen];

	ansiStringToWideChar(ansiString, ansiStringLength, wideCharString);

	int multiByteStringLen = wideCharStringToUtf8(wideCharString, wideCharStringLen, NULL);

	if (utf8String)
		wideCharStringToUtf8(wideCharString, wideCharStringLen, utf8String);

	return multiByteStringLen;
}
std::string CDirectorySearch::GetFileName()
{
    std::string sBuffer;

#if defined(__WIN32)
    int len = wideCharStringToUtf8(m_fdData.name, -1, NULL);
    char fileName[len];

    wideCharStringToUtf8(m_fdData.name, -1, fileName);

    sBuffer = fileName;
#else
    sBuffer = m_fdData.name;
#endif

    return sBuffer;
}
std::string CDirectorySearch::GetFilePath()
{   // begin GetFilePath
    std::string sBuffer = m_sDirectory;

    if(sBuffer[sBuffer.length()-1] != DIRECTORY_DELIMITOR && m_fdData.name[0] != DIRECTORY_DELIMITOR)
        sBuffer += DIRECTORY_DELIMITOR;

#if defined(__WIN32)
    int len = wideCharStringToUtf8(m_fdData.name, -1, NULL);
    char filePath[len];

    wideCharStringToUtf8(m_fdData.name, -1, filePath);

    sBuffer += filePath;
#else
    sBuffer += m_fdData.name;
#endif

    return sBuffer;
}// end GetFilePath
std::string CDirectorySearch::GetExtension()
{   // begin GetExtension
#if defined(__WIN32)
    int len = wideCharStringToUtf8(m_fdData.name, -1, NULL);
    char filePath[len];

    wideCharStringToUtf8(m_fdData.name, -1, filePath);
#else
    char *filePath = m_fdData.name;
#endif

    std::string sBuffer;

    for (int i = strlen(filePath) - 1; i >= 0; i--)
    {
        if (filePath[i] == '.')
            sBuffer = &filePath[i + 1];
    }

    return sBuffer;
}// end GetExtension
Ejemplo n.º 5
0
 char *ADM_getInstallRelativePath(const char *base1, const char *base2, const char *base3)
 {

 	wchar_t wcModuleName[MAX_PATH];

 	GetModuleFileNameW(0, wcModuleName, sizeof(wcModuleName) / sizeof(wchar_t));

 	int len = wideCharStringToUtf8(wcModuleName, -1, NULL);
 	char *moduleName = new char[len];

 	wideCharStringToUtf8(wcModuleName, -1, moduleName);

 	char *slash = strrchr(moduleName, '\\');

 	if (slash)
 		*slash = '\0';

 	char *relativePath = ADM_getRelativePath(moduleName, base1, base2, base3);

 	delete [] moduleName;

 	return relativePath;
 }
Ejemplo n.º 6
0
/**
 *  \fn buildDirectoryContent
 * 	\brief Returns the content of a dir with the extension ext. The receiving array must be allocated by caller
 * (just the array, not the names themselves)
 */
uint8_t buildDirectoryContent(uint32_t *outnb, const char *base, char *jobName[], int maxElems, const char *ext)
{
	DIR *dir;
	struct dirent *direntry;
	int dirmax = 0, len;
	int extlen = strlen(ext);

	ADM_assert(extlen);

#ifdef __WIN32
	int dirNameLength = utf8StringToWideChar(base, -1, NULL);
	wchar_t base2[dirNameLength];

	utf8StringToWideChar(base, -1, base2);
#else
	const char *base2 = base;
#endif

	dir = opendir(base2);
	if (!dir)
		return 0;

	while (direntry = readdir(dir))
	{
#ifdef __WIN32
		int dirLength = wideCharStringToUtf8(direntry->d_name, -1, NULL);
		char d_name[dirLength];

		wideCharStringToUtf8(direntry->d_name, -1, d_name);
#else
		const char *d_name = direntry->d_name;
#endif

		len = strlen(d_name);

		if (len < (extlen + 1))
			continue;

		int xbase = len - extlen;

		if (memcmp(d_name + xbase, ext, extlen))
			//if (direntry->d_name[len-1]!='s' || direntry->d_name[len-2]!='j' || direntry->d_name[len-3]!='.')
		{
			printf("ignored: %s\n", d_name);
			continue;
		}

		jobName[dirmax] = (char *)ADM_alloc(strlen(base) + strlen(d_name) + 2);
		strcpy(jobName[dirmax], base);
		strcat(jobName[dirmax], "/");
		strcat(jobName[dirmax], d_name);
		dirmax++;

		if (dirmax >= maxElems)
		{
			printf("[jobs]: Max # of jobs exceeded\n");
			break;
		}
	}

	closedir(dir);
	*outnb = dirmax;

	return 1;
}
Ejemplo n.º 7
0
/*
      Get the root directory for .avidemux stuff
******************************************************/
char *ADM_getBaseDir(void)
{
	char *home;

	if (baseDirDone)
		return ADM_basedir;

	// Get the base directory
#ifdef __WIN32
	wchar_t wcHome[MAX_PATH];

	if (SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, wcHome) == S_OK)
	{
		int len = wideCharStringToUtf8(wcHome, -1, NULL);
		home = new char[len];

		wideCharStringToUtf8(wcHome, -1, home);
	}
	else
	{
		printf("Oops: can't determine the Application Data folder.");
		home = ADM_strdup("c:\\");
	}
#else
	const char* homeEnv = getenv("HOME");

	if (homeEnv)
	{
		home = new char[strlen(homeEnv) + 1];
		strcpy(home, homeEnv);
	}
	else
	{
		printf("Oops: can't determine $HOME.");

		return NULL;
	}
#endif

	// Try to open the .avidemux directory
	char *dirname = new char[strlen(home) + strlen(ADM_DIR_NAME) + 2];
	strcpy(dirname, home);
	strcat(dirname, ADM_DIR_NAME);

	if (!ADM_mkdir(dirname))
	{
		printf("Oops: cannot create the .avidemux directory", NULL);
		delete [] dirname;
		return NULL;
	}

	delete [] dirname;

	// Now built the filename
	strncpy(ADM_basedir,home, 1023);
	strncat(ADM_basedir, ADM_DIR_NAME, 1023 - strlen(ADM_basedir));
	baseDirDone = 1;
	printf("Using %s as base directory for prefs/jobs/...\n", ADM_basedir);

	return ADM_basedir;
}