NSIS : How to keep input value from previous dialog after click Next/Back button? - textbox

If I change value in textbox and click Next button, then click Back button to back to the page again, I wanna keep new value that I changed it in textbox. How can I do?
This is my code :
AcustomPage.nsh
!macro create_AcustomPage APP_NAME CUS_FULLNAME
Page custom create_AcustomPage leave_AcustomPage
Function create_AcustomPage
Push $0
StrCpy $AcustomPage.FirstOpened 0
nsDialogs::Create 1018
Pop $AcustomPage
GetDlgItem $AcustomPage.Button.Next $HWNDPARENT 1
System::Call user32::GetWindowText(i$AcustomPage.Button.Next,t.s,i${NSIS_MAX_STRLEN})
nsDialogs::CreateControl STATIC ${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS} 0 0u 0u 100% 20u "${AcustomPage_TITLE}"
Pop $AcustomPage.Text
${NSD_CreateGroupBox} 0u 20u 100% 78% "AcustomPage Setting"
Pop $AcustomPage.SettingBox
${NSD_CreateLabel} 10u 50u 20u 11u "URL:"
Pop $AcustomPage.FULLNAME.Label
${NSD_CreateText} 60u 50u 60% 11u ""
Pop $0
${NSD_OnChange} $0 Update_AcustomPage_Next_Button
${If} ${CUS_FULLNAME} != ""
${NSD_SetText} $0 ${CUS_FULLNAME}
${EndIf}
Call Update_AcustomPage_Next_Button
nsDialogs::Show
FunctionEnd
Function leave_AcustomPage
${NSD_GetText} $0 $CUS_FULLNAME
FunctionEnd
Function Update_AcustomPage_Next_Button
Push $R5
${NSD_GetText} $0 $R5
${If} $R5 != ""
EnableWindow $AcustomPage.Button.Next 1
Return
${EndIf}
${If} $R5 == ""
EnableWindow $AcustomPage.Button.Next 0
Return
${EndIf}
Pop $R5
FunctionEnd
!macroend
Thanks,

You are on the right track by always saving the text in $CUS_FULLNAME in the leave callback but you never use $CUS_FULLNAME to set the text when creating the page, you seem to try to do something with ${CUS_FULLNAME} instead!
It should probably look more like this:
${NSD_CreateText} 60u 50u 60% 11u "${CUS_FULLNAME}"
Pop $0
${If} $CUS_FULLNAME != ""
${NSD_SetText} $0 $CUS_FULLNAME
${EndIf}
${NSD_OnChange} $0 Update_AcustomPage_Next_Button
Here is a standalone example:
!include nsDialogs.nsh
var hCtlFullName
var FullName
Function mypageCreate
nsDialogs::Create 1018
Pop $0
${NSD_CreateText} 60u 30u 60% 11u "$FullName"
Pop $hCtlFullName
${NSD_OnChange} $hCtlFullName mypage_VerifyInput
call mypage_VerifyInput
nsDialogs::Show
FunctionEnd
Function mypageLeave
${NSD_GetText} $hCtlFullName $FullName
FunctionEnd
Function mypage_VerifyInput
Call mypageLeave ; Loads the text into $FullName
Push $0
GetDlgItem $0 $HWNDPARENT 1
${If} $FullName == ""
EnableWindow $0 0
${Else}
EnableWindow $0 1
${EndIf}
Pop $0
FunctionEnd
Page Custom mypageCreate mypageLeave
Page Components
Page InstFiles
Section
DetailPrint $FullName
SectionEnd

Related

New to LUA, i have question about my script

