-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjob control.cpp
executable file
·99 lines (75 loc) · 2.65 KB
/
job control.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Include statements
#include <windows.h>
#include <windef.h>
#include <atlstr.h>
#include <shlobj.h>
#include "resource.h"
#include "program.h"
#include "class.h"
#include "function.h"
// Global objects
extern handleitem Handle;
jobitem Job; // Make the job object here
// Reset the program to let the user prepare the job
void JobReset() { sectionitem section;
// Change the stage
if (Job.stage == JobStageRunning) return; // Can only reset when before or done
// Initialize job information
Job.stage = JobStageBefore;
Job.stop = false;
Job.time = 0;
Job.tasks = L"";
Job.task = Job.errors = L"";
Job.error = 0;
Job.folder = Job.file = Job.compare = 0;
Job.foldererror = Job.fileerror = Job.compareerror = 0;
Job.log = Job.hash = NULL;
// Load tasks text from the registry to the tasks box
string s = RegistryRead(REGISTRYKEY, REGISTRYPATH, REGISTRYNAME);
WindowTextSet(Handle.tasks, s);
}
// Start the job, locking down the program while it runs
void JobStart() { sectionitem section;
// Change the stage
if (Job.stage != JobStageBefore) return; // Can only start when before
Job.stage = JobStageRunning;
// Record the time now as when the job starts
Job.time = GetTickCount();
// Save tasks text from the tasks box to the registry
Job.tasks = WindowTextGet(Handle.tasks);
RegistryWrite(REGISTRYKEY, REGISTRYPATH, REGISTRYNAME, Job.tasks);
// Delete the log file from last time and open a new one
string s = LogPath(L"Backup");
DiskDeleteFile(s);
Job.log = LogOpen(s, L"Errors");
// Start a new thread that will perform all the tasks
BeginThread(Tasks); // Have the thread run the Tasks() function
}
// Check to see if the job should stop
bool JobContinue() { sectionitem section;
// Check the stage
if (Job.stage != JobStageRunning) return false; // Should only be used when running
// Return false to make the caller not do the next task
return !Job.stop;
}
// Stop the job now, while it's running
void JobStop() { sectionitem section;
// Check the stage
if (Job.stage != JobStageRunning) return; // Can only stop when running
// Record an error that we stopped it
JobError(L"Stopped");
// Set the flag for the thread to see
Job.stop = true;
}
// The job is done
void JobDone() { sectionitem section;
// Change the stage
if (Job.stage != JobStageRunning) return; // Can only stop when running
Job.stage = JobStageDone;
// Calculate how long the job took
Job.time = GetTickCount() - Job.time;
// Clear the last task it did, this would show up in status
JobTask(L"");
// Write the footer and close the error log file
LogClose(Job.log);
}