📄 main.cpp
字号:
else if(value=="off")
{
show=false;
}
i++;
}
}
else if(arg=="-dim")
{
i++;
string value(argv[i]);
vector<string> whVec;
LTKStringUtil::tokenizeString(value, ",", whVec);
if(whVec.size()!=1 && whVec.size()!=2)
{
cout<<"'"<<value<<"' not defined for dim"<<endl;
cout<<"type imgwriter -help for options and their values"<<endl;
exit(1);
}
else
{
if(whVec.size()==1)
{
size=atoi(whVec[0].c_str());
dimW = dimH = 0;
if(size<=0)
{
cout<<"Attribute 'size' of dim cannot be less than 1"<<endl;
exit(1);
}
}
else
{
dimW=atoi(whVec[0].c_str());
if(dimW<=0)
{
cout<<"Attribute 'width' of dim cannot be less than 1"<<endl;
exit(1);
}
dimH=atoi(whVec[1].c_str());
if(dimH<=0)
{
cout<<"Attribute 'height' of dim cannot be less than 1"<<endl;
exit(1);
}
}
i++;
}
}
else if(arg=="-data")
{
i++;
string value(argv[i]);
if(value!="unipen" && value!="hpl")
{
cout<<"'"<<value<<"' not defined for data"<<endl;
cout<<"type imgwriter -help for options and their values"<<endl;
exit(1);
}
data=value;
i++;
}
else if(arg=="-bb")
{
i++;
string value(argv[i]);
if(value!="true" && value!="false")
{
cout<<"'"<<value<<"' not defined for bb"<<endl;
cout<<"type imgwriter -help for options and their values"<<endl;
exit(1);
}
if(value=="true")
{
bb=true;
}
else
{
bb=false;
}
i++;
}
else if(arg=="-sp")
{
i++;
string value(argv[i]);
if(value!="true" && value!="false")
{
cout<<"'"<<value<<"' not defined for sp"<<endl;
cout<<"type imgwriter -help for options and their values"<<endl;
exit(1);
}
if(value=="true")
{
sp=true;
}
else
{
sp=false;
}
i++;
}
else if(arg=="-file")
{
i++;
string value(argv[i]);
filesList=value;
i++;
}
else if(arg=="-fext")
{
i++;
string value(argv[i]);
fileExt=value;
i++;
}
else if ((arg == "-ver")||(arg == "-v"))
{
cout << "\n version of imgwriter tool: " << SUPPORTED_MIN_VERSION << endl;
exit(0);
}
else
{
src=argv[i];
i++;
if(i<argc)
{
dest=argv[i];
i++;
}
}
}
if(show)
{
startUp(strRootDir,strTempDir);
}
if(src.empty())
{
ifstream inputFileList(filesList.c_str());
if(!inputFileList)
{
cout<<"File containing the list of files is not found"<<endl;
exit(1);
}
else
{
while(inputFileList)
{
string eachLine;
getline(inputFileList,eachLine);
if(!eachLine.empty())
{
string imgFileName=getFileName(eachLine);
int fileNameIndex=eachLine.rfind(imgFileName);
//string destDirectoryPath=eachLine.substr(0,fileNameIndex+4);
string destDirectoryPath=eachLine.substr(0,fileNameIndex);
string destImagePath=destDirectoryPath+imgFileName+".bmp";
writeImageFile(eachLine,destImagePath, data, view,
colorR, colorG, colorB, dimW, dimH,
size, bb, sp);
}
}
}
inputFileList.close();
}
else if(filesList.empty())
{
DIR *srcDIR;
struct dirent *srcDIREntry;
srcDIR=opendir(src.c_str());
if(srcDIR!=NULL)
{
readdir(srcDIR);
readdir(srcDIR);
int img=0;
string outputFileName=existingTempDir+"/marchtool/mt_tmp/output.html";
ofstream output;
if(show)
{
output.open(outputFileName.c_str());
output<<"<html>"<<endl;
output<<"<body>"<<endl;
output<<"<h3 align='center'>March Tool</h3><br><br>"<<endl;
output<<"<table align='center' border='1' bordercolor='black'>"<<endl;
}
while((srcDIREntry=readdir(srcDIR))!=NULL)
{
string srcFileName(srcDIREntry->d_name);
if(srcFileName.rfind(fileExt)!=string::npos)
{
string srcFilePath=src+"/"+srcFileName;
string destFile=srcFileName.substr(0,srcFileName.find_last_of('.'))+".bmp";
string destFilePath;
if(show)
{
destFilePath=existingTempDir+"/marchtool/mt_tmp/"+destFile;
}
else
{
if(dest.empty())
{
cout<<"Please mention the destination folder name"<<endl;
exit(1);
}
destFilePath=dest+"/"+destFile;
}
writeImageFile(srcFilePath,destFilePath, data, view,
colorR, colorG, colorB, dimW, dimH,
size,bb,sp);
if(show)
{
if(img==0)
{
output<<"<tr>"<<endl;
}
output<<"<td><a href='file://"<<srcFilePath<<"' title='"<<srcFileName.substr(0,srcFileName.find_last_of('.'))<<"'><img src='"<<destFile<<"' border='0'/></a></td>"<<endl;
img++;
if(img==4)
{
output<<"</tr>"<<endl;
img=0;
}
}
}
}
if(show)
{
if(img!=4)
{
output<<"</tr>"<<endl;
}
output<<"</table>"<<endl;
output<<"</body>"<<endl;
output<<"</html>"<<endl;
output.close();
string exeWithCmdOptions;
#ifdef _WIN32
exeWithCmdOptions="rundll32 url.dll,FileProtocolHandler file://"+existingTempDir+"/marchtool/mt_tmp/output.html";
#else
exeWithCmdOptions="netscape file:/"+existingTempDir+"/marchtool/mt_tmp/output.html";
#endif
//system("rundll32 url.dll,FileProtocolHandler file://c:/marchtool/mt_tmp/output.html");
system(exeWithCmdOptions.c_str());
}
closedir (srcDIR);
}
else
{
string title=getFileName(src);
string destFile=title+".bmp";
string destFilePath;
if(show)
{
destFilePath=existingTempDir+"/marchtool/mt_tmp/"+destFile;
}
else
{
if(dest.empty())
{
cout<<"Please mention the destination file name"<<endl;
exit(1);
}
else
{
destFilePath=dest;
}
}
writeImageFile(src, destFilePath, data, view, colorR, colorG,
colorB,dimW,dimH,size,bb,sp);
if(show)
{
string outputFileName=existingTempDir+"/marchtool/mt_tmp/output.html";
ofstream output(outputFileName.c_str());
output<<"<html>"<<endl;
output<<"<body>"<<endl;
output<<"<h3 align='center'>March Tool</h3><br><br>"<<endl;
output<<"<table align='center' border='1' bordercolor='black'>"<<endl;
output<<"<tr>"<<endl;
output<<"<td><a href='file://"<<src<<"' title='"<<title<<"'><img src='"<<destFile<<"' border='0'/></a></td>"<<endl;
output<<"</tr>"<<endl;
output<<"</table>"<<endl;
output<<"</body>"<<endl;
output<<"</html>"<<endl;
output.close();
//system("rundll32 url.dll,FileProtocolHandler file://c:/marchtool/mt_tmp/output.html");
string exeWithCmdOptions;
#ifdef _WIN32
exeWithCmdOptions="rundll32 url.dll,FileProtocolHandler file://"+existingTempDir+"/marchtool/mt_tmp/output.html";
#else
exeWithCmdOptions="netscape file:/"+existingTempDir+"/marchtool/mt_tmp/output.html";
#endif
system(exeWithCmdOptions.c_str());
}
}
}
else
{
cout<<"Please mention either the source folder/file name or the file containing the list of files"<<endl;
exit(1);
}
}
catch(...)
{
cout<<endl<<"Unable to execute the command with the specified options!"<<endl;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -