当前位置:网站首页>[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();
}
边栏推荐
- Listen to my advice and learn according to this embedded curriculum content and curriculum system
- MapReduce instance (VII): single table join
- 六月刷题01——数组
- Global and Chinese markets of SERS substrates 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of AVR series microcontrollers 2022-2028: Research Report on technology, participants, trends, market size and share
- 为什么要数据分层
- Redis distributed lock implementation redison 15 questions
- Vs All comments and uncomments
- Mapreduce实例(六):倒排索引
- 听哥一句劝,按这套嵌入式的课程内容和课程体系去学习
猜你喜欢

Detailed explanation of cookies and sessions

基于B/S的医院管理住院系统的研究与实现(附:源码 论文 sql文件)

Cap theory

英雄联盟轮播图手动轮播

Single chip microcomputer realizes modular programming: Thinking + example + system tutorial (the degree of practicality is appalling)

Hard core! One configuration center for 8 classes!

数据建模有哪些模型

大学C语言入门到底怎么学才可以走捷径

大学想要选择学习自动化专业,可以看什么书去提前了解?

Defensive C language programming in embedded development
随机推荐
Some thoughts on the study of 51 single chip microcomputer
VH6501学习系列文章
The real future of hardware engineers may not be believed by you if I say so
What you have to know about network IO model
A wave of open source notebooks is coming
May brush question 26 - concurrent search
Leetcode:608 树节点
单片机实现模块化编程:思维+实例+系统教程(实用程度令人发指)
MapReduce instance (IV): natural sorting
为什么要数据分层
五月刷题03——排序
基于B/S的网上零食销售系统的设计与实现(附:源码 论文 Sql文件)
tn-c为何不可用2p断路器?
There are software load balancing and hardware load balancing. Which one to choose?
Meituan Er Mian: why does redis have sentinels?
June brush question 02 - string
MapReduce instance (VIII): Map end join
Minio distributed file storage cluster for full stack development
基于B/S的医院管理住院系统的研究与实现(附:源码 论文 sql文件)
Redis connection redis service command