/[Sims3RigEditor]/trunk/gr2lib_cpp/GrannyAPILogger.cpp
ViewVC logotype

Annotation of /trunk/gr2lib_cpp/GrannyAPILogger.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 55 - (hide annotations) (download)
Thu Aug 12 08:37:47 2010 UTC (10 years, 2 months ago) by william
File size: 3560 byte(s)
Fix all, current, c++ compiler warnings and linker errors

1 william 55 #define _CRT_SECURE_NO_WARNINGS
2 william 6 #include "StdAfx.h"
3     #include "GrannyAPILogger.h"
4 william 12 #include "guicon.h"
5     #include "VSDebugOutput.h"
6     #include <sys/stat.h>
7     #include <ostream>
8     #include <sstream>
9     #include <string>
10     using namespace System::Runtime::InteropServices;
11 william 7 void __cdecl Callback(granny_log_message_type Type, granny_log_message_origin Origin, char const * Message, void * UserData);
12    
13 william 6 GrannyAPILogger::GrannyAPILogger(void)
14     {
15     granny_log_callback NewCallback;
16 william 7 NewCallback.Function = Callback;
17     NewCallback.UserData = NULL;
18 william 12 // set Granny2 log function
19 william 7 GrannySetLogCallback(&NewCallback);
20 william 6 }
21 william 12 void GrannyAPILogger::SetLogFileName(const char* filename)
22     {
23     System::IO::FileInfo^ fs = gcnew System::IO::FileInfo(gcnew System::String(filename));
24     //System::String^ _filename_no_ext = fs->Name->Remove( fs->Name->Length - fs->Extension->Length);
25 william 13 const char* _const_filename_no_ext = (char*)(void*)Marshal::StringToHGlobalAnsi(fs->FullName->ToLower());
26 william 12 const char* log_suffix = ".log";
27     int msg_malloc = (strlen(_const_filename_no_ext) + strlen(log_suffix));
28 william 6
29 william 12 char* msg = (char*)malloc(msg_malloc);
30     for (int i=0; i<msg_malloc; i++) {
31     msg[i] = 0; // Initialize all elements to zero.
32     }
33    
34     strcat(msg,_const_filename_no_ext);
35     strcat(msg,log_suffix);
36     // set Granny2 log file
37     GrannySetLogFileName(msg,true);
38     }
39     void GrannyAPILogger::SetLogFileName(const char* logpath,const char* filename)
40     {
41    
42     if (!System::IO::Directory::Exists(gcnew System::String(logpath)))
43     {
44     System::IO::Directory::CreateDirectory(gcnew System::String(logpath));
45     }
46    
47     System::IO::FileInfo^ fs = gcnew System::IO::FileInfo(gcnew System::String(filename));
48     //System::String^ _filename_no_ext = fs->Name->Remove( fs->Name->Length - fs->Extension->Length);
49     const char* _const_filename_no_ext = (char*)(void*)Marshal::StringToHGlobalAnsi(fs->Name->ToLower());
50     const char* log_suffix = ".log";
51     int msg_malloc = (strlen(logpath) + strlen(_const_filename_no_ext) + strlen(log_suffix));
52    
53     char* msg = (char*)malloc(msg_malloc);
54     for (int i=0; i<msg_malloc; i++) {
55     msg[i] = 0; // Initialize all elements to zero.
56     }
57     strcat(msg,logpath);
58     strcat(msg,"\\");
59     strcat(msg,_const_filename_no_ext);
60     strcat(msg,log_suffix);
61     // set Granny2 log file
62     GrannySetLogFileName(msg,true);
63     }
64 william 7 void __cdecl Callback(granny_log_message_type Type, granny_log_message_origin Origin, char const * Message, void * UserData)
65 william 6 {
66 william 12 char const* TypeString = GrannyGetLogMessageTypeString(Type);
67     char const* OriginString = GrannyGetLogMessageOriginString(Origin);
68    
69 william 55 void* data = UserData;
70     if(data == NULL){}
71 william 12 printf("\n\n\tGranny2 API Logger: Logging Granny2 Message ->\n\t\tMessage Log Type: %s\n\t\tMessage Log Origin: %s\n\t\tMessage: %s",
72     TypeString,
73     OriginString,
74     Message);
75    
76     VSDebugWriterW VSDebugWriter;
77    
78     VSDebugWriter
79     << "\n\n\tGranny2 API Logger: Logging Granny2 Message ->"
80     << "\n\t\tMessage Log Type: " << TypeString
81     << "\n\t\tMessage Log Origin: " << OriginString
82     << "\n\t\tMessage: " << Message;
83     }
84    
85     void GrannyAPILogger::LogMessage(const char* Message)
86     {
87     //printf("\n\tGranny2 API Logger: Logging Application Message ->\n\t\tMessage: %s",Message);
88     printf("\n\t%s",Message);
89    
90     VSDebugWriterW VSDebugWriter;
91    
92     VSDebugWriter << "\n\t" << Message;
93     /*<< "\n\tGranny2 API Logger: Application Message ->"
94     << "\n\t\tMessage: " << Message;*/
95     }
96     void GrannyAPILogger::LogDebugMessageOnly(const char* Message)
97     {
98     VSDebugWriterW VSDebugWriter;
99     VSDebugWriter << Message;
100     }

  ViewVC Help
Powered by ViewVC 1.1.22