当前位置:网站首页>[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();
}
边栏推荐
- Global and Chinese market of AVR series microcontrollers 2022-2028: Research Report on technology, participants, trends, market size and share
- Teach you how to write the first MCU program hand in hand
- There are software load balancing and hardware load balancing. Which one to choose?
- [deep learning] semantic segmentation: thesis reading (neurips 2021) maskformer: per pixel classification is not all you need
- 大学想要选择学习自动化专业,可以看什么书去提前了解?
- 听哥一句劝,按这套嵌入式的课程内容和课程体系去学习
- May brush question 01 - array
- 51单片机进修的一些感悟
- In order to get an offer, "I believe that hard work will make great achievements
- 嵌入式開發中的防禦性C語言編程
猜你喜欢

Lua script of redis

Release of the sample chapter of "uncover the secrets of asp.net core 6 framework" [200 pages /5 chapters]

发生OOM了,你知道是什么原因吗,又该怎么解决呢?

In order to get an offer, "I believe that hard work will make great achievements

Elk project monitoring platform deployment + deployment of detailed use (II)

五月集训总结——来自阿光

Design and implementation of online snack sales system based on b/s (attached: source code paper SQL file)
![《ASP.NET Core 6框架揭秘》样章发布[200页/5章]](/img/4f/5688c391dd19129d912a3557732047.jpg)
《ASP.NET Core 6框架揭秘》样章发布[200页/5章]

Mapreduce实例(十):ChainMapReduce

Design and implementation of film and television creation forum based on b/s (attached: source code paper SQL file project deployment tutorial)
随机推荐
MapReduce working mechanism
单片机如何从上电复位执行到main函数?
大学想要选择学习自动化专业,可以看什么书去提前了解?
May brush question 03 - sorting
五月集训总结——来自阿光
Day 5 of MySQL learning
Redis distributed lock implementation redison 15 questions
Popularization of security knowledge - twelve moves to protect mobile phones from network attacks
Minio distributed file storage cluster for full stack development
小白带你重游Spark生态圈!
MySQL数据库优化的几种方式(笔面试必问)
Nc17 longest palindrome substring
What are the models of data modeling
C#/. Net phase VI 01C Foundation_ 01: running environment, process of creating new C program, strict case sensitivity, meaning of class library
Processes of libuv
Segmentation sémantique de l'apprentissage profond - résumé du code source
Design and implementation of online shopping system based on Web (attached: source code paper SQL file)
Several ways of MySQL database optimization (pen interview must ask)
五月刷题26——并查集
英雄联盟轮播图自动轮播