当前位置:网站首页>[one click] it only takes 30s to build a blog with one click - QT graphical tool
[one click] it only takes 30s to build a blog with one click - QT graphical tool
2022-07-06 09:46:00 【C+++++++++++++++++++】
List of articles
Software use
Please download it before using git Tools
Project introduction
reminder : After building the website framework locally , The writing experience of each new article is poor , You can see my other hugo Blog automatic writing tool
src Catalog : Store the source code of the graphical project , Use Qt6 It can be started directly QHugoInit project .
bin Catalog : Store the executable binary of the project .
- exec_code.bat: Used to write code execution script
- hugo.exe: The cornerstone of building a blog
- QHugoInit.exe: Software launcher
- log.txt: Log of the whole program execution
Key source code of the project
Prevent the download step from blocking the screen through multithreading
//TODO Simply encapsulate a class for multithreaded communication
class run_thread:public QThread{
public:
run_thread() = delete;
run_thread(const std::function<void()>&Runnable,QObject* parent = nullptr):m_task(nullptr){
m_task = Runnable;
}
void run()override{
if(m_task!=nullptr);
m_task();
}
private:
std::function<void()>m_task;
};
Through documents io Control the code execution of the command line to execute each corresponding step
void MainWindow::on_right_Btn_clicked()
{
auto path = ui->input->text();
if(!QDir(path).exists()||path.isEmpty()){
QMessageBox::warning(nullptr," Tips "," Folder path does not exist ");
return;
}
ui->w2->setVisible(false);
ui->w4->setVisible(false);
ui->w3->setVisible(true);
ui->l1->setText(" Everything is about to be ready ");
ui->l2->setText(" Initializing your hugo Website ");
ui->l3->setOpenExternalLinks(true);
ui->l3->setText(R"(<html> <style> a { color:#3281b8; } </style><head/><body><p> This may take a few minutes , Please do not force the application to close <br/><br/> Idle and bored ?<a href="https://github.com/ACking-you/AutoHugoSetup"> Give me one star</a></p></body></html>)");
QProcess qp;
std::ofstream writer;
m_Path = path;
auto std_str = m_Path.toStdString();
//first step
writer.open("./exec_code.bat");
if(!writer.is_open()){
QMessageBox::warning(nullptr," Tips "," The first write file open failed ");
writer.close();
QCoreApplication::exit(1);
}
ui->info_text->setText(" Initializing hugo Blog ");
std::replace(std_str.begin(),std_str.end(),'/','\\'); // Note here :cmd32 The command only supports backslashes !
writer<<R"(chcp 65001)"<<'\n'; // Set the code to utf-8
writer<<R"(copy .\hugo.exe )"<<std_str<<'\n'; //copy One copy hugo.exe Go to the target directory
writer<<"cd /d"<<std_str<<'\n'; // Switch to create directory , here /d Represents switching directories directly in one step
writer<<R"(.\hugo new site myBlog)"<<'\n'; // initialization hugo command
writer.close();
qp.startCommand(R"(.\exec_code.bat)");
if(qp.waitForFinished()){
QString str = qp.readAll();
m_logWriter<<"-----1st step-----\n\r"<<str.toStdString()<<'\n';
ui->info_text->setText(" hugo Blog initialization complete ");
}
//second step: Judge before performing this step git Is it available , This step takes the longest , Don't let it jam the main thread , Therefore, multithreading technology is needed
qp.startCommand("git");
if(!qp.waitForFinished()){
QMessageBox::warning(nullptr," Tips "," Not installed git Tool or not set to environment variable ");
QCoreApplication::exit(1);
}
writer.open("./exec_code.bat");
if(!writer.is_open()){
QMessageBox::warning(nullptr," Tips "," The second write file open failed ");
writer.close();
QCoreApplication::exit(1);
}
ui->info_text->setText(" Downloading FeelIt The theme ");
std::filesystem::path blog_path = std_str;
blog_path /= "myBlog";
m_Path = blog_path.string().c_str();
writer<<"cd /d"<<blog_path<<"\\themes"<<'\n'; //cd To themes Folder directory
writer<<"git clone https://gitee.com/acking-you/FeelIt.git"<<'\n';// Begin to pass git Download the theme pack
writer.close();
QThread* sub_thread = new run_thread([&]{
// Don't disturb the normal operation of the main thread for the most time-consuming work , Otherwise, the main thread may appear to be paralyzed
QProcess tqp;
// Signal slot mechanism , The main thread waits for the sub thread to complete the task and send a signal before executing the last step , Because this process must be synchronized , Therefore, the signal slot is required to wait
connect(&tqp,&QProcess::finished,[&](int exitCode, QProcess::ExitStatus exitStatus){
//step third
std::ofstream writer;
QProcess qp;
writer.open("./exec_code.bat");
if(!writer.is_open()){
QMessageBox::warning(nullptr," Tips "," The third write file open failed ");
writer.close();
QCoreApplication::exit(1);
}
ui->info_text->setText(" Configuring local themes ...");
writer<<"cd /d"<<m_Path.toStdString()<<'\n'; //cd To blog_path
writer<<R"(del .\config.toml)"<<'\n'; // Delete the original config file
writer<<R"(move .\themes\FeelIt\config.toml .\)"<<'\n'; // Put my configuration file in the top-level directory
writer<<R"(move .\themes\FeelIt\exampleSite\static\* .\static\)"<<'\n';// Move static Image resources
writer<<R"(move ..\hugo.exe .\)"<<'\n';// Put the previous hugo.exe Move to the real blog directory
writer<<R"(mkdir .\content\posts)"<<'\n'; // Create a directory for writing articles
writer.close();
qp.startCommand(R"(.\exec_code.bat)");
if(qp.waitForFinished(120000)){
ui->info_text->setText(" Configuration complete ");
ending();
m_logWriter<<"-----3rd step-----\n\r"<<qp.readAll().toStdString();
}
});
tqp.startCommand(R"(.\exec_code.bat)");
if(!tqp.waitForFinished(120000)){
QMessageBox::warning(nullptr," Tips "," Download theme response timeout ");
QCoreApplication::exit(1);
}else{
m_logWriter<<"-----2nd step-----\n\r"<<tqp.readAll().toStdString();
}
});
sub_thread->start();
}
边栏推荐
- MapReduce instance (IV): natural sorting
- MapReduce instance (V): secondary sorting
- 英雄联盟轮播图手动轮播
- [Yu Yue education] reference materials of complex variable function and integral transformation of Shenyang University of Technology
- Oom happened. Do you know the reason and how to solve it?
- Mapreduce实例(七):单表join
- YARN组织架构
- 机械工程师和电气工程师方向哪个前景比较好?
- DCDC power ripple test
- Redis distributed lock implementation redison 15 questions
猜你喜欢
Design and implementation of online snack sales system based on b/s (attached: source code paper SQL file)
Redis distributed lock implementation redison 15 questions
33岁可以学PLC吗
Oom happened. Do you know the reason and how to solve it?
Single chip microcomputer realizes modular programming: Thinking + example + system tutorial (the degree of practicality is appalling)
面试突击62:group by 有哪些注意事项?
Redis分布式锁实现Redisson 15问
Can I learn PLC at the age of 33
O & M, let go of monitoring - let go of yourself
一大波開源小抄來襲
随机推荐
DCDC power ripple test
MapReduce instance (VI): inverted index
[deep learning] semantic segmentation: paper reading: (2021-12) mask2former
May brush question 26 - concurrent search
MapReduce instance (IX): reduce end join
Solve the problem of too many small files
零基础学习单片机切记这四点要求,少走弯路
Regular expressions are actually very simple
Mapreduce实例(四):自然排序
Cap theory
Activiti7工作流的使用
Which is the better prospect for mechanical engineer or Electrical Engineer?
Use of activiti7 workflow
CAPL 脚本打印函数 write ,writeEx ,writeLineEx ,writeToLog ,writeToLogEx ,writeDbgLevel 你真的分的清楚什么情况下用哪个吗?
为什么要数据分层
Defensive C language programming in embedded development
五月集训总结——来自阿光
【深度學習】語義分割-源代碼匯總
【深度学习】语义分割:论文阅读:(2021-12)Mask2Former
面试突击62:group by 有哪些注意事项?