Hello im new to LUA and in general new to scripting/coding
This is script what im talking about
print("Type a Number!")
repeat
input = io.read()
if input == "10" then
print("Ten")
elseif input == "7" then
print("Seven")
elseif input == "1" then
print("One!")
elseif input == "exit" or input == "Exit" then
print("Exiting...")
else
print("incorrect")
end
until input == "Exit" or input == "exit"
I kinda feel like there is too much elseif but I didn't want to print "incorrect" when i type exit or Exit so my solution was to add another elseif before else command. Can be this be more simplified or i can't do nothing with it and its good
And one more question why this is not working
num = 10
input = io.read()
If input == num then
print("Ten")
end
Or this code
num = 10
input = io.read()
If input == 10 then
print("Ten")
end
Why code above where i have boolean with string after if, only works
Define your behaviour
local actions = {
[1] = function() print("One");
-- Same for any other numbers you want
["exit"] = function() os.exit() end; -- Close the whole program
}
Get your input
local input = io.read() -- This returns a string
Normalize your input
input = input:lower() -- Make the whole string lowercase
input = tonumber(input) or input -- Try converting to number
Get the action matching your input
local action = actions[input]
Run the action if one was found
if action then
action()
else
print("Error! Could not handle input: ", input)
end
local inputs = {
['1'] = 'One!'
, ['7'] = 'Seven'
, ['10'] = 'Ten'
, exit = 'Exiting...'
, Exit = 'Exiting...'
}
local input
print 'Type a Number!'
repeat
input = io.read ()
print (inputs [input] or 'incorrect') -- Lua 'nullsafe' operator.
until input == 'Exit' or input == 'exit'

Generate electron app.exe which will ask for user input during installation (using electron-builder and nsis)?

