Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AdemJensen committed Nov 25, 2018
1 parent 0875647 commit 1028418
Show file tree
Hide file tree
Showing 13 changed files with 1,415 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
71 changes: 71 additions & 0 deletions change.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (C) 2018 AdemJensen
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 3,
// or (at your option) any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.

void changesettings()
{
while(true)
{
clearall();
string cbef="[?ȴ??Ӧ]?ѡ?????ĵ??\n________________________________________\n";
string sel1="????:"+exename;
string sel2="?????ʼ??:"+itos(from);
string sel3="????????:"+itos(to);
string sel4="?????:"+inname;
string sel5="??????:"+outname;
int select=arrowselect(cbef,"________________________________________",6,1,sel1.c_str(),2,sel2.c_str(),2,sel3.c_str(),2,sel4.c_str(),3,sel5.c_str(),4,"[??????");
announcedata();
if(select==1)
{
bool curok=false;
string temp;
while(!curok) curok=loadexename(temp);
}
if(select==2)
{
bool curok=false;
string temp;
while(true)
{
while(true)
{
curok=false;
while(!curok) curok=loadfrom(temp);
curok=false;
while(!curok) curok=loadto(temp);
if(from>to)
{
_err("[?????ʼ????ڽ????!\n");
toset=false;
fromset=false;
continue;
}
break;
}
curok=false;
while(!curok) curok=loadinname(temp);
if(!infilecheck(inname,from,to,true)) continue;
break;
}
}
if(select==3)
{
bool curok=false;
string temp;
while(!curok||!checkallset(true)) curok=loadoutname(temp);
}
if(select==4) return;
}
}
202 changes: 202 additions & 0 deletions checksys.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
// Copyright (C) 2018 AdemJensen
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 3,
// or (at your option) any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.

bool checkexename(string s,bool show)
{
if(show) cout<<"[信息]正在检查exe合法性...";
int len=s.size();
if(s[len-4]!='.'||s[len-3]!='e'||s[len-2]!='x'||s[len-1]!='e')
{
cline();
if(show) _err("[错误]指定的文件不是exe文件!\n");
return false;
}
if(!exist(s))
{
cline();
if(show) _err("[错误]无法找到指定exe文件!\n");
return false;
}
if(s==currentexe)
{
cline();
if(show) _err("[错误]不能指定转换器为目标exe程序!\n");
return false;
}
string opera=s+" -anti-reopen-mode";
cline();_warn("[注意]检查exe需要运行您的exe,如有崩溃,属于正常现象。\n");

WinExec(opera.c_str(),SW_SHOW);

Sleep(500);
opera="taskkill /IM "+s;
opera+=" /f";
system(opera.c_str());
clearall();

if(!exist("std.out"))
{
cline();
if(show) _err("[错误]指定的exe程序未正确设置文件操作!\n");
return false;
}
remove("std.out");
//remove("std.in");
cline();
return true;
}

bool checkrule(string s,bool show)
{
int len=s.size();
int pos;
bool ok=true;
bool havenes=false;
for(int i=0;i<len;i++)
{
if(s[i]=='%')
{
pos=i;
i++;
if(s[i]=='%') continue;
while(isdigit(s[i])&&i<len-1) i++;
if(s[i]=='d')
{
havenes=true;
continue;
}
if(show) _err("[错误]无法识别的标识符\""),_err(exract(s,pos,i)),_err("\"!\n");
ok=false;
}
}
if(!havenes)
{
if(show) _err("[错误]缺少标识符\"%d\"!\n");
ok=false;
}
return ok;
}

bool numcheck(string s)
{
int len=s.size();
for(int i=0;i<len;i++)
{
if(!isdigit(s[i]))
{
return false;
}
}
return true;
}

string getfilename(string s,int now)
{
int len=s.size();
int pos;
string ans;
for(int i=0;i<len;i++)
{
if(s[i]=='%')
{
pos=i;i++;
if(s[i]=='%')
{
ans+=s[i];
continue;
}
while(isdigit(s[i])&&i<len-1) i++;
if(s[i]=='d')
{
int snum=stoi(exract(s,pos+1,i-1));
string targetnum=itos(now);
int divis=snum-targetnum.size();
for(int i=1;i<=divis;i++) ans+='0';
ans+=targetnum;
}
}
else
{
ans+=s[i];
}
}
return ans;
}

bool infilecheck(string s,int from,int to,bool show)
{
bool ok=true;
for(int i=from;i<=to;i++)
{
if(!exist(getfilename(s,i)))
{
if(show) _err("[错误]无法找到\""),_err(getfilename(s,i)),_err("\"!\n");
ok=false;
}
}
return ok;
}

bool checknum(string s,bool show)
{
if(!numcheck(s))
{
if(show) _err("[错误]数字中包含非法字符!\n");
return false;
}
if(stoi(s)<0)
{
if(show) _err("[错误]数字无效!\n");
return false;
}
return true;
}

bool checkallset(bool show)
{
bool result=true;
if(!exenameset)
{
if(show) _err("[错误]未设置程序名!\n");
result=false;
}
if(!innameset)
{
if(show) _err("[错误]未设置输入文件名!\n");
result=false;
}
if(!outnameset)
{
if(show) _err("[错误]未设置输出文件名!\n");
result=false;
}
if(!fromset)
{
if(show) _err("[错误]未设置文件开始编号!\n");
result=false;
}
if(!toset)
{
if(show) _err("[错误]未设置文件结束编号!\n");
result=false;
}
if(getfilename(inname,from)==getfilename(outname,from)||getfilename(inname,to)==getfilename(outname,to))
{
if(show) _err("[错误]输入文件与输出文件有重复!\n");
result=false;
}
return result;
}
46 changes: 46 additions & 0 deletions convertmain.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (C) 2018 AdemJensen
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 3,
// or (at your option) any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.

bool mainconversion(bool show)
{
if(show) clearall();
string outfilename;
string infilename;
announcedata();
for(int i=from;i<=to;i++)
{
infilename=getfilename(inname,i);
outfilename=getfilename(outname,i);
if(show) cout<<"[信息]正在转换: "<<infilename<<" --> "<<outfilename<<"\r";
CopyFile(infilename.c_str(),"std.in",false);
int result=system(exename.c_str());
if(result!=0)
{
if(show) cline();
if(show) cout<<endl;
if(show) _err("[错误]进行"),_err(infilename),_err(" --> "),_err(outfilename),_err("操作过程中:\n");
if(show) _err("[错误]您提供的程序在运行时错误!返回值:"),_err(result),_err('\n');
if(show) _err("[错误]进程已取消!按任意键继续。\n");
remove("std.in");remove("std.out");
return false;
}
CopyFile("std.out",outfilename.c_str(),false);
remove("std.in");remove("std.out");
if(show) cline();
}
if(show) cline();
return true;
}

0 comments on commit 1028418

Please sign in to comment.