OSDN Git Service

名前登録機能追加
[nlite/nlite.git] / nlite / nlite_common.cpp
1 #include "stdafx.h"
2 #include "nlite_include.h"
3
4
5
6 namespace nlite{
7
8 namespace nliteregex{
9         namespace text{
10                 const  CString URL_TEXT = TEXT("(https?|ftp)(://[-_.!~*\'()a-zA-Z0-9;/?:@&=+$,%#]+)");
11                 const  CString TAG_TEXT = TEXT("<[\"_;!?,\\:.'$%&#/a-zA-Z0-9= ]*>");
12                 const  CString VIDEOID_TEXT = TEXT("(sm|nm)([0-9])+");
13                 const  CString LIVEID_TEXT = TEXT("(lv)([0-9])+");
14                 const  CString LINK_TEXT = TEXT("(") + URL_TEXT + TEXT(")|(") + VIDEOID_TEXT + TEXT(")|(") + LIVEID_TEXT + TEXT(")");
15                 const  CString SEARTCH_AT_MARK(TEXT("(.*)(@|\81\97)([^@^\81\97]+)"));
16                 const  tstring NUTHINGSTRING(TEXT(""));
17         }
18         const  tregex URL(text::URL_TEXT);
19         const  tregex TAGSTRING(text::TAG_TEXT);
20         const  tregex VIDEOID(text::VIDEOID_TEXT);
21         const  tregex LIVEID(text::LIVEID_TEXT);
22         const  tregex LILNKREGEX(text::LINK_TEXT);
23         const tregex NAMESERTCHREGEX(text::SEARTCH_AT_MARK);
24 }
25 Property nliteProperty; 
26 CListenerList nlite::listenerList;
27 TCHAR appFolderPath[_MAX_PATH];
28 CString ncvAppSettingPath;
29 TCHAR localAppDataPath[_MAX_PATH];
30
31  VOID nlite::UnexpectedErrorMessageShow(LPCTSTR headMessage,LPCTSTR summary,UINT line,LPCTSTR fileName,LPCTSTR function){
32         tstring errMessage;
33         errMessage = headMessage;
34         errMessage += TEXT("\91z\92è\82³\82ê\82Ä\82¢\82È\82¢\83G\83\89\81[\82ª\94­\90\82µ\82Ü\82µ\82½\81B\83A\83v\83\8a\83P\81[\83V\83\87\83\93\94z\92u\83t\83H\83\8b\83_\82É\8dì\90¬\82³\82ê\82½\83\8d\83O\83t\83@\83C\83\8b\82ð\93n\82µ\82Ä\82à\82ç\82¦\82é\82Æ\8aJ\94­\8eÒ\82ª\94ñ\8fí\82É\8aì\82Ñ\82Ü\82·");
35         errMessage += TEXT("\r\n\83G\83\89\81[\83\81\83b\83Z\81[\83W:");
36         errMessage += summary;
37         DebugOutW(fileName,function,line,DUMPING__DEBUGER__ | LINEFEAD__DEBUGER__ ,ERRORMODE__DEBUGER__,TEXT("%s"),summary);
38         ::MessageBox(NULL,errMessage.c_str(),TEXT("\91z\92è\82³\82ê\82Ä\82¢\82È\82¢\83G\83\89\81["),MB_ICONERROR | MB_OK);
39         
40
41
42          return;
43  }
44
45  HINSTANCE OpenURL(HWND hwnd,const GeneralProperty &gp,LPCTSTR url ,INT nShowCommand){
46
47          HINSTANCE rslt;
48
49         if(gp.browserPath.Length() == 0){
50
51                 rslt = ShellExecute(hwnd, NULL, url, NULL, NULL, nShowCommand);
52
53         } else{
54
55                 rslt = ShellExecute(hwnd, NULL, gp.browserPath, url, NULL, nShowCommand);
56
57         }
58
59         return rslt;
60
61  }
62
63  BOOL SurelyCreate(LPCTSTR dir,BOOL bFile){
64
65          
66
67          BOOL rslt = FALSE;
68          std::vector<TCHAR> buf(_tcslen(dir) + 1);
69          _tcscpy(&buf[0],dir);
70
71
72          if( (PathFileExists(dir) && (!bFile || !::PathIsDirectory( dir )))){
73
74                  goto success;
75          }
76
77          LPTSTR startPtr = &buf[0];
78          LPTSTR indexPtr = startPtr;
79          LPTSTR cmpPtr;
80          do {
81
82                  cmpPtr = _tcsstr(indexPtr,TEXT("\\"));
83
84                  if(cmpPtr == NULL){
85                         
86                          if(bFile == TRUE){
87                                 CAtlFile file;
88                                 if( file.Create(startPtr,0,0,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL) != S_OK){
89
90                                         goto err;
91
92                                 }
93                          } else {
94
95                                  ::CreateDirectory(startPtr,0);
96                          }
97
98                          break;
99
100
101                  }else if(indexPtr == cmpPtr){
102                          break;
103
104                  }
105
106                  cmpPtr[0] = TEXT('\0');
107                  ::CreateDirectory(startPtr,0);
108                  cmpPtr[0] = TEXT('\\');
109                  cmpPtr++;
110                  indexPtr = cmpPtr;
111                  
112
113          }while(indexPtr[0] != TEXT('\0'));
114
115 success:
116
117
118          rslt = TRUE;
119
120 end:
121
122          return rslt;
123
124
125 err:
126          rslt = FALSE;
127          goto end;
128  }
129
130
131 ///
132 ///NCV\83\86\81[\83U\8fî\95ñ\83t\83@\83C\83\8b\83p\83X\8eæ\93¾XML\83p\81[\83T
133 ///
134 class CReadNCVListenerInfoFile:public CXmlParser{
135
136 private:
137         
138         BOOL settingDirFlag;
139         CString &path;  
140                 
141                 
142
143
144 public:
145
146         CReadNCVListenerInfoFile(CString &in_path):settingDirFlag(FALSE),path(in_path){}
147
148         void OnStartElement (const XML_Char *pszName, const XML_Char **papszAttrs){
149
150                 if(_tcscmp(pszName,TEXT("SettingDir")) == 0){
151
152                         settingDirFlag = TRUE;
153
154                 }
155
156         }
157
158         void OnEndElement (const XML_Char *pszName){
159
160                 if(_tcscmp(pszName,TEXT("SettingDir")) == 0){
161
162                         settingDirFlag = FALSE;
163
164                 }
165
166         }
167
168         void OnCharacterData (const XML_Char *pszData, int nLength){
169
170                 if(settingDirFlag == TRUE){
171
172                         path.Append(pszData,nLength);
173
174                 }
175
176         }
177 };
178
179  CString GetNCVListenerInfoFilePath(){
180
181         
182         CString rslt;
183         
184
185         if((PathFileExists(ncvAppSettingPath) &&  (!::PathIsDirectory( ncvAppSettingPath )))){
186
187                 
188                 CAtlFile ncvAppSettingFile;
189                 ULONGLONG ncvAppSettingFileSize = 0;
190                 if(SUCCEEDED(ncvAppSettingFile.Create(ncvAppSettingPath,GENERIC_READ,FILE_SHARE_READ,OPEN_ALWAYS)) == FALSE ||
191                         SUCCEEDED(ncvAppSettingFile.GetSize(ncvAppSettingFileSize)) == FALSE){
192
193                                 throw Exception(TEXT("NCV\82Ì\90Ý\92è\83t\83@\83C\83\8b\82ª\93Ç\82Ý\8d\9e\82ß\82Ü\82¹\82ñ\82Å\82µ\82½"),__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
194
195                 }
196                 std::vector<char> fileBuf(static_cast<UINT_PTR>(ncvAppSettingFileSize) / sizeof(char) + (1 * sizeof(char)));
197                 ncvAppSettingFile.Read(&fileBuf[0],fileBuf.size());
198                 LPSTR startPtr = strstr(&fileBuf[0],"<");
199                 if(startPtr != NULL){
200                         CReadNCVListenerInfoFile parser(rslt);
201                         parser.Parse(startPtr);
202                         rslt += TEXT("UserSetting.xml");
203
204                 }
205
206         }
207
208
209
210
211         return rslt;
212  }
213
214 const CApplicationInfo * appInfo = NULL;
215
216 }