|
Posted on 2008-11-04 19:27 S.l.e!ep.¢% 阅读(2260) 评论(4) 编辑 收藏 引用 所属分类: VC
为了生成 swf 方法,写了个工具,写得,写得很粗糙…… #include <string> #include <vector> #include <iostream> using namespace std; #include <windows.h> #include <atlbase.h>
namespace std { typedef basic_string<WCHAR, char_traits<WCHAR>, allocator<WCHAR> > tstring; }
/**//* * return a absolute path and create a temporary file * the path is the system temp directory, * the filename is a temporary file name contains [strTmp] * Tips!!! Must delete the temporary file after used */ string getTempFilePath(string strTmp) { TCHAR szTmpPath[_MAX_PATH] = {0}, szTmpFileName[_MAX_PATH] = {0};
DWORD dwLength = ::GetTempPath(_MAX_PATH, szTmpPath);
/**//* * If the function [GetTempPath] fails, return a null string */ if ( dwLength == 0 ) return __TEXT("");
DWORD dwLength2 = ::GetTempFileName(szTmpPath, strTmp.c_str(), 0, szTmpFileName);
/**//* * If the function [GetTempFileName] fails, return a null string */ if ( dwLength2 == 0 ) return __TEXT("");
return szTmpFileName; }// _getTempFilePath()
int main(int argc, char* argv[]) { int nArgs = 0; std::vector<std::tstring> vecToken;
LPWSTR * szArglist = ::CommandLineToArgvW(::GetCommandLineW(), &nArgs);
if( NULL == szArglist ) { cout << "Invalid Parameter!" << endl; return 1; } else { for(int i = 0; i < nArgs; i++) vecToken.push_back(szArglist[i]);
}// if( NULL == szArglist )
// Free memory allocated for CommandLineToArgvW arguments. LocalFree(szArglist);
if ( vecToken.size() != 3 ) { cout << "Invalid Parameter! " << vecToken.size() << endl; return 1; }
USES_CONVERSION; //cout << (char*)W2A(vecToken[1].c_str()) << endl; //cout << (char*)W2A(vecToken[2].c_str()) << endl;
// 获取目标目录所有 *.fla 文件 WIN32_FIND_DATA filedata; char strResultLogPath[MAX_PATH] = {0}; sprintf(strResultLogPath, _T("%s\\*.fla"), W2A(vecToken[1].c_str()) ); std::vector<string> vecFlaLogs;
HANDLE hFind = ::FindFirstFile(strResultLogPath, &filedata); if (hFind == INVALID_HANDLE_VALUE) { // 一个 .fla 文件都没有 } else { do { // filedata.cFileName 为 fla 的文件名 vecFlaLogs.push_back(filedata.cFileName); OutputDebugString(filedata.cFileName); OutputDebugString("\n"); } while( FindNextFile(hFind, &filedata) );
}// if (hFind == INVALID_HANDLE_VALUE) ::FindClose(hFind);
// 存放临时文件 string strFile = getTempFilePath("fl"); string strFile1 = strFile; strFile += ".jsfl";
FILE* pFile = fopen(strFile.c_str(), "wb"); if ( pFile == NULL ) { cout << "failed to open file: " << strFile.c_str() << endl; return 1; }
std::vector<string>::iterator iter_t; for ( iter_t = vecFlaLogs.begin(); iter_t != vecFlaLogs.end(); iter_t++ ) { string strFlaFile = *iter_t; string strSwfFile = *iter_t;
strSwfFile = strSwfFile.substr(0, strSwfFile.length() - 4); strSwfFile += ".swf"; fprintf(pFile, "var sourceFile = \"file:/**////%s/%s\";\r\n", W2A(vecToken[1].c_str()), strFlaFile.c_str()); fprintf(pFile, "var outputFile = \"file:/**////%s/%s\";\r\n", W2A(vecToken[2].c_str()), strSwfFile.c_str()); fprintf(pFile, "var doc = fl.openDocument(sourceFile);\r\n"); fprintf(pFile, "doc.exportSWF(outputFile, true);\r\n"); fprintf(pFile, "doc.close(false);\r\n");
}// for ( iter_t = vecFlaLogs.begin(); iter_t != vecFlaLogs.end(); iter_t++ )
fprintf(pFile, "fl.quit();\r\n"); // 关闭文件时才保存文件内容 fclose(pFile);
// 读取注册表 HKEY hk; LPCTSTR data_Get="Flash.JSCommandFile\\shell\\open\\command"; //在注册表里的位置 long ret0 = ::RegOpenKeyEx(HKEY_CLASSES_ROOT, //根 data_Get, 0, //必须为0,保留 KEY_READ, //安全访问屏蔽字,具体见MSDN,列出了所有的值 &hk); //通过ERROR_SUCCESS判断打开是否成功。 if( ret0 != ERROR_SUCCESS) { cout << "failed to read regedit" << endl; return 1; }
LPBYTE win_version = new BYTE[80]; DWORD type=REG_SZ; DWORD cbData=80; long ret1 = ::RegQueryValueEx(hk, "", //请求得到的键的名称 NULL, //保留,必须为 NULL, //值的类型,具体见MSDN win_version, //接受值的缓冲区 &cbData); //缓冲区大小 if ( ret1 != ERROR_SUCCESS ) { cout << "failed to read regedit" << endl; return 1; }
string strRegValue = (char*)win_version; delete[] win_version; ::RegCloseKey(hk); strRegValue = strRegValue.substr(0, strRegValue.length() - 5);
// 调用 flash.exe //strRegValue strRegValue += " "; strRegValue += "\""; strRegValue += strFile; strRegValue += "\"";
UINT rlt = WinExec(strRegValue.c_str(), SW_HIDE); switch (rlt) { case 0: { cout << "The system is out of memory or resources." << endl; return 1; } break;
case ERROR_BAD_FORMAT: { cout << "The .exe file is invalid." << endl; return 1; } break;
case ERROR_FILE_NOT_FOUND: { cout << "The specified file was not found." << endl; return 1; } break; case ERROR_PATH_NOT_FOUND: { cout << "The specified path was not found." << endl; return 1; } break; }
// 删除临时文件 ::DeleteFile(strFile.c_str()); ::DeleteFile(strFile1.c_str());
return 0; }
Feedback
# re: 为了生成flash文件方便,写了个工具 回复 更多评论
2008-11-05 02:11 by
这个代码好像在www.zuiwanting.com见过
# re: 为了生成flash文件方便,写了个工具 回复 更多评论
2008-11-05 12:55 by
好像是在命令行调用什么工具来编译fla文件为swf 其实用C++写这样的功能太浪费了 用一个bat或VBS完全能搞定的
# re: 为了生成flash文件方便,写了个工具 回复 更多评论
2008-11-05 14:19 by
该页面有木马………………
最近发现cppblog好多页面都被挂了木马,大家小心一下
# re: 为了生成flash文件方便,写了个工具 回复 更多评论
2008-11-10 22:21 by
你是指这个页面有马?
晕,我没装杀毒软件啊!!!!
|