PackageManager: HTML Log
[reactos.git] / rosapps / packmgr / lib / log.cpp
1 ////////////////////////////////////////////////////////
2 //
3 // log.cpp
4 //
5 // Script Functions
6 //
7 //
8 // Klemens Friedl, 19.03.2005
9 // frik85@hotmail.com
10 //
11 ////////////////////////////////////////////////////////////////////
12
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <time.h>
16 #include <windows.h>
17
18 #include "log.h"
19 #include "package.hpp" // for Package Manager version
20 #include <reactos/version.h> // ReactOS version: \reactos\include\reactos\version.h
21
22 bool LogCreated = false;
23
24 void Log (const char *message)
25 {
26 FILE *file;
27 char GTime[80];
28 char version[50];
29 char versionos[50];
30
31 if (!LogCreated)
32 {
33 file = fopen(LOGFILE, "w");
34 LogCreated = true;
35
36 //HTML Header
37 fputs("<html><head><title>Logfile</title></head><body>", file);
38
39 // date and time
40 time_t now;
41 now = time(NULL);
42 strftime(GTime,sizeof GTime,"%Y-%m-%d",localtime(&now));
43
44 // package manager version information
45 wsprintfA(version, " Package Manager %d.%d.%d",
46 PACKMGR_VERSION_MAJOR,
47 PACKMGR_VERSION_MINOR,
48 PACKMGR_VERSION_PATCH_LEVEL);
49
50 // operating system version information
51 wsprintfA(versionos, " ReactOS %d.%d.%d",
52 KERNEL_VERSION_MAJOR,
53 KERNEL_VERSION_MINOR,
54 KERNEL_VERSION_PATCH_LEVEL);
55
56 fputs("<h2>ReactOS Package Manager - Log File</h2><br>\n", file);
57 fputs("WARNING: This is still pre-alpha software.<br>\n", file);
58
59 fputs("Date: ", file);
60 fputs(GTime, file);
61 fputs("<br>\n", file);
62
63 fputs(version, file);
64 fputs("<br>\n", file);
65 fputs(versionos, file);
66 fputs("<br>\n", file);
67 }
68
69 else
70 file = fopen(LOGFILE, "a");
71
72 if (file == NULL)
73 {
74 if (LogCreated)
75 LogCreated = false;
76
77 return Log(message);
78 }
79
80 else
81 {
82 // Save log entry (+ add time)
83 fputs("<br>\n", file);
84
85 time_t now;
86 now = time(NULL);
87 strftime(GTime,sizeof GTime,"%I:%M:%S %p ",localtime(&now));
88
89 fputs("<b>", file);
90 fputs(GTime, file);
91 fputs("</b>", file);
92
93 fputs(message, file);
94 fclose(file);
95 }
96
97 if (file)
98 fclose(file);
99 }
100
101 void LogAdd (const char *message)
102 {
103 FILE *file;
104
105 file = fopen(LOGFILE, "a");
106
107 // Save log entry
108 fputs(message, file);
109 fclose(file);
110
111 if (file)
112 fclose(file);
113 }