- Rearrange reactos.dff according to rosapps rearrange.
[reactos.git] / rosapps / applications / 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>\n", 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 // write the head
57 fputs("<h2>ReactOS Package Manager - Log File</h2>\n", file);
58 //fputs("WARNING: This is still pre-alpha software.<br>\n", file);
59
60 fputs("Date: ", file);
61 fputs(GTime, file);
62 fputs("<br>\n", file);
63
64 fputs("Version: ", file);
65 fputs(version, file);
66 fputs("<br>\n", file);
67
68 fputs("OS: ", file);
69 fputs(versionos, file);
70 fputs("<br>\n", file);
71 }
72
73 else
74 file = fopen(LOGFILE, "a");
75
76 if (file == NULL)
77 {
78 if (LogCreated)
79 LogCreated = false;
80
81 return Log(message);
82 }
83
84 else
85 {
86 // Save log entry (+ add time)
87 fputs("<br>\n", file);
88
89 time_t now;
90 now = time(NULL);
91 strftime(GTime,sizeof GTime,"%I:%M:%S %p",localtime(&now));
92
93 fputs("<b>", file);
94 fputs(GTime, file);
95 fputs("</b> ", file);
96
97 fputs(message, file);
98 fclose(file);
99 }
100
101 if (file)
102 fclose(file);
103 }
104
105 void LogAdd (const char *message)
106 {
107 FILE *file;
108
109 file = fopen(LOGFILE, "a");
110
111 // Save log entry
112 fputs(message, file);
113 fclose(file);
114
115 if (file)
116 fclose(file);
117 }