Commits

Anonymous committed 33888fa

building and working on Windows

Comments (0)

Files changed (4)

NPAPIFileIOforChromeAPI.cpp

     std::ostringstream currentNum("");
     //std::vector<char> buffer;
     //buffer.reserve(arrayLength);
-    char buffer[arrayLength];
+    char* buffer = new char[arrayLength];
     int idx = 0;
     
     int size = jsonArray.length();
     boost::filesystem::ofstream out(p, std::ios::out | std::ios::binary);
     out.write(buffer, arrayLength);
     out.close();
+	delete [] buffer;
     return true;
    
 }
     if (is_regular_file(p))
     {
         int size = file_size(p);
-        char buffer[size];
+        char* buffer = new char[size];
         
         boost::filesystem::ifstream in(p, std::ios::in | std::ios::binary);
     
         } else {
             throw script_error("Error executing JavaScript code");
         }
-
+		delete [] buffer;
         
         //return boost::make_shared<BinaryArray>(buffer, size);
         /*jsBytes.reserve(size);
 void NPAPIFileIOforChromeAPI::launchFileSelect(JSObjectPtr callback)
 {
     DialogManager* dlgMgr = DialogManager::get();
-    dlgMgr->OpenFolderDialog(m_host, NULL, boost::bind(&NPAPIFileIOforChromeAPI::fileSelectCallback, this, _1, callback));
+	NPAPIFileIOforChromePtr plugin = m_plugin.lock();
+    dlgMgr->OpenFolderDialog(m_host, plugin->GetWindow(), boost::bind(&NPAPIFileIOforChromeAPI::fileSelectCallback, this, _1, callback));
 }
 void NPAPIFileIOforChromeAPI::fileSelectCallback(const std::string &path, JSObjectPtr callback)
 {
     
    // pid_t pid = getppid();
     
-    
+#else
+	return "";
 #endif
+
 }
 

Win/DialogManagerWin.cpp

+#include "win_common.h"
+#include <commdlg.h>
+#include <string>
+#include <boost/thread.hpp>
+#include "utf8_tools.h"
+#include "Win/PluginWindowlessWin.h"
+#include "Win/PluginWindowWin.h"
+
+#include "DialogManagerWin.h"
+#include <shlobj.h>
+#include "precompiled_headers.h" // Anything before this is PCH on windows
+
+DialogManager* DialogManager::get()
+{
+    static DialogManagerWin inst;
+    return &inst;
+}
+
+void DialogManagerWin::OpenFolderDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb) {
+    FB::PluginWindowWin* wndWin = dynamic_cast<FB::PluginWindowWin*>(win);
+    FB::PluginWindowlessWin* wndlessWin = dynamic_cast<FB::PluginWindowlessWin*>(win);
+
+    HWND browserWindow = wndWin ? wndWin->getBrowserHWND() : wndlessWin->getHWND();
+    boost::thread dlgThread(&DialogManagerWin::_showFolderDialog, this, browserWindow, cb);
+}
+
+void DialogManagerWin::_showFolderDialog(HWND wnd, const PathCallback& cb) {
+    BROWSEINFO bi = { 0 };
+    bi.lpszTitle = _T("Select a folder to import");
+    bi.hwndOwner = wnd;
+    LPITEMIDLIST pidl = SHBrowseForFolder ( &bi );
+    if ( pidl != 0 )
+    {
+        std::wstring out;
+        // get the name of the folder
+        TCHAR path[MAX_PATH];
+        if ( SHGetPathFromIDList ( pidl, path ) )
+        {
+            out = path;
+        }
+
+        // free memory used
+        IMalloc * imalloc = 0;
+        if ( SUCCEEDED( SHGetMalloc ( &imalloc )) )
+        {
+            imalloc->Free ( pidl );
+            imalloc->Release ( );
+        }
+        cb(FB::wstring_to_utf8(path));
+    } else {
+        cb("");
+    }
+}
+void DialogManagerWin::_showFileDialog(HWND wnd, const std::string& path, const std::string& filter, const PathCallback& cb)
+{
+    wchar_t Filestring[256];
+    std::string out;
+
+    std::wstring wFilter(FB::utf8_to_wstring(filter));
+    std::wstring wPath(FB::utf8_to_wstring(filter));
+
+    OPENFILENAME opf;
+    opf.hwndOwner = wnd;
+    opf.lpstrFilter = wFilter.c_str();
+    opf.lpstrCustomFilter = 0;
+    opf.nMaxCustFilter = 0L;
+    opf.nFilterIndex = 1L;
+    opf.lpstrFile = Filestring;
+    opf.lpstrFile[0] = '\0';
+    opf.nMaxFile = 256;
+    opf.lpstrFileTitle = 0;
+    opf.nMaxFileTitle=50;
+    opf.lpstrInitialDir = wPath.c_str();
+    opf.lpstrTitle = L"Choose directory to import";
+    opf.nFileOffset = 0;
+    opf.nFileExtension = 0;
+    opf.lpstrDefExt = L"*.*";
+    opf.lpfnHook = NULL;
+    opf.lCustData = 0;
+    opf.Flags = (OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT) & ~OFN_ALLOWMULTISELECT;
+    opf.lStructSize = sizeof(OPENFILENAME);
+
+    if(GetOpenFileName(&opf))
+    {
+        out = FB::wstring_to_utf8(std::wstring(opf.lpstrFile));
+    }
+
+    cb(out);
+}

Win/DialogManagerWin.h

+#ifndef DialogManagerWin_h__
+#define DialogManagerWin_h__
+
+#include <boost/noncopyable.hpp>
+#include <string>
+
+#include "../DialogManager.h"
+
+class DialogManagerWin : public DialogManager
+{
+public:
+    void OpenFolderDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb);
+
+protected:
+    DialogManagerWin() {};
+    ~DialogManagerWin() {};
+    void _showFileDialog(HWND wnd, const std::string& path, const std::string& filter, const PathCallback& cb);
+    void _showFolderDialog(HWND wnd, const PathCallback& cb);
+    friend class DialogManager;
+};
+#endif // DialogManagerWin_h__

Win/New Text Document.txt

+#include "win_common.h"
+#include <commdlg.h>
+#include <string>
+#include <boost/thread.hpp>
+#include "utf8_tools.h"
+#include "Win/PluginWindowlessWin.h"
+#include "Win/PluginWindowWin.h"
+
+#include "DialogManagerWin.h"
+#include <shlobj.h>
+#include "precompiled_headers.h" // Anything before this is PCH on windows
+
+DialogManager* DialogManager::get()
+{
+    static DialogManagerWin inst;
+    return &inst;
+}
+
+void DialogManagerWin::OpenFolderDialog(const FB::BrowserHostPtr& host, FB::PluginWindow* win, const PathCallback& cb) {
+    FB::PluginWindowWin* wndWin = dynamic_cast<FB::PluginWindowWin*>(win);
+    FB::PluginWindowlessWin* wndlessWin = dynamic_cast<FB::PluginWindowlessWin*>(win);
+
+    HWND browserWindow = wndWin ? wndWin->getBrowserHWND() : wndlessWin->getHWND();
+    boost::thread dlgThread(&DialogManagerWin::_showFolderDialog, this, browserWindow, cb);
+}
+
+void DialogManagerWin::_showFolderDialog(HWND wnd, const PathCallback& cb) {
+    BROWSEINFO bi = { 0 };
+    bi.lpszTitle = _T("Select a folder to import");
+    bi.hwndOwner = wnd;
+    LPITEMIDLIST pidl = SHBrowseForFolder ( &bi );
+    if ( pidl != 0 )
+    {
+        std::wstring out;
+        // get the name of the folder
+        TCHAR path[MAX_PATH];
+        if ( SHGetPathFromIDList ( pidl, path ) )
+        {
+            out = path;
+        }
+
+        // free memory used
+        IMalloc * imalloc = 0;
+        if ( SUCCEEDED( SHGetMalloc ( &imalloc )) )
+        {
+            imalloc->Free ( pidl );
+            imalloc->Release ( );
+        }
+        cb(FB::wstring_to_utf8(path));
+    } else {
+        cb("");
+    }
+}
+void DialogManagerWin::_showFileDialog(HWND wnd, const std::string& path, const std::string& filter, const PathCallback& cb)
+{
+    wchar_t Filestring[256];
+    std::string out;
+
+    std::wstring wFilter(FB::utf8_to_wstring(filter));
+    std::wstring wPath(FB::utf8_to_wstring(filter));
+
+    OPENFILENAME opf;
+    opf.hwndOwner = wnd;
+    opf.lpstrFilter = wFilter.c_str();
+    opf.lpstrCustomFilter = 0;
+    opf.nMaxCustFilter = 0L;
+    opf.nFilterIndex = 1L;
+    opf.lpstrFile = Filestring;
+    opf.lpstrFile[0] = '\0';
+    opf.nMaxFile = 256;
+    opf.lpstrFileTitle = 0;
+    opf.nMaxFileTitle=50;
+    opf.lpstrInitialDir = wPath.c_str();
+    opf.lpstrTitle = L"Choose directory to import";
+    opf.nFileOffset = 0;
+    opf.nFileExtension = 0;
+    opf.lpstrDefExt = L"*.*";
+    opf.lpfnHook = NULL;
+    opf.lCustData = 0;
+    opf.Flags = (OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT) & ~OFN_ALLOWMULTISELECT;
+    opf.lStructSize = sizeof(OPENFILENAME);
+
+    if(GetOpenFileName(&opf))
+    {
+        out = FB::wstring_to_utf8(std::wstring(opf.lpstrFile));
+    }
+
+    cb(out);
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.