I am trying to generate electron app.exe with the use of **electron-builder** and **nsis**, which should ask user input at time of installation.
Following is my **package.json**.
...
"build": {
"appId": "com.electron.test",
"productName": "test",
"win": {
"target": [
"nsis"
],
"icon": "assets/icon.ico"
},
"nsis": {
"warningsAsErrors": false,
"installerIcon": "assets/icon.ico",
"runAfterFinish": false,
"oneClick": false,
"perMachine": true,
"allowToChangeInstallationDirectory": true,
"installerHeader": "assets/installerHeader.bmp",
"include": "build/installer.nsh"
},
"mac": {
"category": "your.app.category.type"
}
}
...
I want to display custom page **Between** Select Location Page and Installation Progress Page.
Following is my **installer.nsh** which is create one custom page i.e. ask for user to input username and password.
!include "EnvVarUpdate.nsh"
!include "MUI2.nsh"
!include "nsDialogs.nsh"
!include "LogicLib.nsh"
Var Dialog
Var UserLabel
Var UserText
Var UserState
Var PassLabel
Var PassText
Var PassState
;--------------------------------
; Show install details
ShowInstDetails show
;--------------------------------
;Interface Settings
!define MUI_ABORTWARNING
Page custom nsDialogsPage nsDialogsPageLeave
Function nsDialogsPage
nsDialogs::Create 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}
${NSD_CreateLabel} 0 0 100% 12u "Username:"
Pop $UserLabel
${NSD_CreateText} 0 13u 100% 12u $UserState
Pop $UserText
${NSD_CreateLabel} 0 39u 100% 12u "Password:"
Pop $PassLabel
${NSD_CreatePassword} 0 52u 100% 12u $PassState
Pop $PassText
nsDialogs::Show
FunctionEnd
Function nsDialogsPageLeave
${NSD_GetText} $UserText $UserState
${NSD_GetText} $PassText $PassState
${If} $UserState == ""
MessageBox MB_OK "Username is missing."
Abort
${EndIf}
${If} $PassState == ""
MessageBox MB_OK "Password is missing."
Abort
${EndIf}
StrCpy $1 $UserState
StrCpy $2 $PassState
FileOpen $9 $INSTDIR\credentials.txt w
FileWrite $9 "$1:$2"
FileClose $9
SetFileAttributes $INSTDIR\credentials.txt HIDDEN|READONLY
FunctionEnd
Section
SectionEnd
!macro customHeader
!macroend
!macro preInit
!macroend
!macro customInstall
${EnvVarUpdate} $0 "PATH" "A" "HKLM" "$INSTDIR"
!macroend
!macro customUnInstall
${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$INSTDIR"
!macroend
Please provide any solution.
**Thanks & Regards**
Rachit V. Sakhidas
It looks like everything is correct. The NSIS script posted is for creating your custom page. What is your question? Do you have any errors or you just do not know what to do?
Q: Your page is not shown in installer?
If no: Did you include you custom page in the electron-nsis script so the page is actually shown?
Q: Do you have troubles with creating custom pages?
If yes: try this tool: https://nsis.sourceforge.io/Install_Designer (I am its developer so feel free to ask here any questions).
It is really tough to says what is wrong with this few information, please post full scripts and logs.

ComputerCraft tracking Lua "io" library exceptions

I am currently trying to debug a Minecraft-based turtle farming script with functions and API functions.
When I am executing I get an 'io' exception (which is understandable as I am trying to write to a log for each loop), but it doesn't tell me which script it is in or the line number. Are there any solutions apart from printing throughout program execution?
Exception I have been getting:
io:107: index expected, got nil
main turtle-farming script:
--[[main script for farming procedure]]
--load functions responsible for positioning/repositioning/farming
os.loadAPI("APIS/positioners");
os.loadAPI("APIS/farmers");
--action turtle start farming condition
assert(positioners.check_start_pos(), "Could not initialise the turtle for the farming procedure\nCould not identify it's starting location\n(are there birch planks directly above and beneath it?");
--check Netherrack can be found from start block, declare 'dir' also as local
local init_result, dir = positioners.find_next_neth()
assert(init_result, "Could not find the appropriate direction to travel in from\n the turtle starting position, is the farm set up correctly?");
local loop_vars = {["count"] = 0, ["blockId"] = nil, ["dir"] = nil, ["prevManvr"] = nil, ["action"] = ""};
--**input** assertion tests for required fuel level and seed requirements
assert(turtle.getFuelLevel() > 50, "Fuel level is below required level to start farming, - terminating");
--given 'result' == true can start farming
turtle.forward();
--open log file (overwrite) and save to io class handle
log = io.open("logs/proc_log", "w");
--start main farming process loop
while turtle.getFuelLevel() > 0 do
--reset action variable
loop_vars["action"] = "";
--sort log variables
loop_vars["count"] = loop_vars["count"] + 1;
--identify the block above (returns inv slot(1-4) it matches with or false if it doesn't)
loop_vars["blockId"] = positioners.id();
if blockId == 1 then
loop_vars["action"] = "Netherrack above ";
if loop_vars["dir"] == nil then
print("Netherrack found, planting");
farmers.plant();
--shift turtle forward such that it can evaluate a new block. Ensure that moves forward in case of obstruction
assert(turtle.forward(), "The turtle is impeded from moving forwards in farming route");
--log statement
loop_vars["action"] = loop_vars["action"].."plant and move forward";
else
--initiate change in direction procedure
assert(positioners.change_direction(loop_vars["dir"]), "Failed to complete turtle change direction procedure");
--reset dir
loop_vars["dir"] = nil;
loop_vars["action"] = loop_vars["action"].." actioned 'positioners.change_position(dir)'.";
end;
elseif blockId == 3 then
turtle.forward();
--log statement
loop_vars["action"] = "Proceeding past marble block";
elseif blockId == false then
print("Finding next Netherrack block.");
--retrace back to the most recent 'legitimate' block");
turtle.back();
--call function to reposition turtle for next farming line
result, loop_vars["dir"] = positioners.find_next_neth(loop_vars["prevMan"]);
assert(result, "A new netherrack block could not be found in any direction.");
--assign dir result to prevMan (information for next positioners.change_position() call
loop_vars["prevMan"] = loop_vars["dir"];
--log statement
loop_vars["action"] = "No 'legitimate' block above, 'positioners.find_next_neth() successful,\nassigning dir accordingly.";
else
--log statement
log.write("Unhandled exception in farm_proc main loop");
log.close();
error("positioners.find_next_neth() did not find an appropriate block above it.");
end;
print("farm_proc loop");
--write current turn to log file
log.write("Turn no: "..loop_vars["count"].."\n Id()== "..tostring(loop_vars["blockId"]).."\n Action: "..loop_vars["action"].."\n Previous maneuver: "..loop_vars["prevMan"].."\n\n");
end;
--updating log
log.write("Error - turtle ran out of fuel\n");
log.close();
error("Turtle ran out of fuel whilst planting - terminated");
'positioners' api (movement/detection based tasks):
function find_next_neth(prevMan)
--[[Find direction of the next overhead block of Netherrack from turtle's current pos,
Order;
N
E
W
S
Error (no direction found)]]
--define numbers corresponding to directions
local dirs = {"Back", "Left", "Right", "Forward"};
--create a loop counter to ensure does not exceed full checking loop
local counter = 4;
--loop through movement proc. until netherrack (slot 1) is found above it (if at all)
while true do
print("Looping, current loop counter is: ", counter);
local idAhead = id_ahead();
if counter == 4 then
--placeholder, script should never need to find forwards
elseif counter == 3 then
turtle.turnLeft();
elseif counter == 2 then
turtle.turnRight();
turtle.turnRight();
elseif counter == 1 then
turtle.turnRight();
--decremented counter has reached it's minimum
elseif counter < 1 then
return false, nil;
else
error("For find_next_neth iteration counter out of range");
end;
--decrement counter variable
counter = counter - 1;
--boolean condition to determine whether function is complete, incomplete or broken. 'prevMan' as a logical statement will return true if var has value, and false if not
local testPrev = (not prevMan == dir[(math.abs(counter - 4) + 1))] or not prevMan);
local validBlock = (idAhead == 1 or idAhead == 3)
if testPrev and validBlock then
--all tests are valid - break loop to return
break;
end;
--report success and return result
print("Nether found!\n");
return true, dirs[counter];
end;
end;
function change_direction(dir)
--intialise a base error string
local errMsg = "Could not action positioners.change_direction(dir, prevMan) ";
if dir == "East" then
assert(turtle.forward(), errMsg.."Obstruction to route");
--this should finalise a 180deg turn to the left
turtle.turnLeft()
elseif dir == "West" then
assert(turtle.forward(), errMsg.."Obstruction to route");
--180deg turn left
turtle.turnRight()
elseif dir == "North" then
--no action
elseif dir == "South" then
error("Return to start not yet implemented");
else
error("positioners.change_direction() parameter not as expected");
end;
return true;
end;
function id(slot)
--[[Determines if netherrack is currently above turtle.
Return false means the block
above does not match slots 1-4 of the
turtle's inv. Takes optional int
for specific block slot index
in turtle compare]]
--checking argument
if slot ~= nil then
--select slot given as argument
turtle.select(slot);
if turtle.compareUp() then
--don't return int because specific material requested
return true;
else
return false;
end;
end;
counter = 1
while counter < 5 do
turtle.select(counter);
--identify whether the current selected slot item matches the blovk overhead
if turtle.compareUp() then
--return block above's corresponding slot index
return counter
end;
counter = counter + 1;
end;
--return number indicating unidentfied block
return false;
end;
function id_ahead(slot)
if turtle.forward() then
--save value of id call for later return
local rtn = id(slot)
turtle.back();
return rtn
else
error("turtle could not move forwards in id_ahead(slot)");
end;
end;
function check_start_pos()
--set selected slot to birch planks (no currently selected method implemented so cannot revert this change internally)
turtle.select(2);
--save boolean variables for comparison of blocks above and below position
local up = turtle.compareUp();
local down = turtle.compareDown();
--test if above boolean values are true (turtle in designated start position)
if up and down then
return true;
else
print("Not in appropriate farming start position");
return false;
end;
end;
(The 'farmers' api simply checks current seeds and then plants a crop through farmers.plant())
I believe I have found the solution - the debug library, specifically debug.traceback() allows you to introspect the call stack more closely when catching an error
debug library index

NSD_CreateText not populating stack

For my NSIS script I need some user info, so I have the following code:
Function tomcatConfig
!insertmacro MUI_HEADER_TEXT "$(TEXT_CONF_TITLE)" "$(TEXT_CONF_SUBTITLE)"
nsDialogs::Create 1018
Pop $0
${NSD_CreateLabel} 0 2u 100u 14u "Tomcat shutdown port"
Pop $R0
${NSD_CreateText} 150u 0 50u 12u "8005"
Pop $CtlTomcatPortShutdown
${NSD_SetTextLimit} $CtlTomcatPortShutdown 5
${NSD_CreateLabel} 0 19u 100u 14u "Tomcat default http port"
Pop $R0
${NSD_CreateText} 150u 17u 50u 12u "80"
Pop $CtlTomcatPortHttp
${NSD_SetTextLimit} $CtlTomcatPortHttp 5
${NSD_CreateLabel} 0 36u 100u 14u "Tomcat default https port"
Pop $R0
${NSD_CreateText} 150u 34u 50u 12u "443"
Pop $CtlTomcatPortSSL
${NSD_SetTextLimit} $CtlTomcatPortSSL 5
${NSD_CreateLabel} 0 57u 140u 14u "Tomcat service name"
Pop $R0
${NSD_CreateText} 150u 55u 140u 12u "Servicename"
Pop $CtlTomcatServiceName
${NSD_SetFocus} $CtlTomcatPortShutdown
nsDialogs::Show
FunctionEnd
When I am using $CtlTomcatPortShutdown, $CtlTomcatPortHttp, $CtlTomcatPortHttp, $CtlTomcatServiceName in my script, I get returned some random number, instead of the input I expect (service name, port numbers etc.).
This sample from NSIS NsDialog page also looks invalid on Windows 10, when I use $Text I am returned a random number as well.
!include nsDialogs.nsh
!include LogicLib.nsh
Name nsDialogs
OutFile nsDialogs.exe
XPStyle on
Var Dialog
Var Label
Var Text
Page custom nsDialogsPage
Page instfiles
Function nsDialogsPage
nsDialogs::Create 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}
${NSD_CreateLabel} 0 0 100% 12u "Hello, welcome to nsDialogs!"
Pop $Label
${NSD_CreateText} 0 13u 100% -13u "Type something here..."
Pop $Text
nsDialogs::Show
FunctionEnd
Section
DetailPrint "hello $Text"
SectionEnd
The ${NSD_CreateXYZ} macros return the handle (HWND) to the control on the stack, not a random number. This handle can be used in calls to ${NSD_GetText} and ${NSD_SetText} etc.

convert feedback comments rtl or ltr depending on language

I have a php feedback form that I want the comment text to be aligned to left or right depending on language:
if Arabic should be aligned rtl, any other language no (default which is ltr)
This is the current code line (that makes everything right to left!):
$comment = "<p dir=\"rtl\">".str_replace ("\n", "<br />", $comment);
so I want to tell it: if Arabic, then rtl, if not Arabic, ignore that rtl
function containsArabic($str)
{
return preg_match('~\p{Arabic}~u', $str);
}
echo containsArabic('helloسلام'); // rturn 1
echo containsArabic('سلام');//return 1
echo containsArabic('testسلامtest'); // return 1
echo containsArabic('test');// return 0
if the text contain Arabic letter the function return 1 else return 0
You can use these regex'es to determine whether the comments contain Arabic or Persian chars.
function containsArabic($str)
{
return preg_match('~\p{Arabic}~u', $str);
}
echo containsArabic('helloسلام');
echo containsArabic('سلام');
echo containsArabic('testسلامtest');
echo containsArabic('test');

Resources