A PHP Error was encountered

Severity: 8192

Message: Function create_function() is deprecated

Filename: geshi/geshi.php

Line Number: 4698

Backtrace:

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 4698
Function: _error_handler

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 4621
Function: _optimize_regexp_list_tokens_to_string

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 1655
Function: optimize_regexp_list

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 2029
Function: optimize_keyword_group

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 2168
Function: build_parse_cache

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/Process.php
Line: 45
Function: parse_code

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/models/Pastes.php
Line: 517
Function: syntax

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/controllers/Main.php
Line: 693
Function: getPaste

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/index.php
Line: 315
Function: require_once

Untitled - Stikked
From Social Sloth, 9 Years ago, written in C++.
Embed
  1. #include "stdafx.h"
  2. #include "gyazowin.h"
  3.  
  4.  
  5. HINSTANCE hInst;
  6. TCHAR *szTitle                  = _T("Gyazo");
  7. TCHAR *szWindowClass    = _T("GYAZOWIN");
  8. TCHAR *szWindowClassL   = _T("GYAZOWINL");
  9. HWND hLayerWnd;
  10.  
  11. int ofX, ofY;
  12.  
  13.  
  14. ATOM                            MyRegisterClass(HINSTANCE hInstance);
  15. BOOL                            InitInstance(HINSTANCE, int);
  16. LRESULT CALLBACK        WndProc(HWND, UINT, WPARAM, LPARAM);
  17. LRESULT CALLBACK        LayerWndProc(HWND, UINT, WPARAM, LPARAM);
  18.  
  19. int                                     GetEncoderClsid(const WCHAR* format, CLSID* pClsid);
  20.  
  21. BOOL                            isPng(LPCTSTR fileName);
  22. VOID                            drawRubberband(HDC hdc, LPRECT newRect, BOOL erase);
  23. VOID                            execUrl(const char* str);
  24. VOID                            setClipBoardText(const char* str);
  25. BOOL                            convertPNG(LPCTSTR destFile, LPCTSTR srcFile);
  26. BOOL                            savePNG(LPCTSTR fileName, HBITMAP newBMP);
  27. BOOL                            uploadFile(HWND hwnd, LPCTSTR fileName);
  28. std::string                     getId();
  29. BOOL                            saveId(const WCHAR* str);
  30.  
  31. int APIENTRY _tWinMain(HINSTANCE hInstance,
  32.                      HINSTANCE hPrevInstance,
  33.                      LPTSTR    lpCmdLine,
  34.                      int       nCmdShow)
  35. {
  36.         UNREFERENCED_PARAMETER(hPrevInstance);
  37.         UNREFERENCED_PARAMETER(lpCmdLine);
  38.  
  39.         MSG msg;
  40.  
  41.         TCHAR   szThisPath[MAX_PATH];
  42.         DWORD   sLen;
  43.  
  44.  
  45.         sLen = GetModuleFileName(NULL, szThisPath, MAX_PATH);
  46.         for(unsigned int i = sLen; i >= 0; i--) {
  47.                 if(szThisPath[i] == _T('\\')) {
  48.                         szThisPath[i] = _T('\0');
  49.                         break;
  50.                 }
  51.         }
  52.  
  53.         SetCurrentDirectory(szThisPath);
  54.  
  55.  
  56.         if ( 2 == __argc )
  57.         {
  58.  
  59.                 if (isPng(__targv[1])) {
  60.  
  61.                         uploadFile(NULL, __targv[1]);
  62.                 }else {
  63.  
  64.                         TCHAR tmpDir[MAX_PATH], tmpFile[MAX_PATH];
  65.                         GetTempPath(MAX_PATH, tmpDir);
  66.                         GetTempFileName(tmpDir, _T("gya"), 0, tmpFile);
  67.                        
  68.                         if (convertPNG(tmpFile, __targv[1])) {
  69.  
  70.                                 uploadFile(NULL, tmpFile);
  71.                         } else {
  72.  
  73.                                 MessageBox(NULL, _T("Cannot convert this image"), szTitle,
  74.                                         MB_OK | MB_ICONERROR);
  75.                         }
  76.                         DeleteFile(tmpFile);
  77.                 }
  78.                 return TRUE;
  79.         }
  80.  
  81.  
  82.         MyRegisterClass(hInstance);
  83.  
  84.  
  85.         if (!InitInstance (hInstance, nCmdShow))
  86.         {
  87.                 return FALSE;
  88.         }
  89.  
  90.         while (GetMessage(&msg, NULL, 0, 0))
  91.         {
  92.                 TranslateMessage(&msg);
  93.                 DispatchMessage(&msg);
  94.         }
  95.  
  96.         return (int) msg.wParam;
  97. }
  98.  
  99.  
  100. BOOL isPng(LPCTSTR fileName)
  101. {
  102.         unsigned char pngHead[] = { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A };
  103.         unsigned char readHead[8];
  104.        
  105.         FILE *fp = NULL;
  106.        
  107.         if (0 != _tfopen_s(&fp, fileName, _T("rb")) ||
  108.                 8 != fread(readHead, 1, 8, fp)) {
  109.  
  110.                 return FALSE;
  111.         }
  112.         fclose(fp);
  113.  
  114.         for(unsigned int i=0;i<8;i++)
  115.                 if(pngHead[i] != readHead[i]) return FALSE;
  116.  
  117.         return TRUE;
  118.  
  119. }
  120.  
  121.  
  122. ATOM MyRegisterClass(HINSTANCE hInstance)
  123. {
  124.         WNDCLASS wc;
  125.  
  126.  
  127.         wc.style         = 0;                                  
  128.         wc.lpfnWndProc   = WndProc;
  129.         wc.cbClsExtra    = 0;
  130.         wc.cbWndExtra    = 0;
  131.         wc.hInstance     = hInstance;
  132.         wc.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_GYAZOWIN));
  133.         wc.hCursor       = LoadCursor(NULL, IDC_CROSS);
  134.         wc.hbrBackground = 0;
  135.         wc.lpszMenuName  = 0;
  136.         wc.lpszClassName = szWindowClass;
  137.  
  138.         RegisterClass(&wc);
  139.  
  140.  
  141.         wc.style         = CS_HREDRAW | CS_VREDRAW;
  142.         wc.lpfnWndProc   = LayerWndProc;
  143.         wc.cbClsExtra    = 0;
  144.         wc.cbWndExtra    = 0;
  145.         wc.hInstance     = hInstance;
  146.         wc.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_GYAZOWIN));
  147.         wc.hCursor       = LoadCursor(NULL, IDC_CROSS);
  148.         wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  149.         wc.lpszMenuName  = 0;
  150.         wc.lpszClassName = szWindowClassL;
  151.  
  152.         return RegisterClass(&wc);
  153. }
  154. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  155. {
  156.         HWND hWnd;
  157.         hInst = hInstance;
  158.  
  159.         int x, y, w, h;
  160.  
  161.         x = GetSystemMetrics(SM_XVIRTUALSCREEN);
  162.         y = GetSystemMetrics(SM_YVIRTUALSCREEN);
  163.         w = GetSystemMetrics(SM_CXVIRTUALSCREEN);
  164.         h = GetSystemMetrics(SM_CYVIRTUALSCREEN);
  165.  
  166.  
  167.         ofX = x; ofY = y;
  168.  
  169.  
  170.         hWnd = CreateWindowEx(
  171.                 WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW | WS_EX_TOPMOST
  172. #if(_WIN32_WINNT >= 0x0500)
  173.                 | WS_EX_NOACTIVATE
  174. #endif
  175.                 ,
  176.                 szWindowClass, NULL, WS_POPUP,
  177.                 0, 0, 0, 0,
  178.                 NULL, NULL, hInstance, NULL);
  179.  
  180.  
  181.         if (!hWnd) return FALSE;
  182.        
  183.  
  184.         MoveWindow(hWnd, x, y, w, h, FALSE);
  185.        
  186.  
  187.         ShowWindow(hWnd, SW_SHOW);
  188.         UpdateWindow(hWnd);
  189.  
  190.  
  191.         SetTimer(hWnd, 1, 100, NULL);
  192.  
  193.  
  194.  
  195.         hLayerWnd = CreateWindowEx(
  196.          WS_EX_TOOLWINDOW
  197. #if(_WIN32_WINNT >= 0x0500)
  198.                 | WS_EX_LAYERED | WS_EX_NOACTIVATE
  199. #endif
  200.                 ,
  201.                 szWindowClassL, NULL, WS_POPUP,
  202.                 100, 100, 300, 300,
  203.                 hWnd, NULL, hInstance, NULL);
  204.  
  205.     SetLayeredWindowAttributes(hLayerWnd, RGB(255, 0, 0), 100, LWA_COLORKEY|LWA_ALPHA);
  206.  
  207.        
  208.  
  209.  
  210.        
  211.         return TRUE;
  212. }
  213.  
  214.  
  215. int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
  216. {
  217.    UINT  num = 0;        
  218.    UINT  size = 0;        
  219.  
  220.    ImageCodecInfo* pImageCodecInfo = NULL;
  221.  
  222.    GetImageEncodersSize(&num, &size);
  223.    if(size == 0)
  224.       return -1;  // Failure
  225.  
  226.    pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
  227.    if(pImageCodecInfo == NULL)
  228.       return -1;  // Failure
  229.  
  230.    GetImageEncoders(num, size, pImageCodecInfo);
  231.  
  232.    for(UINT j = 0; j < num; ++j)
  233.    {
  234.       if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
  235.       {
  236.          *pClsid = pImageCodecInfo[j].Clsid;
  237.          free(pImageCodecInfo);
  238.          return j;  // Success
  239.       }    
  240.    }
  241.  
  242.    free(pImageCodecInfo);
  243.    return -1;  // Failure
  244. }
  245.  
  246.  
  247. VOID drawRubberband(HDC hdc, LPRECT newRect, BOOL erase)
  248. {
  249.        
  250.         static BOOL firstDraw = TRUE;
  251.         static RECT lastRect  = {0};
  252.         static RECT clipRect  = {0};
  253.        
  254.         if(firstDraw) {
  255.  
  256.                 ShowWindow(hLayerWnd, SW_SHOW);
  257.                 UpdateWindow(hLayerWnd);
  258.  
  259.                 firstDraw = FALSE;
  260.         }
  261.  
  262.         if (erase) {
  263.  
  264.                 ShowWindow(hLayerWnd, SW_HIDE);
  265.                
  266.         }
  267.  
  268.  
  269.         clipRect = *newRect;
  270.         if ( clipRect.right  < clipRect.left ) {
  271.                 int tmp = clipRect.left;
  272.                 clipRect.left   = clipRect.right;
  273.                 clipRect.right  = tmp;
  274.         }
  275.         if ( clipRect.bottom < clipRect.top  ) {
  276.                 int tmp = clipRect.top;
  277.                 clipRect.top    = clipRect.bottom;
  278.                 clipRect.bottom = tmp;
  279.         }
  280.         MoveWindow(hLayerWnd,  clipRect.left, clipRect.top,
  281.                         clipRect.right-  clipRect.left + 1, clipRect.bottom - clipRect.top + 1,true);
  282.  
  283.        
  284.         return;
  285.  
  286. }
  287.  
  288.  
  289. BOOL convertPNG(LPCTSTR destFile, LPCTSTR srcFile)
  290. {
  291.         BOOL                            res = FALSE;
  292.  
  293.         GdiplusStartupInput     gdiplusStartupInput;
  294.         ULONG_PTR                       gdiplusToken;
  295.         CLSID                           clsidEncoder;
  296.  
  297.  
  298.         GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
  299.  
  300.         Image *b = new Image(srcFile, 0);
  301.  
  302.         if (0 == b->GetLastStatus()) {
  303.                 if (GetEncoderClsid(L"image/png", &clsidEncoder)) {
  304.  
  305.                         if (0 == b->Save(destFile, &clsidEncoder, 0) ) {
  306.  
  307.                                         res = TRUE;
  308.                         }
  309.                 }
  310.         }
  311.  
  312.  
  313.         delete b;
  314.         GdiplusShutdown(gdiplusToken);
  315.  
  316.         return res;
  317. }
  318.  
  319.  
  320. BOOL savePNG(LPCTSTR fileName, HBITMAP newBMP)
  321. {
  322.         BOOL                            res = FALSE;
  323.  
  324.         GdiplusStartupInput     gdiplusStartupInput;
  325.         ULONG_PTR                       gdiplusToken;
  326.         CLSID                           clsidEncoder;
  327.  
  328.  
  329.         GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
  330.        
  331.  
  332.         Bitmap *b = new Bitmap(newBMP, NULL);
  333.        
  334.         if (GetEncoderClsid(L"image/png", &clsidEncoder)) {
  335.  
  336.                 if (0 ==
  337.                         b->Save(fileName, &clsidEncoder, 0) ) {
  338.  
  339.                                 res = TRUE;
  340.                 }
  341.         }
  342.        
  343.  
  344.         delete b;
  345.         GdiplusShutdown(gdiplusToken);
  346.  
  347.         return res;
  348. }
  349.  
  350.  
  351. LRESULT CALLBACK LayerWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  352. {
  353.         HDC hdc;
  354.         RECT clipRect   = {0, 0, 500, 500};
  355.         HBRUSH hBrush;
  356.         HPEN hPen;
  357.         HFONT hFont;
  358.  
  359.  
  360.         switch (message)
  361.         {
  362.         case WM_ERASEBKGND:
  363.                  GetClientRect(hWnd, &clipRect);
  364.                
  365.                 hdc = GetDC(hWnd);
  366.         hBrush = CreateSolidBrush(RGB(100,100,100));
  367.         SelectObject(hdc, hBrush);
  368.                 hPen = CreatePen(PS_DASH,1,RGB(255,255,255));
  369.                 SelectObject(hdc, hPen);
  370.                 Rectangle(hdc,0,0,clipRect.right,clipRect.bottom);
  371.  
  372.  
  373.                 int fHeight;
  374.                 fHeight = -MulDiv(8, GetDeviceCaps(hdc, LOGPIXELSY), 72);
  375.                 hFont = CreateFont(fHeight,
  376.                         0,
  377.                         0,                
  378.                         0,              
  379.                         FW_REGULAR,        
  380.                         FALSE,
  381.                         FALSE,    
  382.                         FALSE,        
  383.                         ANSI_CHARSET,
  384.                         OUT_DEFAULT_PRECIS,
  385.                         CLIP_DEFAULT_PRECIS,
  386.                         PROOF_QUALITY,
  387.                         FIXED_PITCH | FF_MODERN,
  388.                         L"Tahoma");  
  389.  
  390.                 SelectObject(hdc, hFont);
  391.  
  392.                 int iWidth, iHeight;
  393.                 iWidth  = clipRect.right  - clipRect.left;
  394.                 iHeight = clipRect.bottom - clipRect.top;
  395.  
  396.                 wchar_t sWidth[200], sHeight[200];
  397.                 swprintf_s(sWidth, L"%d", iWidth);
  398.                 swprintf_s(sHeight, L"%d", iHeight);
  399.  
  400.                 int w,h,h2;
  401.                 w = -fHeight * 2.5 + 8;
  402.                 h = -fHeight * 2 + 8;
  403.                 h2 = h + fHeight;
  404.  
  405.                 SetBkMode(hdc,TRANSPARENT);
  406.                 SetTextColor(hdc,RGB(0,0,0));
  407.                 TextOut(hdc, clipRect.right-w+1,clipRect.bottom-h+1,(LPCWSTR)sWidth,wcslen(sWidth));
  408.                 TextOut(hdc, clipRect.right-w+1,clipRect.bottom-h2+1,(LPCWSTR)sHeight,wcslen(sHeight));
  409.                 SetTextColor(hdc,RGB(255,255,255));
  410.                 TextOut(hdc, clipRect.right-w,clipRect.bottom-h,(LPCWSTR)sWidth,wcslen(sWidth));
  411.                 TextOut(hdc, clipRect.right-w,clipRect.bottom-h2,(LPCWSTR)sHeight,wcslen(sHeight));
  412.  
  413.                 DeleteObject(hPen);
  414.                 DeleteObject(hBrush);
  415.                 DeleteObject(hFont);
  416.                 ReleaseDC(hWnd, hdc);
  417.  
  418.                 return TRUE;
  419.  
  420.         break;
  421.         default:
  422.                 return DefWindowProc(hWnd, message, wParam, lParam);
  423.         }
  424.         return 0;
  425.  
  426. }
  427.  
  428.  
  429. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  430. {
  431.         HDC hdc;
  432.        
  433.         static BOOL onClip              = FALSE;
  434.         static BOOL firstDraw   = TRUE;
  435.         static RECT clipRect    = {0, 0, 0, 0};
  436.        
  437.         switch (message)
  438.         {
  439.         case WM_RBUTTONDOWN:
  440.  
  441.                 DestroyWindow(hWnd);
  442.                 return DefWindowProc(hWnd, message, wParam, lParam);
  443.                 break;
  444.  
  445.         case WM_TIMER:
  446.  
  447.                 if (GetKeyState(VK_ESCAPE) & 0x8000){
  448.                         DestroyWindow(hWnd);
  449.                         return DefWindowProc(hWnd, message, wParam, lParam);
  450.                 }
  451.                 break;
  452.  
  453.         case WM_MOUSEMOVE:
  454.                 if (onClip) {
  455.  
  456.                         clipRect.right  = LOWORD(lParam) + ofX;
  457.                         clipRect.bottom = HIWORD(lParam) + ofY;
  458.                        
  459.                         hdc = GetDC(NULL);
  460.                         drawRubberband(hdc, &clipRect, FALSE);
  461.  
  462.                         ReleaseDC(NULL, hdc);
  463.                 }
  464.                 break;
  465.        
  466.  
  467.         case WM_LBUTTONDOWN:
  468.                 {
  469.  
  470.                         onClip = TRUE;
  471.                        
  472.  
  473.                         clipRect.left = LOWORD(lParam) + ofX;
  474.                         clipRect.top  = HIWORD(lParam) + ofY;
  475.                        
  476.  
  477.  
  478.  
  479.                         SetCapture(hWnd);
  480.                 }
  481.                 break;
  482.  
  483.         case WM_LBUTTONUP:
  484.                 {
  485.  
  486.                         onClip = FALSE;
  487.                        
  488.  
  489.                         ReleaseCapture();
  490.                
  491.  
  492.                         clipRect.right  = LOWORD(lParam) + ofX;
  493.                         clipRect.bottom = HIWORD(lParam) + ofY;
  494.  
  495.  
  496.                         HDC hdc = GetDC(NULL);
  497.  
  498.  
  499.                         drawRubberband(hdc, &clipRect, TRUE);
  500.  
  501.                         if ( clipRect.right  < clipRect.left ) {
  502.                                 int tmp = clipRect.left;
  503.                                 clipRect.left   = clipRect.right;
  504.                                 clipRect.right  = tmp;
  505.                         }
  506.                         if ( clipRect.bottom < clipRect.top  ) {
  507.                                 int tmp = clipRect.top;
  508.                                 clipRect.top    = clipRect.bottom;
  509.                                 clipRect.bottom = tmp;
  510.                         }
  511.                        
  512.  
  513.                         int iWidth, iHeight;
  514.                         iWidth  = clipRect.right  - clipRect.left + 1;
  515.                         iHeight = clipRect.bottom - clipRect.top  + 1;
  516.  
  517.                         if(iWidth == 0 || iHeight == 0) {
  518.  
  519.                                 ReleaseDC(NULL, hdc);
  520.                                 DestroyWindow(hWnd);
  521.                                 break;
  522.                         }
  523.  
  524.  
  525.                         HBITMAP newBMP = CreateCompatibleBitmap(hdc, iWidth, iHeight);
  526.                         HDC         newDC  = CreateCompatibleDC(hdc);
  527.                        
  528.  
  529.                         SelectObject(newDC, newBMP);
  530.  
  531.  
  532.                         BitBlt(newDC, 0, 0, iWidth, iHeight,
  533.                                 hdc, clipRect.left, clipRect.top, SRCCOPY);
  534.                        
  535.  
  536.                         ShowWindow(hWnd, SW_HIDE);
  537.  
  538.                         TCHAR tmpDir[MAX_PATH], tmpFile[MAX_PATH];
  539.                         GetTempPath(MAX_PATH, tmpDir);
  540.                         GetTempFileName(tmpDir, _T("gya"), 0, tmpFile);
  541.                        
  542.                         if (savePNG(tmpFile, newBMP)) {
  543.  
  544.  
  545.                                 if (!uploadFile(hWnd, tmpFile)) {
  546.                                        
  547.                                 }
  548.                         } else {
  549.  
  550.                                 MessageBox(hWnd, _T("Cannot save png image"), szTitle,
  551.                                         MB_OK | MB_ICONERROR);
  552.                         }
  553.  
  554.  
  555.                         DeleteFile(tmpFile);
  556.                        
  557.                         DeleteDC(newDC);
  558.                         DeleteObject(newBMP);
  559.  
  560.                         ReleaseDC(NULL, hdc);
  561.                         DestroyWindow(hWnd);
  562.                         PostQuitMessage(0);
  563.                 }
  564.                 break;
  565.  
  566.         case WM_DESTROY:
  567.                 PostQuitMessage(0);
  568.                 break;
  569.  
  570.         default:
  571.                 return DefWindowProc(hWnd, message, wParam, lParam);
  572.         }
  573.         return 0;
  574. }
  575.  
  576.  
  577. VOID setClipBoardText(const char* str)
  578. {
  579.  
  580.         HGLOBAL hText;
  581.         char    *pText;
  582.         size_t  slen;
  583.  
  584.         slen  = strlen(str) + 1;
  585.  
  586.         hText = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, slen * sizeof(TCHAR));
  587.  
  588.         pText = (char *)GlobalLock(hText);
  589.         strncpy_s(pText, slen, str, slen);
  590.         GlobalUnlock(hText);
  591.        
  592.  
  593.         OpenClipboard(NULL);
  594.         EmptyClipboard();
  595.         SetClipboardData(CF_TEXT, hText);
  596.         CloseClipboard();
  597.  
  598.  
  599.         GlobalFree(hText);
  600. }
  601.  
  602.  
  603. VOID execUrl(const char* str)
  604. {
  605.         size_t  slen;
  606.         size_t  dcount;
  607.         slen  = strlen(str) + 1;
  608.  
  609.         TCHAR *wcUrl = (TCHAR *)malloc(slen * sizeof(TCHAR));
  610.        
  611.  
  612.         mbstowcs_s(&dcount, wcUrl, slen, str, slen);
  613.        
  614.  
  615.         SHELLEXECUTEINFO lsw = {0};
  616.         lsw.cbSize = sizeof(SHELLEXECUTEINFO);
  617.         lsw.lpVerb = _T("open");
  618.         lsw.lpFile = wcUrl;
  619.  
  620.         ShellExecuteEx(&lsw);
  621.  
  622.         free(wcUrl);
  623. }
  624.  
  625.  
  626. std::string getId()
  627. {
  628.  
  629.     TCHAR idFile[_MAX_PATH];
  630.         TCHAR idDir[_MAX_PATH];
  631.  
  632.     SHGetSpecialFolderPath( NULL, idFile, CSIDL_APPDATA, FALSE );
  633.  
  634.          _tcscat_s( idFile, _T("\\Gyazo"));
  635.          _tcscpy_s( idDir, idFile);
  636.          _tcscat_s( idFile, _T("\\id.txt"));
  637.  
  638.         const TCHAR*     idOldFile                      = _T("id.txt");
  639.         BOOL oldFileExist = FALSE;
  640.  
  641.         std::string idStr;
  642.  
  643.  
  644.         std::ifstream ifs;
  645.  
  646.         ifs.open(idFile);
  647.         if (! ifs.fail()) {
  648.  
  649.                 ifs >> idStr;
  650.                 ifs.close();
  651.         } else{        
  652.                 std::ifstream ifsold;
  653.                 ifsold.open(idOldFile);
  654.                 if (! ifsold.fail()) {
  655.  
  656.                         ifsold >> idStr;
  657.                         ifsold.close();
  658.                 }
  659.         }
  660.  
  661.         return idStr;
  662. }
  663.  
  664.  
  665. BOOL saveId(const WCHAR* str)
  666. {
  667.  
  668.     TCHAR idFile[_MAX_PATH];
  669.         TCHAR idDir[_MAX_PATH];
  670.  
  671.     SHGetSpecialFolderPath( NULL, idFile, CSIDL_APPDATA, FALSE );
  672.  
  673.          _tcscat_s( idFile, _T("\\Gyazo"));
  674.          _tcscpy_s( idDir, idFile);
  675.          _tcscat_s( idFile, _T("\\id.txt"));
  676.  
  677.         const TCHAR*     idOldFile                      = _T("id.txt");
  678.  
  679.         size_t  slen;
  680.         size_t  dcount;
  681.         slen  = _tcslen(str) + 1;
  682.  
  683.         char *idStr = (char *)malloc(slen * sizeof(char));
  684.  
  685.         wcstombs_s(&dcount, idStr, slen, str, slen);
  686.  
  687.  
  688.         CreateDirectory(idDir,NULL);
  689.         std::ofstream ofs;
  690.         ofs.open(idFile);
  691.         if (! ofs.fail()) {
  692.                 ofs << idStr;
  693.                 ofs.close();
  694.  
  695.  
  696.                 if (PathFileExists(idOldFile)){
  697.                         DeleteFile(idOldFile);
  698.                 }
  699.         }else{
  700.                 free(idStr);
  701.                 return FALSE;
  702.         }
  703.  
  704.         free(idStr);
  705.         return TRUE;
  706. }
  707.  
  708.  
  709. BOOL uploadFile(HWND hwnd, LPCTSTR fileName)
  710. {
  711.         const TCHAR* UPLOAD_SERVER = _T("i.douglasbrunal.co");
  712.         const TCHAR* UPLOAD_PATH = _T("/up.php");
  713.  
  714.         const char*  sBoundary = "----BOUNDARYBOUNDARY----";
  715.         const char   sCrLf[] = { 0xd, 0xa, 0x0 };
  716.         const TCHAR* szHeader =
  717.                 _T("Content-type: multipart/form-data; boundary=----BOUNDARYBOUNDARY----");
  718.  
  719.         std::ostringstream      buf;
  720.         std::string                     idStr;
  721.  
  722.         //
  723.         idStr = getId();
  724.  
  725.  
  726.         buf << "--";
  727.         buf << sBoundary;
  728.         buf << sCrLf;
  729.         buf << "content-disposition: form-data; name=\"id\"";
  730.         buf << sCrLf;
  731.         buf << sCrLf;
  732.         buf << idStr;
  733.         buf << sCrLf;
  734.  
  735.  
  736.         buf << "--";
  737.         buf << sBoundary;
  738.         buf << sCrLf;
  739.         buf << "content-disposition: form-data; name=\"imagedata\"; filename=\"gyazo\"";
  740.         buf << sCrLf;
  741.  
  742.         buf << sCrLf;
  743.  
  744.  
  745.         std::ifstream png;
  746.         png.open(fileName, std::ios::binary);
  747.         if (png.fail()) {
  748.                 MessageBox(hwnd, _T("PNG open failed"), szTitle, MB_ICONERROR | MB_OK);
  749.                 png.close();
  750.                 return FALSE;
  751.         }
  752.         buf << png.rdbuf();
  753.         png.close();
  754.  
  755.  
  756.         buf << sCrLf;
  757.         buf << "--";
  758.         buf << sBoundary;
  759.         buf << "--";
  760.         buf << sCrLf;
  761.  
  762.  
  763.         std::string oMsg(buf.str());
  764.  
  765.  
  766.         HINTERNET hSession = InternetOpen(szTitle,
  767.                 INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
  768.         if (NULL == hSession) {
  769.                 MessageBox(hwnd, _T("Cannot configure wininet"),
  770.                         szTitle, MB_ICONERROR | MB_OK);
  771.                 return FALSE;
  772.         }
  773.  
  774.  
  775.         HINTERNET hConnection = InternetConnect(hSession,
  776.                 UPLOAD_SERVER, INTERNET_DEFAULT_HTTP_PORT,
  777.                 NULL, NULL, INTERNET_SERVICE_HTTP, 0, NULL);
  778.         if (NULL == hSession) {
  779.                 MessageBox(hwnd, _T("Cannot initiate connection"),
  780.                         szTitle, MB_ICONERROR | MB_OK);
  781.                 return FALSE;
  782.         }
  783.  
  784.  
  785.         HINTERNET hRequest = HttpOpenRequest(hConnection,
  786.                 _T("POST"), UPLOAD_PATH, NULL,
  787.                 NULL, NULL, INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD, NULL);
  788.         if (NULL == hSession) {
  789.                 MessageBox(hwnd, _T("Cannot compose post request"),
  790.                         szTitle, MB_ICONERROR | MB_OK);
  791.                 return FALSE;
  792.         }
  793.  
  794.  
  795.         const TCHAR* ua = _T("User-Agent: Gyazowin/1.0\r\n");
  796.         BOOL bResult = HttpAddRequestHeaders(
  797.                 hRequest, ua, _tcslen(ua),
  798.                 HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE);
  799.         if (FALSE == bResult) {
  800.                 MessageBox(hwnd, _T("Cannot set user agent"),
  801.                         szTitle, MB_ICONERROR | MB_OK);
  802.                 return FALSE;
  803.         }
  804.  
  805.  
  806.         if (HttpSendRequest(hRequest,
  807.                 szHeader,
  808.                 lstrlen(szHeader),
  809.                 (LPVOID)oMsg.c_str(),
  810.                 (DWORD)oMsg.length()))
  811.         {
  812.  
  813.  
  814.                 DWORD resLen = 8;
  815.                 TCHAR resCode[8];
  816.  
  817.                 HttpQueryInfo(hRequest, HTTP_QUERY_STATUS_CODE, resCode, &resLen, 0);
  818.                 if (_ttoi(resCode) != 200) {
  819.  
  820.                         MessageBox(hwnd, _T("Failed to upload (unexpected result code, under maintainance?)"),
  821.                                 szTitle, MB_ICONERROR | MB_OK);
  822.                 }
  823.                 else {
  824.  
  825.                         DWORD idLen = 100;
  826.                         TCHAR newid[100];
  827.  
  828.                         memset(newid, 0, idLen*sizeof(TCHAR));
  829.                         _tcscpy_s(newid, _T("X-Gyazo-Id"));
  830.  
  831.                         HttpQueryInfo(hRequest, HTTP_QUERY_CUSTOM, newid, &idLen, 0);
  832.                         if (GetLastError() != ERROR_HTTP_HEADER_NOT_FOUND && idLen != 0) {
  833.  
  834.                                 saveId(newid);
  835.                         }
  836.  
  837.                         DWORD len;
  838.                         char  resbuf[1024];
  839.                         std::string result;
  840.  
  841.  
  842.                         while (InternetReadFile(hRequest, (LPVOID)resbuf, 1024, &len)
  843.                                 && len != 0)
  844.                         {
  845.                                 result.append(resbuf, len);
  846.                         }
  847.  
  848.                         result += '\0';
  849.  
  850.  
  851.                         setClipBoardText(result.c_str());
  852.  
  853.  
  854.                         execUrl(result.c_str());
  855.  
  856.                         return TRUE;
  857.                 }
  858.         }
  859.         else {
  860.  
  861.                 MessageBox(hwnd, _T("Failed to upload"), szTitle, MB_ICONERROR | MB_OK);
  862.         }
  863.  
  864.         return FALSE;
  865.  
  866. }