summaryrefslogtreecommitdiff
path: root/ldmicro/lib/freezeLD/freezeLD.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ldmicro/lib/freezeLD/freezeLD.cpp')
-rw-r--r--ldmicro/lib/freezeLD/freezeLD.cpp187
1 files changed, 165 insertions, 22 deletions
diff --git a/ldmicro/lib/freezeLD/freezeLD.cpp b/ldmicro/lib/freezeLD/freezeLD.cpp
index 0bbd33f..ea3fae2 100644
--- a/ldmicro/lib/freezeLD/freezeLD.cpp
+++ b/ldmicro/lib/freezeLD/freezeLD.cpp
@@ -19,19 +19,34 @@
void FreezeWindowPosF(HWID hwid, char *subKey, char *name)
{
//g_print("freezing");
- char* moveToKeyLocatin = (char *)malloc(strlen(subKey) + 35);
+ char* Ld_CWD = (char *)malloc(MAX_PATH);
+ getcwd(Ld_CWD, sizeof(Ld_CWD));
+
+ if (!Ld_CWD)
+ return;
+ char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30);
if(!moveToKeyLocatin)
+ {
+ free(Ld_CWD);
return;
- sprintf(moveToKeyLocatin, "mkdir -p %s/%s", LDMICRO_REGISTER, subKey);
+ }
+ sprintf(moveToKeyLocatin, "mkdir -p %s/%s", FREEZE_REGISTER, subKey);
system(moveToKeyLocatin);
- sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey);
- if (-1 == system(moveToKeyLocatin))
+ sprintf(moveToKeyLocatin, "%s/%s", FREEZE_REGISTER, subKey);
+ if (-1 == chdir(moveToKeyLocatin))
+ {
+ free(Ld_CWD);
+ free(moveToKeyLocatin);
return;
+ }
free(moveToKeyLocatin);
char *keyName = (char *)malloc(strlen(name) + 30);
if(!keyName)
+ {
+ free(Ld_CWD);
return;
+ }
Key newKey;
@@ -40,7 +55,11 @@ void FreezeWindowPosF(HWID hwid, char *subKey, char *name)
sprintf(keyName, "%s_width", name);
std::ofstream Register(keyName, std::ios::binary | std::ios::trunc);
if (!Register.is_open())
+ {
+ free(Ld_CWD);
+ free(keyName);
return;
+ }
gtk_window_get_size(GTK_WINDOW(hwid), &val, NULL);
newKey.type = 'i';
newKey.val.i = val;
@@ -51,7 +70,11 @@ void FreezeWindowPosF(HWID hwid, char *subKey, char *name)
sprintf(keyName, "%s_height", name);
Register.open(keyName, std::ios::binary | std::ios::trunc);
if (!Register.is_open())
+ {
+ free(Ld_CWD);
+ free(keyName);
return;
+ }
gtk_window_get_size(GTK_WINDOW(hwid), NULL, &val);
newKey.type = 'i';
newKey.val.i = val;
@@ -62,7 +85,11 @@ void FreezeWindowPosF(HWID hwid, char *subKey, char *name)
sprintf(keyName, "%s_posX", name);
Register.open(keyName, std::ios::binary | std::ios::trunc);
if (!Register.is_open())
+ {
+ free(Ld_CWD);
+ free(keyName);
return;
+ }
gtk_window_get_position(GTK_WINDOW(hwid), &val, NULL);
newKey.type = 'i';
newKey.val.i = val;
@@ -73,7 +100,11 @@ void FreezeWindowPosF(HWID hwid, char *subKey, char *name)
sprintf(keyName, "%s_posY", name);
Register.open(keyName, std::ios::binary | std::ios::trunc);
if (!Register.is_open())
+ {
+ free(Ld_CWD);
+ free(keyName);
return;
+ }
gtk_window_get_position(GTK_WINDOW(hwid), NULL, &val);
newKey.type = 'i';
newKey.val.i = val;
@@ -84,13 +115,19 @@ void FreezeWindowPosF(HWID hwid, char *subKey, char *name)
sprintf(keyName, "%s_maximized", name);
Register.open(keyName, std::ios::binary | std::ios::trunc);
if (!Register.is_open())
+ {
+ free(Ld_CWD);
+ free(keyName);
return;
+ }
newKey.type = 'b';
newKey.val.b = gtk_window_is_maximized(GTK_WINDOW(hwid));
Register.write((char*) &newKey, sizeof(newKey));
Register.close();
free(keyName);
+ chdir(Ld_CWD);
+ free(Ld_CWD);
//g_print("freezed");
}
@@ -105,17 +142,33 @@ static void Clamp(LONG *v, LONG min, LONG max)
*/
void ThawWindowPosF(HWID hwid, char *subKey, char *name)
{
- char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30);
+ char* Ld_CWD = (char *)malloc(MAX_PATH);
+ getcwd(Ld_CWD, sizeof(Ld_CWD));
+
+ if (!Ld_CWD)
+ return;
+
+ char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30);
if(!moveToKeyLocatin)
+ {
+ free(Ld_CWD);
return;
- sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey);
- if (-1 == system(moveToKeyLocatin))
+ }
+ sprintf(moveToKeyLocatin, "%s/%s", FREEZE_REGISTER, subKey);
+ if (-1 == chdir(moveToKeyLocatin))
+ {
+ free(Ld_CWD);
+ free(moveToKeyLocatin);
return;
+ }
free(moveToKeyLocatin);
char *keyName = (char *)malloc(strlen(name) + 30);
if(!keyName)
+ {
+ free(Ld_CWD);
return;
+ }
Key newKey1, newKey2;
@@ -123,14 +176,22 @@ void ThawWindowPosF(HWID hwid, char *subKey, char *name)
sprintf(keyName, "%s_width", name);
std::ifstream Register(keyName, std::ios::binary);
if (!Register.is_open())
+ {
+ free(Ld_CWD);
+ free(keyName);
return;
+ }
Register.read((char*) &newKey1, sizeof(newKey1));
Register.close();
sprintf(keyName, "%s_height", name);
Register.open(keyName, std::ios::binary);
if (!Register.is_open())
+ {
+ free(Ld_CWD);
+ free(keyName);
return;
+ }
Register.read((char*) &newKey2, sizeof(newKey2));
Register.close();
if (newKey1.type == 'i' && newKey2.type == 'i')
@@ -141,14 +202,22 @@ void ThawWindowPosF(HWID hwid, char *subKey, char *name)
sprintf(keyName, "%s_posX", name);
Register.open(keyName, std::ios::binary);
if (!Register.is_open())
+ {
+ free(Ld_CWD);
+ free(keyName);
return;
+ }
Register.read((char*) &newKey1, sizeof(newKey1));
Register.close();
sprintf(keyName, "%s_posY", name);
Register.open(keyName, std::ios::binary);
if (!Register.is_open())
+ {
+ free(Ld_CWD);
+ free(keyName);
return;
+ }
Register.read((char*) &newKey2, sizeof(newKey2));
Register.close();
if (newKey1.type == 'i' && newKey2.type == 'i')
@@ -158,7 +227,11 @@ void ThawWindowPosF(HWID hwid, char *subKey, char *name)
sprintf(keyName, "%s_maximized", name);
Register.open(keyName, std::ios::binary);
if (!Register.is_open())
+ {
+ free(Ld_CWD);
+ free(keyName);
return;
+ }
Register.read((char*) &newKey1, sizeof(newKey1));
Register.close();
if (newKey1.type == 'b')
@@ -169,6 +242,8 @@ void ThawWindowPosF(HWID hwid, char *subKey, char *name)
/// gtk_window_move handles off-screen window placement
free(keyName);
+ chdir(Ld_CWD);
+ free(Ld_CWD);
}
/*
@@ -176,14 +251,27 @@ void ThawWindowPosF(HWID hwid, char *subKey, char *name)
*/
void FreezeDWORDF(DWORD val, char *subKey, char *name)
{
- char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30);
+ char* Ld_CWD = (char *)malloc(MAX_PATH);
+ getcwd(Ld_CWD, sizeof(Ld_CWD));
+
+ if (!Ld_CWD)
+ return;
+
+ char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30);
if(!moveToKeyLocatin)
+ {
+ free(Ld_CWD);
return;
- sprintf(moveToKeyLocatin, "mkdir -p %s/%s", LDMICRO_REGISTER, subKey);
- system(moveToKeyLocatin);
- sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey);
- if (-1 == system(moveToKeyLocatin))
+ }
+ sprintf(moveToKeyLocatin, "mkdir -p %s/%s", FREEZE_REGISTER, subKey);
+ system(moveToKeyLocatin);
+ sprintf(moveToKeyLocatin, "%s/%s", FREEZE_REGISTER, subKey);
+ if (-1 == chdir(moveToKeyLocatin))
+ {
+ free(Ld_CWD);
+ free(moveToKeyLocatin);
return;
+ }
free(moveToKeyLocatin);
Key newKey;
@@ -192,6 +280,9 @@ void FreezeDWORDF(DWORD val, char *subKey, char *name)
std::ofstream Register(name, std::ios::binary | std::ios::trunc);
Register.write((char*) &newKey, sizeof(newKey));
Register.close();
+
+ chdir(Ld_CWD);
+ free(Ld_CWD);
}
/*
@@ -199,12 +290,25 @@ void FreezeDWORDF(DWORD val, char *subKey, char *name)
*/
DWORD ThawDWORDF(DWORD val, char *subKey, char *name)
{
- char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30);
+ char* Ld_CWD = (char *)malloc(MAX_PATH);
+ getcwd(Ld_CWD, sizeof(Ld_CWD));
+
+ if (!Ld_CWD)
+ return val;
+
+ char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30);
if(!moveToKeyLocatin)
+ {
+ free(Ld_CWD);
return val;
- sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey);
- if (-1 == system(moveToKeyLocatin))
+ }
+ sprintf(moveToKeyLocatin, "%s/%s", FREEZE_REGISTER, subKey);
+ if (-1 == chdir(moveToKeyLocatin))
+ {
+ free(Ld_CWD);
+ free(moveToKeyLocatin);
return val;
+ }
free(moveToKeyLocatin);
Key newKey;
@@ -212,6 +316,10 @@ DWORD ThawDWORDF(DWORD val, char *subKey, char *name)
std::ifstream Register(name, std::ios::binary);
Register.read((char*) &newKey, sizeof(newKey));
Register.close();
+
+ chdir(Ld_CWD);
+ free(Ld_CWD);
+
if(Register.bad())
return val;
@@ -226,20 +334,36 @@ DWORD ThawDWORDF(DWORD val, char *subKey, char *name)
*/
void FreezeStringF(char *val, char *subKey, char *name)
{
- char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30);
+ char* Ld_CWD = (char *)malloc(MAX_PATH);
+ getcwd(Ld_CWD, sizeof(Ld_CWD));
+
+ if (!Ld_CWD)
+ return;
+
+ char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30);
if(!moveToKeyLocatin)
+ {
+ free(Ld_CWD);
return;
- sprintf(moveToKeyLocatin, "mkdir -p %s/%s", LDMICRO_REGISTER, subKey);
- system(moveToKeyLocatin);
- sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey);
- if (-1 == system(moveToKeyLocatin))
+ }
+ sprintf(moveToKeyLocatin, "mkdir -p %s/%s", FREEZE_REGISTER, subKey);
+ system(moveToKeyLocatin);
+ sprintf(moveToKeyLocatin, "%s/%s", FREEZE_REGISTER, subKey);
+ if (-1 == chdir(moveToKeyLocatin))
+ {
+ free(Ld_CWD);
+ free(moveToKeyLocatin);
return;
+ }
free(moveToKeyLocatin);
std::ofstream Register(name, std::ios::trunc);
Register << strlen(val)+1 << "\n";
Register << val;
Register.close();
+
+ chdir(Ld_CWD);
+ free(Ld_CWD);
}
/*
@@ -247,19 +371,38 @@ void FreezeStringF(char *val, char *subKey, char *name)
*/
void ThawStringF(char *val, int max, char *subKey, char *name)
{
+ char* Ld_CWD = (char *)malloc(MAX_PATH);
+ getcwd(Ld_CWD, sizeof(Ld_CWD));
+
+ if (!Ld_CWD)
+ return;
+
char* moveToKeyLocatin = (char *)malloc(strlen(name) + 30);
if(!moveToKeyLocatin)
+ {
+ free(Ld_CWD);
return;
- sprintf(moveToKeyLocatin, "cd %s/%s", LDMICRO_REGISTER, subKey);
- if (-1 == system(moveToKeyLocatin))
+ }
+ sprintf(moveToKeyLocatin, "%s/%s", FREEZE_REGISTER, subKey);
+ if (-1 == chdir(moveToKeyLocatin))
+ {
+ free(Ld_CWD);
+ free(moveToKeyLocatin);
return;
+ }
free(moveToKeyLocatin);
std::ifstream Register(name);
int l;
Register >> l;
if (l >= max)
+ {
+ free(Ld_CWD);
return;
+ }
Register >> val;
+
+ chdir(Ld_CWD);
+ free(Ld_CWD);
}