-
-
Save hxhb/3207f4a57d63e30a721115b656deaced to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <string> | |
#include <map> | |
#include <initializer_list> | |
#include "fileList.h" | |
using namespace std; | |
bool split(const std::string& InPath,std::string& OutDir,std::string& OutName,std::string& OutExtension) | |
{ | |
bool status = false; | |
size_t r_slash_index = InPath.find_last_of('\\'); | |
if(r_slash_index != std::string::npos) | |
{ | |
std::string directory(InPath,0,r_slash_index); | |
std::string name(InPath,r_slash_index+1,InPath.size()-r_slash_index); | |
std::string extension; | |
size_t last_dot_index = name.find_last_of('.'); | |
if(last_dot_index!=std::string::npos) | |
{ | |
extension = std::string(name,last_dot_index+1,name.size()-last_dot_index); | |
name = std::string(name,0,last_dot_index); | |
} | |
OutDir = directory; | |
OutName = name; | |
OutExtension = extension; | |
status = true; | |
} | |
return status; | |
} | |
#define SHOW_REPLACED_MESSAGE 0 | |
int main(int argc,char*argv[]){ | |
vector<string> fileTypeList{".png",".jpg"}; | |
std::string searchPath; | |
if(argc > 1) | |
{ | |
searchPath = std::string(argv[1]); | |
} | |
else | |
{ | |
searchPath = fileList::getExecAbsPath(); | |
} | |
std::cout<<"Search path:"<<searchPath<<std::endl; | |
fileList search(searchPath,fileTypeList); | |
search.start(); | |
auto GenWebpLambda = [](const std::vector<std::string>& in_file_list) | |
{ | |
for(const auto& index : in_file_list) | |
{ | |
std::string dir,name,extension; | |
if(split(index,dir,name,extension)) | |
{ | |
// cout<<"dir:"<<dir<<"\tfilename:"<<name<<"\textension:"<<extension<<endl; | |
std::string result = dir+"\\"+name+".webp"; | |
fstream _file; | |
_file.open(result,ios::in); | |
if(!_file) | |
{ | |
std::string command = "cwebp -q 85 "+index+" -o "+result; | |
cout<<command<<endl; | |
system(command.data()); | |
} | |
else | |
{ | |
#if SHOW_REPLACED_MESSAGE | |
cout<<index<<" is replicated"<<endl; | |
#endif | |
} | |
} | |
} | |
}; | |
for(const auto& extension:fileTypeList) | |
{ | |
cout<<"replacing "<<extension<<" as webp..."<<endl; | |
const auto& foundfileList = search.getTypeMatchFileList(extension); | |
GenWebpLambda(foundfileList); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment