Skip to content

Commit

Permalink
embed default snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
erinata committed May 3, 2012
1 parent d4e2b02 commit 74f90cc
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 21 deletions.
9 changes: 5 additions & 4 deletions Config/Version.h
Expand Up @@ -29,17 +29,18 @@

//#define TESTING


#define VERSION_TEXT "0.5.60"
#define VERSION_NUM 0,5,60,0
#define VERSION_LINEAR 560
#define VERSION_TEXT "0.5.59.1"
#define VERSION_NUM 0,5,59,1
#define VERSION_LINEAR 559
#define VERSION_KEEP_CONFIG_START 549
#define VERSION_STAGE "(Alpha)"
#ifdef TESTING
#define VERSION_STAGE_ADD " Nightly"
#else
#define VERSION_STAGE_ADD ""
#endif
#define SNIPPET_RESOURCE 301
#define DEFAULTSNIPPETPATH "DefaultSnippetPackage\\fingertext_standard_library-0.2.0.ftd"


#define AUTHOR_NAME "erinata"
Expand Down
Binary file modified Config/Version.rc
Binary file not shown.
Binary file removed Config/resource.h
Binary file not shown.
2 changes: 1 addition & 1 deletion Embeded/DefaultPackage.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion FingerText.vcxproj.filters
Expand Up @@ -17,7 +17,7 @@
<UniqueIdentifier>{e8edcf11-cad7-40e9-b5bf-04bdec6f47f8}</UniqueIdentifier>
</Filter>
<Filter Include="DefaultPackage">
<UniqueIdentifier>{933989c4-d530-4e49-86b6-3a9366456336}</UniqueIdentifier>
<UniqueIdentifier>{3a2c5b06-f015-49be-86dd-70454f557f90}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
Expand Down
63 changes: 48 additions & 15 deletions PluginDefinition.cpp
Expand Up @@ -285,9 +285,10 @@ void commandMenuInit()
g_toggleDisableIndex = setCommand(TEXT("Toggle On/Off FingerText"), toggleDisable);
setCommand();
g_selectionToSnippetIndex = setCommand(TEXT("Create Snippet from Selection"), doSelectionToSnippet);
g_downloadDefaultPackageIndex = setCommand(TEXT("Install Default Snippet Package"), installDefaultPackage);
g_importSnippetsIndex = setCommand(TEXT("Import Snippets from ftd file"), importSnippetsOnly);
//g_downloadDefaultPackageIndex = setCommand(TEXT("Import Default Snippet Package"), downloadDefaultPackage);
g_downloadDefaultPackageIndex = setCommand(TEXT("Install Default Snippet Package"), installDefaultPackage);

g_exportSnippetsIndex = setCommand(TEXT("Export All Snippets"), exportSnippetsOnly);
g_deleteAllSnippetsIndex = setCommand(TEXT("Delete All Snippets"), exportAndClearSnippets);

Expand Down Expand Up @@ -3842,21 +3843,53 @@ void setListTarget()

void installDefaultPackage()
{
HRSRC hRes = FindResource((HINSTANCE)g_hModule, MAKEINTRESOURCE(ID_CUSTOM1), L"ANYTHINGGOESHERE");
HGLOBAL hMem = LoadResource((HINSTANCE)g_hModule, hRes);
DWORD size = SizeofResource((HINSTANCE)g_hModule, hRes);
char* resText = (char*)LockResource(hMem);
char* text = (char*)malloc(size + 1);
memcpy(text, resText, size);
text[size] = 0;
FreeResource(hMem);


//std::ofstream myfile;
//myfile.open (g_downloadPath);
updateSnippetCount();

int messageReturn = IDYES;

if (toDouble(g_snippetCount) != 0)
{
messageReturn = showMessageBox(TEXT("It seems that you already have some snippets in your FingerText database.\r\n\r\nAre you sure that you want to install the Default Snippet Package?"),MB_YESNO);
if (messageReturn == IDNO) return;
}


HGLOBAL res_handle = NULL;
HRSRC res;
char * res_data;
DWORD res_size;

// NOTE: providing g_hInstance is important, NULL might not work
res = FindResource((HINSTANCE)g_hModule, MAKEINTRESOURCE(SNIPPET_RESOURCE), RT_RCDATA);
//res = FindResource(NULL, MAKEINTRESOURCE(MY_RESOURCE), RT_RCDATA);

if (!res)
{
showMessageBox(TEXT("Error importing Default Snippets."));
return;
}

res_handle = LoadResource((HINSTANCE)g_hModule, res);
if (!res_handle)
{
showMessageBox(TEXT("Error importing Default Snippets."));
return;
}

res_data = (char*)LockResource(res_handle);
res_size = SizeofResource(NULL, res);

std::string defaultSnippetText;
defaultSnippetText = toString(res_data);

std::ofstream myfile;
myfile.open (g_downloadPath);
//myfile << getDefaultPackage();
//myfile.close();
//importSnippets(g_downloadPath);
myfile << defaultSnippetText;
myfile.close();
importSnippets(g_downloadPath);

//delete [] res_data;
}

void downloadDefaultPackage()
Expand Down

0 comments on commit 74f90cc

Please sign in to comment.