int GetFileOwner (const char *Computer, const char *Name, char *Owner) { SECURITY_INFORMATION si = OWNER_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION; SECURITY_DESCRIPTOR *sd; char sddata[500]; *Owner=0; sd=(SECURITY_DESCRIPTOR *)sddata; char AnsiName[NM]; OemToChar(Name,AnsiName); SetFileApisToANSI(); DWORD Needed; int GetCode=GetFileSecurity(AnsiName,si,sd,sizeof(sddata),&Needed); SetFileApisToOEM(); if (!GetCode || (Needed>sizeof(sddata))) return(FALSE); PSID pOwner; BOOL OwnerDefaulted; if (!GetSecurityDescriptorOwner(sd,&pOwner,&OwnerDefaulted)) return(FALSE); char AccountName[200],DomainName[200]; DWORD AccountLength=sizeof(AccountName),DomainLength=sizeof(DomainName); SID_NAME_USE snu; if (!LookupAccountSid(Computer,pOwner,AccountName,&AccountLength,DomainName,&DomainLength,&snu)) return(FALSE); CharToOem(AccountName,Owner); return(TRUE); }
void ConvertNameToShort(const char *Src,char *Dest) { char ShortName[NM],AnsiName[NM]; SetFileApisToANSI(); OemToChar(Src,AnsiName); if (GetShortPathName(AnsiName,ShortName,sizeof(ShortName))) CharToOem(ShortName,Dest); else lstrcpy(Dest,Src); SetFileApisToOEM(); }
bool WcxArchive::pExtract( const char *lpDestPath ) { int nProcessed = 0; int nResult = 0; m_files.clear(); while ( nResult == 0 ) { tHeaderData HeaderData; memset (&HeaderData, 0, sizeof (HeaderData)); nResult = m_pModule->m_pfnReadHeader (m_hArchive, &HeaderData); if( nResult!=0 ) continue; char szDestPath[MAX_PATH] = {0}; strcpy(szDestPath, lpDestPath); PathAppendA(szDestPath, HeaderData.FileName); int nProcessResult = 0; if ( (HeaderData.FileAttr & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY ) { CreateDirEx (szDestPath); nProcessResult = m_pModule->m_pfnProcessFile (m_hArchive, PK_SKIP, NULL, NULL); ATLASSERT(FALSE); } else { CreateDirs( szDestPath ); SetFileApisToANSI(); nProcessResult = m_pModule->m_pfnProcessFile (m_hArchive, PK_EXTRACT, NULL, szDestPath); SetFileApisToOEM(); if(!nProcessResult) m_files.push_back( szDestPath ); } if ( !nProcessResult ) nProcessed++; } return nProcessed!=0; }
bool WcxArchive::pOpenArchive( const char *lpFileName, int nOpMode ) { char szFilename[255] = {0}; strcpy(szFilename, lpFileName); tOpenArchiveData OpenArchiveData = {0}; OpenArchiveData.ArcName = szFilename; OpenArchiveData.OpenMode = (nOpMode == 0)?PK_OM_LIST:PK_OM_EXTRACT; SetFileApisToANSI(); m_hArchive = m_pModule->m_pfnOpenArchive (&OpenArchiveData); SetFileApisToOEM(); if(m_hArchive) { if (m_pModule->m_pfnSetProcessDataProc) m_pModule->m_pfnSetProcessDataProc (m_hArchive, ProcessDataProc); if (m_pModule->m_pfnSetChangeVolProc) m_pModule->m_pfnSetChangeVolProc (m_hArchive, ChangeVolProc); } return m_hArchive!=NULL; }
int main(int argc, char **argv) #endif { LPSTR tail; int i; #ifdef WGP_CONSOLE HINSTANCE hInstance = GetModuleHandle(NULL), hPrevInstance = NULL; #endif #ifndef WGP_CONSOLE # if defined( __MINGW32__) && !defined(_W64) # define argc _argc # define argv _argv # else /* MSVC, WATCOM, MINGW-W64 */ # define argc __argc # define argv __argv # endif #endif /* WGP_CONSOLE */ szModuleName = (LPSTR)malloc(MAXSTR+1); CheckMemory(szModuleName); /* get path to EXE */ GetModuleFileName(hInstance, (LPSTR) szModuleName, MAXSTR); if ((tail = (LPSTR)_fstrrchr(szModuleName,'\\')) != (LPSTR)NULL) { tail++; *tail = 0; } szModuleName = (LPSTR)realloc(szModuleName, _fstrlen(szModuleName)+1); CheckMemory(szModuleName); if (_fstrlen(szModuleName) >= 5 && _fstrnicmp(&szModuleName[_fstrlen(szModuleName)-5], "\\bin\\", 5) == 0) { int len = _fstrlen(szModuleName)-4; szPackageDir = (LPSTR)malloc(len+1); CheckMemory(szPackageDir); _fstrncpy(szPackageDir, szModuleName, len); szPackageDir[len] = '\0'; } else szPackageDir = szModuleName; #ifndef WGP_CONSOLE textwin.hInstance = hInstance; textwin.hPrevInstance = hPrevInstance; textwin.nCmdShow = nCmdShow; textwin.Title = "gnuplot"; #endif /* create structure of first graph window */ graphwin = (LPGW) calloc(1, sizeof(GW)); listgraphs = graphwin; /* locate ini file */ { char * inifile; get_user_env(); /* this hasn't been called yet */ inifile = gp_strdup("~\\wgnuplot.ini"); gp_expand_tilde(&inifile); /* if tilde expansion fails use current directory as default - that was the previous default behaviour */ if (inifile[0] == '~') { free(inifile); inifile = "wgnuplot.ini"; } #ifndef WGP_CONSOLE textwin.IniFile = inifile; #endif graphwin->IniFile = inifile; ReadMainIni(inifile, "WGNUPLOT"); } #ifndef WGP_CONSOLE textwin.IniSection = "WGNUPLOT"; textwin.DragPre = "load '"; textwin.DragPost = "'\n"; textwin.lpmw = &menuwin; textwin.ScreenSize.x = 80; textwin.ScreenSize.y = 80; textwin.KeyBufSize = 2048; textwin.CursorFlag = 1; /* scroll to cursor after \n & \r */ textwin.shutdown = MakeProcInstance((FARPROC)ShutDown, hInstance); textwin.AboutText = (LPSTR)malloc(1024); CheckMemory(textwin.AboutText); sprintf(textwin.AboutText, "Version %s patchlevel %s\n" \ "last modified %s\n" \ "%s\n%s, %s and many others\n" \ "gnuplot home: http://www.gnuplot.info\n", gnuplot_version, gnuplot_patchlevel, gnuplot_date, gnuplot_copyright, authors[1], authors[0]); textwin.AboutText = (LPSTR)realloc(textwin.AboutText, _fstrlen(textwin.AboutText)+1); CheckMemory(textwin.AboutText); menuwin.szMenuName = szMenuName; #endif pausewin.hInstance = hInstance; pausewin.hPrevInstance = hPrevInstance; pausewin.Title = "gnuplot pause"; graphwin->hInstance = hInstance; graphwin->hPrevInstance = hPrevInstance; #ifdef WGP_CONSOLE graphwin->lptw = NULL; #else graphwin->lptw = &textwin; #endif /* init common controls */ { INITCOMMONCONTROLSEX initCtrls; initCtrls.dwSize = sizeof(INITCOMMONCONTROLSEX); initCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&initCtrls); } #ifndef WGP_CONSOLE if (TextInit(&textwin)) gp_exit(EXIT_FAILURE); textwin.hIcon = LoadIcon(hInstance, "TEXTICON"); SetClassLongPtr(textwin.hWndParent, GCLP_HICON, (LONG_PTR)textwin.hIcon); /* Note: we want to know whether this is an interactive session so that we can * decide whether or not to write status information to stderr. The old test * for this was to see if (argc > 1) but the addition of optional command line * switches broke this. What we really wanted to know was whether any of the * command line arguments are file names or an explicit in-line "-e command". * (This is a copy of a code snippet from plot.c) */ for (i = 1; i < argc; i++) { if (!stricmp(argv[i], "/noend")) continue; if ((argv[i][0] != '-') || (argv[i][1] == 'e')) { interactive = FALSE; break; } } if (interactive) ShowWindow(textwin.hWndParent, textwin.nCmdShow); if (IsIconic(textwin.hWndParent)) { /* update icon */ RECT rect; GetClientRect(textwin.hWndParent, (LPRECT) &rect); InvalidateRect(textwin.hWndParent, (LPRECT) &rect, 1); UpdateWindow(textwin.hWndParent); } # ifndef __WATCOMC__ /* Finally, also redirect C++ standard output streams. */ RedirectOutputStreams(TRUE); # endif #else /* WGP_CONSOLE */ #ifdef CONSOLE_SWITCH_CP /* Change codepage of console to match that of the graph window. WinExit() will revert this. Attention: display of characters does not work correctly with "Terminal" font! Users will have to use "Lucida Console" or similar. */ cp_input = GetConsoleCP(); cp_output = GetConsoleOutputCP(); if (cp_input != GetACP()) { cp_changed = TRUE; SetConsoleCP(GetACP()); /* keyboard input */ SetConsoleOutputCP(GetACP()); /* screen output */ SetFileApisToANSI(); /* file names etc. */ } #endif #endif gp_atexit(WinExit); if (!isatty(fileno(stdin))) setmode(fileno(stdin), O_BINARY); gnu_main(argc, argv); /* First chance to close help system for console gnuplot, second for wgnuplot */ WinCloseHelp(); gp_exit_cleanup(); return 0; }
int main(int argc, char **argv) #endif { /*WNDCLASS wndclass;*/ LPSTR tail; #ifdef WGP_CONSOLE # define _argv argv # define _argc argc HINSTANCE hInstance = GetModuleHandle(NULL), hPrevInstance = NULL; #else #if defined(__MSC__) || defined(__WATCOMC__) # define _argv __argv # define _argc __argc #endif #endif /* WGP_CONSOLE */ szModuleName = (LPSTR)malloc(MAXSTR+1); CheckMemory(szModuleName); /* get path to EXE */ GetModuleFileName(hInstance, (LPSTR) szModuleName, MAXSTR); if ((tail = (LPSTR)_fstrrchr(szModuleName,'\\')) != (LPSTR)NULL) { tail++; *tail = 0; } szModuleName = (LPSTR)realloc(szModuleName, _fstrlen(szModuleName)+1); CheckMemory(szModuleName); if (_fstrlen(szModuleName) >= 5 && _fstrnicmp(&szModuleName[_fstrlen(szModuleName)-5], "\\bin\\", 5) == 0) { int len = _fstrlen(szModuleName)-4; szPackageDir = (LPSTR)malloc(len+1); CheckMemory(szPackageDir); _fstrncpy(szPackageDir, szModuleName, len); szPackageDir[len] = '\0'; } else szPackageDir = szModuleName; #ifndef WGP_CONSOLE textwin.hInstance = hInstance; textwin.hPrevInstance = hPrevInstance; textwin.nCmdShow = nCmdShow; textwin.Title = "gnuplot"; #endif /* create structure of first graph window */ graphwin = calloc(1, sizeof(GW)); listgraphs = graphwin; /* locate ini file */ { char * inifile; get_user_env(); /* this hasn't been called yet */ inifile = gp_strdup("~\\wgnuplot.ini"); gp_expand_tilde(&inifile); /* if tilde expansion fails use current directory as default - that was the previous default behaviour */ if (inifile[0] == '~') { free(inifile); inifile = "wgnuplot.ini"; } #ifndef WGP_CONSOLE textwin.IniFile = inifile; #endif graphwin->IniFile = inifile; ReadMainIni(inifile, "WGNUPLOT"); } #ifndef WGP_CONSOLE textwin.IniSection = "WGNUPLOT"; textwin.DragPre = "load '"; textwin.DragPost = "'\n"; textwin.lpmw = &menuwin; textwin.ScreenSize.x = 80; textwin.ScreenSize.y = 80; textwin.KeyBufSize = 2048; textwin.CursorFlag = 1; /* scroll to cursor after \n & \r */ textwin.shutdown = MakeProcInstance((FARPROC)ShutDown, hInstance); textwin.AboutText = (LPSTR)malloc(1024); CheckMemory(textwin.AboutText); sprintf(textwin.AboutText, "Version %s patchlevel %s\n" \ "last modified %s\n" \ "%s\n%s, %s and many others\n" \ "gnuplot home: http://www.gnuplot.info\n", gnuplot_version, gnuplot_patchlevel, gnuplot_date, gnuplot_copyright, authors[1], authors[0]); textwin.AboutText = (LPSTR)realloc(textwin.AboutText, _fstrlen(textwin.AboutText)+1); CheckMemory(textwin.AboutText); menuwin.szMenuName = szMenuName; #endif pausewin.hInstance = hInstance; pausewin.hPrevInstance = hPrevInstance; pausewin.Title = "gnuplot pause"; graphwin->hInstance = hInstance; graphwin->hPrevInstance = hPrevInstance; #ifdef WGP_CONSOLE graphwin->lptw = NULL; #else graphwin->lptw = &textwin; #endif /* init common controls */ { INITCOMMONCONTROLSEX initCtrls; initCtrls.dwSize = sizeof(INITCOMMONCONTROLSEX); initCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&initCtrls); } #ifndef WGP_CONSOLE if (TextInit(&textwin)) exit(1); textwin.hIcon = LoadIcon(hInstance, "TEXTICON"); SetClassLong(textwin.hWndParent, GCL_HICON, (DWORD)textwin.hIcon); if (_argc>1) { int i,noend=FALSE; for (i=0; i<_argc; ++i) if (!stricmp(_argv[i],"-noend") || !stricmp(_argv[i],"/noend") || !stricmp(_argv[i],"-persist")) noend = TRUE; if (noend) ShowWindow(textwin.hWndParent, textwin.nCmdShow); } else ShowWindow(textwin.hWndParent, textwin.nCmdShow); if (IsIconic(textwin.hWndParent)) { /* update icon */ RECT rect; GetClientRect(textwin.hWndParent, (LPRECT) &rect); InvalidateRect(textwin.hWndParent, (LPRECT) &rect, 1); UpdateWindow(textwin.hWndParent); } #else /* WGP_CONSOLE */ #ifdef CONSOLE_SWITCH_CP /* Change codepage of console to match that of the graph window. WinExit() will revert this. Attention: display of characters does not work correctly with "Terminal" font! Users will have to use "Lucida Console" or similar. */ cp_input = GetConsoleCP(); cp_output = GetConsoleOutputCP(); if (cp_input != GetACP()) { cp_changed = TRUE; SetConsoleCP(GetACP()); /* keyboard input */ SetConsoleOutputCP(GetACP()); /* screen output */ SetFileApisToANSI(); /* file names etc. */ } #endif #endif atexit(WinExit); if (!isatty(fileno(stdin))) setmode(fileno(stdin), O_BINARY); gnu_main(_argc, _argv, environ); /* First chance to close help system for console gnuplot, second for wgnuplot */ WinCloseHelp(); return 0; }
virtual void Epilogue() override { OEMApiCnt--; if(!OEMApiCnt) SetFileApisToANSI(); }