// onLoaded( dic, is_async, is_error, error_mes ); エラーは // sync ( main thead ) void tTVPAsyncImageLoader::LoadRequest( iTJSDispatch2 *owner, tTJSNI_Bitmap* bmp, const ttstr &name ) { //tTVPBaseBitmap* dest = new tTVPBaseBitmap( 32, 32, 32 ); tTVPBaseBitmap dest( TVPGetInitialBitmap() ); iTJSDispatch2* metainfo = NULL; ttstr nname = TVPNormalizeStorageName(name); if( TVPCheckImageCache(nname,&dest,glmNormal,0,0,TVP_clNone,&metainfo) ) { // キャッシュ内に発見、即座に読込みを完了する bmp->CopyFrom( &dest ); bmp->SetLoading( false ); tTJSVariant param[4]; param[0] = tTJSVariant(metainfo,metainfo); if( metainfo ) metainfo->Release(); param[1] = 0; // false param[2] = 0; // false param[3] = TJS_W(""); // error_mes static ttstr eventname(TJS_W("onLoaded")); TVPPostEvent(owner, owner, eventname, 0, TVP_EPT_IMMEDIATE, 4, param); return; } if( TVPIsExistentStorage(name) == false ) { TVPThrowExceptionMessage(TVPCannotFindStorage, name); } ttstr ext = TVPExtractStorageExt(name); if(ext == TJS_W("")) { TVPThrowExceptionMessage(TJS_W("Filename extension not found/%1"), name); } PushLoadQueue( owner, bmp, nname ); }
//--------------------------------------------------------------------------- bool TVPSelectFile(iTJSDispatch2 *params) { // show open dialog box // NOTE: currently this only shows ANSI version of file open dialog. tTJSVariant val; char * filter = NULL; char * filename = NULL; AnsiString initialdir; AnsiString title; AnsiString defaultext; BOOL result; try { // prepare OPENFILENAME structure OPENFILENAME ofn; memset(&ofn, 0, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = TVPGetModalWindowOwnerHandle(); ofn.hInstance = NULL; // set application window position to current window position // get filter ofn.lpstrFilter = NULL; if(TJS_SUCCEEDED(params->PropGet(TJS_MEMBERMUSTEXIST, TJS_W("filter"), 0, &val, params))) { std::vector<AnsiString> filterlist; if(val.Type() != tvtObject) { TVPPushFilterPair(filterlist, ttstr(val).AsAnsiString()); } else { iTJSDispatch2 * array = val.AsObjectNoAddRef(); tjs_int count; tTJSVariant tmp; if(TJS_SUCCEEDED(array->PropGet(TJS_MEMBERMUSTEXIST, TJS_W("count"), 0, &tmp, array))) count = tmp; else count = 0; for(tjs_int i = 0; i < count; i++) { if(TJS_SUCCEEDED(array->PropGetByNum(TJS_MEMBERMUSTEXIST, i, &tmp, array))) { TVPPushFilterPair(filterlist, ttstr(tmp).AsAnsiString()); } } } // create filter buffer tjs_int bufsize = 2; for(std::vector<AnsiString>::iterator i = filterlist.begin(); i != filterlist.end(); i++) { bufsize += i->Length() + 1; } filter = new char[bufsize]; char *p = filter; for(std::vector<AnsiString>::iterator i = filterlist.begin(); i != filterlist.end(); i++) { strcpy(p, i->c_str()); p += i->Length() + 1; } *(p++) = 0; *(p++) = 0; ofn.lpstrFilter = filter; } ofn.lpstrCustomFilter = NULL; ofn.nMaxCustFilter = 0; if(TJS_SUCCEEDED(params->PropGet(TJS_MEMBERMUSTEXIST, TJS_W("filterIndex"), 0, &val, params))) ofn.nFilterIndex = (tjs_int)val; else ofn.nFilterIndex = 0; // filenames filename = new char [MAX_PATH + 1]; filename[0] = 0; if(TJS_SUCCEEDED(params->PropGet(TJS_MEMBERMUSTEXIST, TJS_W("name"), 0, &val, params))) { ttstr lname(val); if(!lname.IsEmpty()) { lname = TVPNormalizeStorageName(lname); TVPGetLocalName(lname); AnsiString name = lname.AsAnsiString(); strncpy(filename, name.c_str(), MAX_PATH); filename[MAX_PATH] = 0; } } ofn.lpstrFile = filename; ofn.nMaxFile = MAX_PATH + 1; ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = 0; // initial dir ofn.lpstrInitialDir = NULL; if(TJS_SUCCEEDED(params->PropGet(TJS_MEMBERMUSTEXIST, TJS_W("initialDir"), 0, &val, params))) { ttstr lname(val); if(!lname.IsEmpty()) { lname = TVPNormalizeStorageName(lname); TVPGetLocalName(lname); initialdir = lname.AsAnsiString(); ofn.lpstrInitialDir = initialdir.c_str(); } } // title if(TJS_SUCCEEDED(params->PropGet(TJS_MEMBERMUSTEXIST, TJS_W("title"), 0, &val, params))) { title = ttstr(val).AsAnsiString(); ofn.lpstrTitle = title.c_str(); } else { ofn.lpstrTitle = NULL; } // flags bool issave = false; if(TJS_SUCCEEDED(params->PropGet(TJS_MEMBERMUSTEXIST, TJS_W("save"), 0, &val, params))) issave = val.operator bool(); ofn.Flags = OFN_ENABLEHOOK|OFN_EXPLORER|OFN_NOCHANGEDIR| OFN_PATHMUSTEXIST|OFN_HIDEREADONLY|OFN_ENABLESIZING; if(!issave) ofn.Flags |= OFN_FILEMUSTEXIST; else ofn.Flags |= OFN_OVERWRITEPROMPT; // default extension if(TJS_SUCCEEDED(params->PropGet(TJS_MEMBERMUSTEXIST, TJS_W("defaultExt"), 0, &val, params))) { defaultext = ttstr(val).AsAnsiString(); ofn.lpstrDefExt = defaultext.c_str(); } else { ofn.lpstrDefExt = NULL; } // hook proc ofn.lpfnHook = TVPOFNHookProc; // show dialog box if(!issave) result = GetOpenFileName(&ofn); else result = GetSaveFileName(&ofn); if(!result && CommDlgExtendedError() == CDERR_STRUCTSIZE) { // for old windows // set lStructSize to old Windows' structure size ofn.lStructSize = TVP_OLD_OFN_STRUCT_SIZE; if(!issave) result = GetOpenFileName(&ofn); else result = GetSaveFileName(&ofn); } if(result) { // returns some informations // filter index val = (tjs_int)ofn.nFilterIndex; params->PropSet(TJS_MEMBERENSURE, TJS_W("filterIndex"), 0, &val, params); // file name val = TVPNormalizeStorageName(ttstr(filename)); params->PropSet(TJS_MEMBERENSURE, TJS_W("name"), 0, &val, params); } } catch(...) { if(filter) delete [] filter; if(filename) delete [] filename; throw; } delete [] filter; delete [] filename; return (bool)result; }
void TVPBeforeSystemInit() { RegisterDllLoadHook(); // register DLL delayed import hook to support _inmm.dll TVPInitProgramArgumentsAndDataPath(false); // ensure command line #ifdef TVP_REPORT_HW_EXCEPTION __dee_hacked_set_getExceptionObjectHook(TVP__dee_hacked_getExceptionObjectHook); // register hook function for hardware exceptions #endif Application->HintHidePause = 24*60*60*1000; // not to hide tool tip hint immediately Application->ShowHint = false; Application->ShowHint = true; // to ensure assigning new HintWindow Class defined in HintWindow.cpp // randomize TVPInitRandomGenerator(); // memory usage { MEMORYSTATUS status; status.dwLength = sizeof(status); GlobalMemoryStatus(&status); TVPPushEnvironNoise(&status, sizeof(status)); TVPTotalPhysMemory = status.dwTotalPhys; TVPAddImportantLog(TJS_W("(info) Total physical memory : ") + ttstr((int)TVPTotalPhysMemory) ); tTJSVariant opt; if(TVPGetCommandLine(TJS_W("-memusage"), &opt)) { ttstr str(opt); if(str == TJS_W("low")) TVPTotalPhysMemory = 0; // assumes zero } if(TVPTotalPhysMemory <= 36*1024*1024) { // very very low memory, forcing to assume zero memory TVPTotalPhysMemory = 0; } if(TVPTotalPhysMemory < 48*1024*1024) { // extra low memory if(TJSObjectHashBitsLimit > 0) TJSObjectHashBitsLimit = 0; TVPSegmentCacheLimit = 0; TVPFreeUnusedLayerCache = true; // in LayerIntf.cpp } else if(TVPTotalPhysMemory < 64*1024*1024) { // low memory if(TJSObjectHashBitsLimit > 4) TJSObjectHashBitsLimit = 4; } } char buf[MAX_PATH]; bool bufset = false; bool nosel = false; bool forcesel = false; bool forcedataxp3 = GetSystemSecurityOption("forcedataxp3") != 0; bool acceptfilenameargument = GetSystemSecurityOption("acceptfilenameargument") != 0; if(!forcedataxp3 && !acceptfilenameargument) { if(TVPGetCommandLine(TJS_W("-nosel")) || TVPGetCommandLine(TJS_W("-about"))) { nosel = true; } else { for(tjs_int i = 1; i<_argc; i++) { if(_argv[i][0] == '-' && _argv[i][1] == '-' && _argv[i][2] == 0) break; if(_argv[i][0] != '-') { // TODO: set the current directory strncpy(buf, _argv[i], MAX_PATH-1); buf[MAX_PATH-1] = '\0'; if(DirectoryExists(buf)) // is directory? strcat(buf, "\\"); TVPProjectDirSelected = true; bufset = true; nosel = true; } } } } // check "-sel" option, to force show folder selection window if(!forcedataxp3 && TVPGetCommandLine(TJS_W("-sel"))) { // sel option was set if(bufset) { char path[MAX_PATH]; char *dum = 0; GetFullPathName(buf, MAX_PATH-1, path, &dum); strcpy(buf, path); TVPProjectDirSelected = false; bufset = true; } nosel = true; forcesel = true; } // check "content-data" directory if(!forcedataxp3 && !nosel) { char tmp[MAX_PATH]; strcpy(tmp, IncludeTrailingBackslash(ExtractFileDir(ParamStr(0))).c_str()); strcat(tmp, "content-data"); if(DirectoryExists(tmp)) { strcat(tmp, "\\"); strcpy(buf, tmp); TVPProjectDirSelected = true; bufset = true; nosel = true; } } // check "data.xp3" archive if(!nosel) { char tmp[MAX_PATH]; strcpy(tmp, IncludeTrailingBackslash(ExtractFileDir(ParamStr(0))).c_str()); strcat(tmp, "data.xp3"); if(FileExists(tmp)) { strcpy(buf, tmp); TVPProjectDirSelected = true; bufset = true; nosel = true; } } // check "data.exe" archive if(!nosel) { char tmp[MAX_PATH]; strcpy(tmp, IncludeTrailingBackslash(ExtractFileDir(ParamStr(0))).c_str()); strcat(tmp, "data.exe"); if(FileExists(tmp)) { strcpy(buf, tmp); TVPProjectDirSelected = true; bufset = true; nosel = true; } } // check self combined xpk archive if(!nosel) { if(TVPIsXP3Archive(TVPNormalizeStorageName(ParamStr(0)))) { strcpy(buf, ParamStr(0).c_str()); TVPProjectDirSelected = true; bufset = true; nosel = true; } } // check "data" directory if(!forcedataxp3 && !nosel) { char tmp[MAX_PATH]; strcpy(tmp, IncludeTrailingBackslash(ExtractFileDir(ParamStr(0))).c_str()); strcat(tmp, "data"); if(DirectoryExists(tmp)) { strcat(tmp, "\\"); strcpy(buf, tmp); TVPProjectDirSelected = true; bufset = true; nosel = true; } } // decide a directory to execute or to show folder selection if(!bufset) { if(forcedataxp3) throw EAbort("Aborted"); strcpy(buf, ExtractFileDir(ParamStr(0)).c_str()); int curdirlen = strlen(buf); if(buf[curdirlen-1] != '\\') buf[curdirlen] = '\\', buf[curdirlen+1] = 0; } if(!forcedataxp3 && (!nosel || forcesel)) { // load krdevui.dll ( TVP[KiRikiri] Development User Interface ) HMODULE krdevui = LoadLibrary("krdevui.dll"); if(!krdevui) { AnsiString toolspath = (IncludeTrailingBackslash( ExtractFilePath(ParamStr(0))) + "tools\\krdevui.dll"); krdevui = LoadLibrary(toolspath.c_str()); } if(!krdevui) { // cannot locate the dll throw Exception( ttstr(TVPCannnotLocateUIDLLForFolderSelection).AsAnsiString()); } typedef int PASCAL (*UIShowFolderSelectorForm_t)(void *reserved, char *buf); typedef void PASCAL (*UIGetVersion_t)(DWORD *hi, DWORD *low); UIShowFolderSelectorForm_t UIShowFolderSelectorForm; UIGetVersion_t UIGetVersion; UIShowFolderSelectorForm = (UIShowFolderSelectorForm_t)GetProcAddress(krdevui, "UIShowFolderSelectorForm"); UIGetVersion = (UIGetVersion_t)GetProcAddress(krdevui, "UIGetVersion"); if(!UIShowFolderSelectorForm || !UIGetVersion) { FreeLibrary(krdevui); throw Exception(ttstr(TVPInvalidUIDLL).AsAnsiString()); } DWORD h, l; UIGetVersion(&h, &l); if(h != TVP_NEED_UI_VERSION) { FreeLibrary(krdevui); throw Exception(ttstr(TVPInvalidUIDLL).AsAnsiString()); } int result = UIShowFolderSelectorForm(Application->Handle, buf); // FreeLibrary(krdevui); // FIXME: the library should be freed as soon as finishing to use it. if(result == mrAbort) { // display the main window } else if(result == mrCancel) { // cancel throw EAbort("Canceled"); } else if(result == mrOk) { // ok, prepare to execute the script TVPProjectDirSelected = true; } } // check project dir and store some environmental variables if(TVPProjectDirSelected) { Application->ShowMainForm=false; } tjs_int buflen = strlen(buf); if(buflen >= 1) { if(buf[buflen-1] != '\\') buf[buflen] = TVPArchiveDelimiter, buf[buflen+1] = 0; } TVPProjectDir = TVPNormalizeStorageName(buf); TVPSetCurrentDirectory(TVPProjectDir); TVPNativeProjectDir = buf; if(TVPProjectDirSelected) { TVPAddImportantLog(TJS_W("(info) Selected project directory : ") + TVPProjectDir); } }
//--------------------------------------------------------------------------- static void TVPInitProgramArgumentsAndDataPath(bool stop_after_datapath_got) { if(!TVPProgramArgumentsInit) { TVPProgramArgumentsInit = true; // find options from self executable image const int num_option_layers = 3; TStringList * options[num_option_layers]; for(int i = 0; i < num_option_layers; i++) options[i] = NULL; try { // read embedded options and default configuration file options[0] = TVPGetEmbeddedOptions(); options[1] = TVPGetConfigFileOptions(TConfMainFrame::GetConfigFileName(ParamStr(0))); // at this point, we need to push all exsting known options // to be able to see datapath PushAllCommandlineArguments(); PushConfigFileOptions(options[1]); // has more priority PushConfigFileOptions(options[0]); // has lesser priority // read datapath tTJSVariant val; AnsiString config_datapath; if(TVPGetCommandLine(TJS_W("-datapath"), &val)) config_datapath = ((ttstr)val).AsAnsiString(); TVPNativeDataPath = TConfMainFrame::GetDataPathDirectory(config_datapath, ParamStr(0)); if(stop_after_datapath_got) return; // read per-user configuration file options[2] = TVPGetConfigFileOptions(TConfMainFrame::GetUserConfigFileName(config_datapath, ParamStr(0))); // push each options into option stock // we need to clear TVPProgramArguments first because of the // option priority order. TVPProgramArguments.clear(); PushAllCommandlineArguments(); PushConfigFileOptions(options[2]); // has more priority PushConfigFileOptions(options[1]); // has more priority PushConfigFileOptions(options[0]); // has lesser priority } __finally { for(int i = 0; i < num_option_layers; i++) if(options[i]) delete options[i]; } // set data path TVPDataPath = TVPNormalizeStorageName(TVPNativeDataPath); TVPAddImportantLog(ttstr("(info) Data path : ") + TVPDataPath); // set log output directory TVPSetLogLocation(TVPNativeDataPath); // increment TVPCommandLineArgumentGeneration TVPCommandLineArgumentGeneration++; }
/** * AVIファイルを開く * @param filename 保存ファイル名 * @param fps 秒間フレーム数 */ void openAVI(const tjs_char *filename, int fps) { closeAVI(); // 録画開始時のサイズを記録しておく aviWidth = _width; aviHeight = _height; // AVIファイルを開く ttstr path = TVPNormalizeStorageName(ttstr(filename)); TVPGetLocalName(path); if (AVIFileOpen(&pavi, path.c_str(), OF_CREATE | OF_WRITE | OF_SHARE_DENY_NONE,NULL) != 0) { ttstr msg = filename; msg += ":can't open"; TVPThrowExceptionMessage(msg.c_str()); } // AVIストリームの生成 AVISTREAMINFO si = { streamtypeVIDEO, // Video Stream comptypeDIB, 0, // Stream Flag 0, 0, 0, 1, // 時間単位 dwScale fps, // フレーム dwRate 0, 0, // ストリームの長さ XXX 0, 0, (DWORD)-1, // -1: Default品質 [0-10000] 0, // 表示する矩形サイズ { 0, 0, aviWidth, aviHeight }, 0, 0, L"KIRIKIRI" }; if (AVIFileCreateStream(pavi, &pstm, &si) != 0) { closeAVI(); TVPThrowExceptionMessage(L"AVIFileCreateStream"); } // ストリームに投げ込むデータフォーマットを指定 BITMAPINFOHEADER bih; bih.biSize = sizeof(bih); bih.biWidth = aviWidth; bih.biHeight = aviHeight; bih.biPlanes = 1; bih.biBitCount = 32; bih.biCompression = BI_RGB; bih.biSizeImage = 0; bih.biXPelsPerMeter = 0; bih.biYPelsPerMeter = 0; bih.biClrUsed = 0; bih.biClrImportant = 0; if (AVIStreamSetFormat(pstm, 0, &bih, sizeof(bih)) != 0 ) { closeAVI(); TVPThrowExceptionMessage(L"AVIFileCreateStream"); } // 先頭フレーム lastFrame = -1; hasCv = false; }
/** * AVIファイルを圧縮フォーマットを指定して開く * @param filename 保存ファイル名 * @param fps 秒間フレーム数 * @param return 圧縮ダイアログでキャンセルを押した場合false。 */ bool openCompressedAVI(const tjs_char *filename, int fps) { closeAVI(); // 録画開始時のサイズを記録しておく aviWidth = _width; aviHeight = _height; // ストリームに投げ込むデータフォーマットを指定 BITMAPINFOHEADER bih; bih.biSize = sizeof(bih); bih.biWidth = aviWidth; bih.biHeight = aviHeight; bih.biPlanes = 1; bih.biBitCount = 32; bih.biCompression = BI_RGB; bih.biSizeImage = 0; bih.biXPelsPerMeter = 0; bih.biYPelsPerMeter = 0; bih.biClrUsed = 0; bih.biClrImportant = 0; // 圧縮オプションを取得 memset(&cv,0,sizeof(COMPVARS)); cv.cbSize=sizeof(COMPVARS); cv.dwFlags=ICMF_COMPVARS_VALID; cv.fccHandler=comptypeDIB; cv.lQ=ICQUALITY_DEFAULT; if (!ICCompressorChoose(NULL,ICMF_CHOOSE_DATARATE | ICMF_CHOOSE_KEYFRAME, &bih,NULL,&cv,NULL)) { return false; } // オプションを指定 opt.fccType=streamtypeVIDEO; opt.fccHandler=cv.fccHandler; opt.dwKeyFrameEvery=cv.lKey; opt.dwQuality=cv.lQ; opt.dwBytesPerSecond=cv.lDataRate; opt.dwFlags=(cv.lDataRate>0?AVICOMPRESSF_DATARATE:0) |(cv.lKey>0?AVICOMPRESSF_KEYFRAMES:0); opt.lpFormat=NULL; opt.cbFormat=0; opt.lpParms=cv.lpState; opt.cbParms=cv.cbState; opt.dwInterleaveEvery=0; // AVIファイルを開く ttstr path = TVPNormalizeStorageName(ttstr(filename)); TVPGetLocalName(path); if (AVIFileOpen(&pavi, path.c_str(), OF_CREATE | OF_WRITE | OF_SHARE_DENY_NONE,NULL) != 0) { ttstr msg = filename; msg += ":can't open"; TVPThrowExceptionMessage(msg.c_str()); } // AVIストリームの生成 AVISTREAMINFO si = { streamtypeVIDEO, // Video Stream comptypeDIB, 0, // Stream Flag 0, 0, 0, 1, // 時間単位 dwScale fps, // フレーム dwRate 0, 10, // ストリームの長さ XXX 0, 0, (DWORD)-1, // -1: Default品質 [0-10000] 0, // 表示する矩形サイズ { 0, 0, aviWidth, aviHeight }, 0, 0, L"KIRIKIRI" }; si.fccHandler=cv.fccHandler; if (AVIFileCreateStream(pavi, &pstm, &si) != 0) { closeAVI(); TVPThrowExceptionMessage(L"AVIFileCreateStream"); } if (AVIMakeCompressedStream(&ptmp,pstm,&opt,NULL)!=AVIERR_OK) { closeAVI(); TVPThrowExceptionMessage(L"AVIMakeCompressedStream"); } if (AVIStreamSetFormat(ptmp, 0, &bih, sizeof(bih)) != 0 ) { closeAVI(); TVPThrowExceptionMessage(L"AVIFileCreateStream"); } // 先頭フレーム lastFrame = -1; hasCv = true; return true; }