Menu

[r7]: / commonfunctions.cpp  Maximize  Restore  History

Download this file

144 lines (123 with data), 3.3 kB

  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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <wx/filename.h>
#include <wx/listimpl.cpp>
#include <wx/arrimpl.cpp>
#include <wx/tokenzr.h>
#include <wx/buffer.h>
#include <sys/stat.h>
#include <wx/encconv.h>
#include <errno.h>
#include "declarations.h"
#include "commonfunctions.h"
#include "dll/gcomp.h"
wxEncodingConverter CP1251ToUnicodeConv, UnicodeToCP1251Conv;
wxEncodingConverter u2utf, utf2u;
WX_DEFINE_LIST(wxPtrList);
WX_DEFINE_OBJARRAY(wxPtrArray);
bool IsValidFileName(const wxString& String)
{
wxFileName fname(String);
return fname.IsOk();
}
wxArrayString SplitPath(const wxString& Path)
{
return wxStringTokenize(Path, _U("/"));
}
void CopyFile(FILE* dest, FILE* src)
{
char buf[1024];
rewind(src);
rewind(dest);
while( !feof(src) )
{
int read = fread(buf, 1, sizeof(buf), src);
fwrite(buf, 1, read, dest);
}
}
bool IsIgnoredFolder(const wxString& FileName)
{
if( !FileName.Cmp(_U(".")) ) return true;
if( !FileName.Cmp(_U("..")) ) return true;
return false;
}
bool IsIgnoredFile(const wxString& FileName)
{
if( !FileName.CmpNoCase(_U("CVS")) ) return true;
if( !FileName.CmpNoCase(_U(".svn")) ) return true;
if( !FileName.CmpNoCase(_U("ChangeLog")) ) return true;
if( !FileName.CmpNoCase(_U("gcomp.ini")) ) return true;
return IsIgnoredFolder(FileName);
}
//Меняет все нежелательные буквы на '_'. Замена производится прямо в строке
int MangleFileName(wxString& str)
{
wxString forbidden = wxFileName::GetForbiddenChars();
int repl_count = 0;
for(uint ch=0;ch<forbidden.Len();ch++) repl_count+=((wxString)str).Replace(forbidden.Mid(ch, 1), _U("_"));
return repl_count;
}
wxString Suffix(const wxString& str)
{
wxFileName fname(str);
return fname.GetExt();
}
void SystemErrorMessage()
{
/* char *ErrMsg = NULL;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
ErrMsg,
0, NULL);
printf(ErrMsg);
fflush(stdout);
LocalFree(ErrMsg);
*/
}
void Msg(int MinimalVerbosityLevel, const wxString& msg, ...)
{
wxString ConvertedMsg;
va_list ap;
va_start(ap, msg);
ConvertedMsg.PrintfV(msg, ap);
va_end(ap);
time_t t;
wxLog::GetActiveTarget()->OnLog(MinimalVerbosityLevel, ConvertedMsg, t);
}
void PrintTime()
{
wxDateTime Time = wxDateTime::Now();
Msg(0, _U("Time: %s"), Time.Format(_U("%H:%M:%S")).c_str());
}
void InitConv()
{
//it's a fuck
CP1251ToUnicodeConv.Init(wxFONTENCODING_CP1251, wxFONTENCODING_UNICODE);
UnicodeToCP1251Conv.Init(wxFONTENCODING_UNICODE, wxFONTENCODING_CP1251);
}
wxString CP1251ToUnicode(const wxString& str)
{
return CP1251ToUnicodeConv.Convert(str);
}
wxString UnicodeToCP1251(const wxString& str)
{
return UnicodeToCP1251Conv.Convert(str);
}
void wxLogConsole::DoLog(wxLogLevel level, const wxChar *szString, time_t t)
{
if(level>GetLogLevel()) return;
DoLogString(szString, t);
}
void wxLogConsole::DoLogString(const wxChar *szString, time_t t)
{
wxString tstr;
TimeStamp(&tstr);
tstr += szString;
#ifndef __WXMSW__
printf("%s\n", (char*)tstr.char_str(wxConvUTF8));
#else
tstr = wxString(tstr.utf8_str(), wxConvUTF8);
tstr = UnicodeToCP1251(tstr);
printf("%s\n", (char*)tstr.char_str(wxConvLocal));
#endif
}