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

Diff of /trunk/gr2lib_cpp/GrannyAPILogger.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.7  
changed lines
  Added in v.12

  ViewVC Help
Powered by ViewVC 1.1.22