-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from superolmo/dev
Moving to 0.1.2.0
- Loading branch information
Showing
24 changed files
with
1,602 additions
and
418 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#include "Configuration.h" | ||
|
||
Configuration::Configuration(NppData nppData) { | ||
//Get directory where the configuration file is located | ||
this->_getPluginDirectory(nppData); | ||
|
||
//Load config file | ||
this->loadConfFile(nppData); | ||
} | ||
|
||
void Configuration::_getPluginDirectory(NppData nppData) { | ||
//TODO replace confFolder with confDir | ||
//TCHAR confFolder[1000]; | ||
TCHAR confDir[MAX_PATH]; | ||
::SendMessage(nppData._nppHandle, NPPM_GETPLUGINSCONFIGDIR, MAX_PATH, (LPARAM)confDir); | ||
//wcsncpy(confFolder, confDir, MAX_PATH); | ||
confFileNameFull = std::wstring(confDir) + L"\\bigfile.conf"; | ||
} | ||
|
||
int Configuration::get_default_page_size_bytes() { | ||
return this->default_page_size_bytes; | ||
}; | ||
bool Configuration::get_default_isAdmin_warnings() { | ||
return this->default_isAdmin_warnings; | ||
}; | ||
|
||
/*********************************************************************************** | ||
Function was taken from Notepad++ plugin called Converter at | ||
https://github.com/npp-plugins/converter/blob/master/source/PluginDefinition.cpp | ||
Modified to suite BigFiles needs | ||
*/ | ||
// | ||
// if conf file does not exist, then create it and load it. | ||
|
||
void Configuration::_getCmdsFromConf(const TCHAR* confPath) | ||
{ | ||
TCHAR cmdNames[MAX_PATH]; | ||
::GetPrivateProfileSectionNames(cmdNames, MAX_PATH, confPath); | ||
TCHAR* pFn = cmdNames; | ||
|
||
if (*pFn && wcscmp(pFn, TEXT("BigFiles")) == 0) | ||
{ | ||
int val = 0; | ||
val = GetPrivateProfileInt(pFn, TEXT("page_size_bytes"), 0, confPath); | ||
if (val != 0) | ||
this->default_page_size_bytes = val; | ||
val = GetPrivateProfileInt(pFn, TEXT("isAdmin_warnings"), 0, confPath); | ||
this->default_isAdmin_warnings = val != 0; | ||
} | ||
else { | ||
::MessageBox(NULL, TEXT("Configuration not found"), TEXT("BigFiles Plugin - Configuration::_getCmdsFromConf"), MB_OK); | ||
} | ||
} | ||
void Configuration::loadConfFile(NppData nppData) | ||
{ | ||
|
||
const char confContent[] = "\ | ||
[BigFiles]\n\ | ||
page_size_bytes=100000\n\ | ||
isAdmin_warnings=1\n\ | ||
\n"; | ||
|
||
//Get the fully qualified name of the config file, function saves it in confFileNameFull | ||
//_getPluginDirectory(nppData); | ||
|
||
// If the file does not exist, save default values | ||
if (!::PathFileExists(confFileNameFull.c_str())) | ||
{ | ||
wsprintf(strMessage, TEXT("%s%s"), TEXT("First time usage. Writing new BigFile config file to "), confFileNameFull.c_str()); | ||
::MessageBox(NULL, strMessage, TEXT("BigFiles Plugin - loadConfFile"), MB_OK); | ||
//Write default configuration file | ||
std::ofstream confFile(confFileNameFull); | ||
if (confFile) | ||
confFile << confContent; | ||
else | ||
::MessageBox(NULL, TEXT("Something went wrong1"), TEXT("BigFiles Plugin - Configuration::loadConfFile"), MB_OK); | ||
if (confFile.bad()) | ||
::MessageBox(NULL, TEXT("Something went wrong2"), TEXT("BigFiles Plugin - Configuration::loadConfFile"), MB_OK); | ||
confFile.close(); | ||
} | ||
//Get values from configuration file | ||
_getCmdsFromConf(confFileNameFull.c_str()); | ||
} | ||
void Configuration::editConf(NppData nppData) | ||
{ | ||
//IDM_FILE_OPEN | ||
if (!::PathFileExists(confFileNameFull.c_str())) | ||
{ | ||
loadConfFile(nppData); | ||
} | ||
::SendMessage(nppData._nppHandle, NPPM_DOOPEN, 0, (LPARAM)confFileNameFull.c_str()); | ||
} | ||
/* | ||
End of copied section from | ||
https://github.com/npp-plugins/converter/blob/master/source/PluginDefinition.cpp | ||
*******************************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#pragma once | ||
|
||
#include "PluginInterface.h" | ||
#include "resource.h" | ||
|
||
/* | ||
Used for: | ||
Functions used: | ||
std::ifstream | ||
*/ | ||
#include <fstream> | ||
|
||
/* | ||
Used for: | ||
PathFindExists | ||
*/ | ||
#include <shlwapi.h> | ||
|
||
class Configuration | ||
{ | ||
|
||
// used for messages | ||
wchar_t strMessage[1000]; | ||
|
||
// Default value of page size in bytes | ||
int default_page_size_bytes = 100000; | ||
|
||
int default_isAdmin_warnings = false; //If it is 1, it warns the user when Notepad++ is open in Admin mode. | ||
|
||
private: | ||
// Function gets the directory path where the configuration folder is located | ||
// This function fills the global variable that is later used for loading and saving configurations | ||
void _getPluginDirectory(NppData nppData); | ||
|
||
void _getCmdsFromConf(const TCHAR*); | ||
|
||
public: | ||
// Holds the fully qualified file name of the configuration file | ||
std::wstring confFileNameFull; | ||
|
||
// Constructor | ||
Configuration(NppData); | ||
|
||
void loadConfFile(NppData nppData); | ||
void editConf(NppData nppData); | ||
|
||
// Getters | ||
int get_default_page_size_bytes(); | ||
bool get_default_isAdmin_warnings(); | ||
} ; |
Oops, something went wrong.