Skip to content

Commit

Permalink
Startup
Browse files Browse the repository at this point in the history
  • Loading branch information
mhtvsSFrpHdE committed Mar 4, 2022
1 parent bde7dd5 commit d0044c6
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
6 changes: 6 additions & 0 deletions qpp/prefetch/Source/Core/read_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "..\Setting\setting.h"
#include "..\Output\stdout.h"
#include "Thread\read_thread.h"
#include "startup.h"

int ReadFile::count_start_scanFolder = 0;
QList<QRunnable *> ReadFile::readThreadQueue = QList<QRunnable *>();
Expand Down Expand Up @@ -180,6 +181,11 @@ bool ReadFile::start_runThreadPool(int rescanInterval)
.toString("ss.zzz");
threadPoolTimeConsumedFormatedString.chop(1);

*StdOut::consoleOutput << "Run startup items..."
<< endl;
StdOut::consoleOutput->flush();
Startup::startOnce();

// Increase task count
count_taskComplete++;

Expand Down
30 changes: 30 additions & 0 deletions qpp/prefetch/Source/Core/startup.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <QProcess>

#include "startup.h"
#include "..\Setting\setting.h"

bool Startup::started = false;

void Startup::startOnce()
{
// Disable after fist run
if (started)
{
return;
}
started = true;

// Get startup items
auto afterPrefetch = Setting::getArray("AfterPrefetch", Setting::setting);
for (int i = 0; i < afterPrefetch.size(); ++i)
{
auto fileName = afterPrefetch[i];

QProcess process;

// Cool stuff
// Use startDetached to avoid print to console
// QProcess: Destroyed while process is still running.
process.startDetached(fileName);
}
}
14 changes: 14 additions & 0 deletions qpp/prefetch/Source/Core/startup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Static class
class Startup
{
public:
// This function will only run once
static void startOnce();

private:
// Disallow creating an instance of this object
Startup() {}

// After run set to true
static bool started;
};
3 changes: 2 additions & 1 deletion qpp/prefetch/prefetch.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ FirefoxProgramFiles=C:\\Mozilla\\Program Files
FirefoxCache=C:\\Mozilla\\AppData\\Local\Mozilla\\Firefox\\Profiles\\default\\cache2\\entries

[AfterPrefetch]
Firefox=C:\\Program Files\\Mozilla Firefox\\firefox.exe
Firefox=\"C:\\Program Files\\Mozilla Firefox\\firefox.exe\" https://www.mozilla.org
Firefox2=explorer Firefox.lnk

[Thread]
MaxThreadCount=0
Expand Down
2 changes: 2 additions & 0 deletions qpp/prefetch/prefetch.pro
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ CONFIG -= app_bundle
HEADERS += \
Source/Core/Thread/read_thread.h \
Source/Core/read_file.h \
Source/Core/startup.h \
Source/Global/global.h \
Source/Output/stdout.h \
Source/Setting/setting.h \
Expand All @@ -18,6 +19,7 @@ HEADERS += \
SOURCES += \
Source/Core/Thread/read_thread.cpp \
Source/Core/read_file.cpp \
Source/Core/startup.cpp \
Source/Global/global.cpp \
Source/Output/stdout.cpp \
Source/Setting/setting.cpp \
Expand Down

0 comments on commit d0044c6

Please sign in to comment.