Esempio n. 1
0
static bool Cmd_ConScribe_UnregisterLog_Execute(COMMAND_ARGS)
{
	UInt32 DefaultFlag = 0;
	UInt32 DeleteFlag = 0;
	char Buffer[kMaxMessageLength];
	const char* ModName = ResolveModName(scriptObj);

	if (Buffer == NULL || ModName == NULL)
		return true;
	else if (!ExtractFormatStringArgs(0, Buffer, paramInfo, arg1, opcodeOffsetPtr, scriptObj, eventList, kCommandInfo_UnregisterLog.numParams, &DefaultFlag, &DeleteFlag))
		return true;

	if (!_stricmp(Buffer, "*.*")) {
		if (!DefaultFlag) { 		
			_MESSAGE("Mod '%s' unregistered all of its logs", ModName);
			LogManager::GetSingleton()->GetModLogData(ModName)->RegisteredLogs.clear();
			DeleteFlag = 0;
		}
		LogManager::GetSingleton()->SetDefaultLog(ModName, (const char*)NULL);
	}
	else	
		LogManager::GetSingleton()->UnregisterLog(ModName, Buffer);

	if (DeleteFlag) {
		DeleteFile(std::string(std::string(GET_INI_STRING("RootDirectory")) + "ConScribe Logs\\Per-Mod\\" + std::string(Buffer) + ".log").c_str());
		_MESSAGE("Deleted '%s'", Buffer);
	}

	return true;
}
Esempio n. 2
0
static bool Cmd_ConScribe_ReadFromLog_Execute(COMMAND_ARGS)
{
	*result = 0;
	const char * ModName = ResolveModName(scriptObj);
	char Buffer[kMaxMessageLength];

	if (!ExtractFormatStringArgs(0, Buffer, paramInfo, arg1, opcodeOffsetPtr, scriptObj, eventList, kCommandInfo_ReadFromLog.numParams))
		return true;
	else if (Buffer == NULL || ModName == NULL)
		return true;

	std::string LogPath;
	std::vector<OBSEElement> LogContents;

	if (!_stricmp(Buffer, "*.*") && LogManager::GetSingleton()->GetDefaultLog(ModName))
		LogPath = std::string(GET_INI_STRING("RootDirectory")) + "ConScribe Logs\\Per-Mod\\" + std::string(LogManager::GetSingleton()->GetDefaultLog(ModName)) + ".log";
	else if (LogManager::GetSingleton()->IsLogRegistered(ModName, Buffer))
		LogPath = std::string(GET_INI_STRING("RootDirectory")) + "ConScribe Logs\\Per-Mod\\" + std::string(Buffer) + ".log";
	else		return true;
	LogContents.push_back(LogPath.c_str());

	ConScribeLog* TempLog = new ConScribeLog(LogPath.c_str(), ConScribeLog::e_In);
	std::vector<std::string> STLVector(TempLog->ReadAllLines());

	OBSEArray* ResultArray = ArrayFromStdVector(LogContents, scriptObj);

	for (std::vector<std::string>::const_iterator Itr = STLVector.begin(); Itr != STLVector.end(); Itr++) {
		if (Itr == STLVector.end() - 1 && Itr->begin() == Itr->end())		continue;		// skip empty last lines
		g_arrayIntfc->AppendElement(ResultArray, Itr->c_str());
	}

	if (!ResultArray)													_MESSAGE("Couldn't create array. Passed in script %08x", scriptObj->refID);
	else if (!g_arrayIntfc->AssignCommandResult(ResultArray, result))	_MESSAGE("Couldn't assign result array. Passed in script %08x", scriptObj->refID);

	return true;
}
Esempio n. 3
0
extern int IniFileRead(TCHAR *ass_type, ass_setting_t *as)
{
    int ret = -1;
	int alignCenter = 0;

    // Allocate string buffers.
    TCHAR *ini_file = new TCHAR[FILE_PATH_MAX];
    TCHAR *tmp_buff = new TCHAR[INI_STRING_MAX];
    WCHAR *utf8_str = new WCHAR[INI_STRING_MAX];
    if (!ini_file || !tmp_buff || !utf8_str)
        goto EXIT;
    // Initliaze string buffers.
    memset(ini_file, 0, sizeof(TCHAR) * FILE_PATH_MAX);
    memset(tmp_buff, 0, sizeof(TCHAR) * INI_STRING_MAX);
    memset(utf8_str, 0, sizeof(WCHAR) * INI_STRING_MAX);

    // Get the file path of ini file.
    if (GetPrivateProfilePath(ini_file))
        goto EXIT;
    // Open ini file.
    FILE *fp = NULL;
    if (_tfopen_s(&fp, ini_file, _T("r")) || !fp) {
        if (_tfopen_s(&fp, ini_file, _T("wb")) || !fp)
            goto EXIT;
#ifdef _UNICODE
		fwrite(utf16le_bom, 4, 1, fp);
#endif
        _ftprintf(fp, _T("%s"), _T(DEFAULT_INI));
    }
    fclose(fp);

    // Caption offset of SWF-Mode
    as->SWF0offset=GetPrivateProfileInt(_T("SWFModeOffset"), _T("SWF0offset"), 0, ini_file);
    as->SWF5offset=GetPrivateProfileInt(_T("SWFModeOffset"), _T("SWF5offset"), 0, ini_file);
    as->SWF7offset=GetPrivateProfileInt(_T("SWFModeOffset"), _T("SWF7offset"), 0, ini_file);
    as->SWF9offset=GetPrivateProfileInt(_T("SWFModeOffset"), _T("SWF9offset"), 0, ini_file);
    as->SWF11offset=GetPrivateProfileInt(_T("SWFModeOffset"), _T("SWF11offset"), 0, ini_file);

    // ass header infomation
#ifndef _UNICODE
#define GET_INI_STRING(sec, key, def, tmp, str, len, ini, get)      \
do {                                                                \
    GetPrivateProfileStringA(sec, key, def, tmp, len, ini);          \
    MultiByteToWideChar(932, 0, tmp, -1, str, len);                 \
    WideCharToMultiByte(CP_UTF8, 0, str, -1, get, len, NULL, NULL); \
} while (0)
#else //_UNICODE
#define GET_INI_STRING(sec, key, def, tmp, str, len, ini, get)      \
do {                                                                \
    GetPrivateProfileStringW(sec, key, def, str, len, ini);          \
    WideCharToMultiByte(CP_UTF8, 0, str, -1, get, len, NULL, NULL); \
} while (0)
#endif
#define GET_INI_VALUE(sec, key, def, ini, get)          \
do {                                                    \
    get = GetPrivateProfileInt(sec, key, def, ini);     \
} while (0)

    GET_INI_STRING(ass_type, _T("Comment1"), NULL, tmp_buff, utf8_str, INI_STRING_MAX, ini_file, as->Comment1);
    GET_INI_STRING(ass_type, _T("Comment2"), NULL, tmp_buff, utf8_str, INI_STRING_MAX, ini_file, as->Comment2);
    GET_INI_STRING(ass_type, _T("Comment3"), NULL, tmp_buff, utf8_str, INI_STRING_MAX, ini_file, as->Comment3);
    GET_INI_VALUE(ass_type, _T("PlayResX"), 1920, ini_file, as->PlayResX);
    GET_INI_VALUE(ass_type, _T("PlayResY"), 1080, ini_file, as->PlayResY);

    GET_INI_STRING(ass_type, _T("DefaultFontname"), _T("MS UI Gothic"), tmp_buff, utf8_str, INI_STRING_MAX, ini_file, as->DefaultFontname);
    GET_INI_VALUE(ass_type, _T("DefaultFontsize"), 90, ini_file, as->DefaultFontsize);
    GET_INI_STRING(ass_type, _T("DefaultStyle"), _T("&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,15,0,1,2,2,1,10,10,10,0")
                 , tmp_buff, utf8_str, INI_STRING_MAX, ini_file, as->DefaultStyle);

    GET_INI_STRING(ass_type, _T("BoxFontname"), _T("MS UI Gothic"), tmp_buff, utf8_str, INI_STRING_MAX, ini_file, as->BoxFontname);
    GET_INI_VALUE(ass_type, _T("BoxFontsize"), 90, ini_file, as->BoxFontsize);
    GET_INI_STRING(ass_type, _T("BoxStyle"), _T("&HFFFFFFFF,&H000000FF,&H00FFFFFF,&H00FFFFFF,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,0")
                 , tmp_buff, utf8_str, INI_STRING_MAX, ini_file, as->BoxStyle);

    GET_INI_STRING(ass_type, _T("RubiFontname"), _T("MS UI Gothic"), tmp_buff, utf8_str, INI_STRING_MAX, ini_file, as->RubiFontname);
    GET_INI_VALUE(ass_type, _T("RubiFontsize"), 50, ini_file, as->RubiFontsize);
    GET_INI_STRING(ass_type, _T("RubiStyle"), _T("&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,2,1,10,10,10,0")
                 , tmp_buff, utf8_str, INI_STRING_MAX, ini_file, as->RubiStyle);
	GET_INI_VALUE(ass_type, _T("AlignCenter"), 0, ini_file, alignCenter);
	if(alignCenter) as->aligncenter = true;

#undef GET_INI_STRING
#undef GET_INI_VALUE

    ret = 0;
EXIT:
    SAFE_DELETE_ARRAY(ini_file);
    SAFE_DELETE_ARRAY(tmp_buff);
    SAFE_DELETE_ARRAY(utf8_str);

    return ret;
}