#1 2013-01-21 21:29

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Store variable for reuse (Get/Set) RegWrite / RegRead

To store and reuse information, it would nice to have a new registry write and read function.

The reg path could be set default to "HKCU\Software\den4b\ReNamer"


Then there could be two simple parameters only: Name and Value.

Example:

script one, write:
RegWrite(Name, Value);
RegWrite('ParentFolder', 'X:\Music\Jazz\unsorted');


script two, read:
val := RegRead(Name);
val := RegRead('ParentFolder');



EDIT:
OTOH, since we could use this for other registry keys too, i think better would be
RegWrite(Key, Name, Value);
RegRead(Key, Name);

.


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#2 2013-01-25 13:30

Andrew
Senior Member
Registered: 2008-05-22
Posts: 542

Re: Store variable for reuse (Get/Set) RegWrite / RegRead

Can't you simply call Windows\System32\reg.exe or Windows\SysWOW64\reg.exe instead?

REG Operation [Parameter List]

  Operation  [ QUERY   | ADD    | DELETE  | COPY    |
               SAVE    | LOAD   | UNLOAD  | RESTORE |
               COMPARE | EXPORT | IMPORT  | FLAGS ]

Return Code: (Except for REG COMPARE)

  0 - Successful
  1 - Failed

For help on a specific operation type:

  REG Operation /?

Examples:

  REG QUERY /?
  REG ADD /?
  REG DELETE /?
  REG COPY /?
  REG SAVE /?
  REG RESTORE /?
  REG LOAD /?
  REG UNLOAD /?
  REG COMPARE /?
  REG EXPORT /?
  REG IMPORT /?
  REG FLAGS /?

I would suggest using this instead of all the extra work required to add registry editing functionality to ReNamer, not to mention the extensive testing required (obviously, since a bug could wreak havoc with the registry and no one wants that!)

Offline

#3 2013-01-27 00:12

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,374

Re: Store variable for reuse (Get/Set) RegWrite / RegRead

It is possible to add these functions, but it might not be a good idea to use these functions for storing temporary data. Registry is very fragile and sensitive, as we are all aware. It's too easy to mess things up in a big way by allowing users easily manipulate it.

So, I would suggest using temporary files for storing such data. I can add a function which will return a path to the temporary folder where users can easily store temporary data using FileReadContent and FileWriteContent functions.

How does that sound?

Offline

#4 2013-01-27 01:21

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,374

Re: Store variable for reuse (Get/Set) RegWrite / RegRead

I've added WideGetTempPath function to the latest development version.

Offline

#5 2013-01-27 01:29

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Store variable for reuse (Get/Set) RegWrite / RegRead

Denis> but it might not be a good idea...It's too easy to mess things up
Ok, but not if you set the key to default "HKCU\Software\den4b" and prevent other paths.

Writing to file will work also.

If we can more easily access the tmp folder it would help to get an dir to store that file.
And the script would work for all users on all systems by using default dirs.

So fine too, no need to add another storing method.
Thanks.




Will you implement this feature to expand all env vars? Like
tmp := ExpandEnvironmentStrings( "%TEMP%" );
FileWriteContent(tmp + '\den4b.txt', 'test');


Or just an build-in var UserTemp like FileName and FilePath?
FileWriteContent(UserTemp + '\den4b.txt', 'test');


I guess it's to much work to expand env vars on the fly ? Like
FileWriteContent('%TMP%\den4b.txt', 'test');



600


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#6 2013-01-27 01:59

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Store variable for reuse (Get/Set) RegWrite / RegRead

Andrew wrote:

Can't you simply call Windows\System32\reg.exe or Windows\SysWOW64\reg.exe instead?

That would need additional work on the query part, since console apps are verbose on output.
Not really a big deal but for average users it will be.

The goal is always: one function; one usable result

Make it easy for non-coders.


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#7 2013-01-27 11:57

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Store variable for reuse (Get/Set) RegWrite / RegRead

Beta 27. Jan. 2013

den4b wrote:

I've added WideGetTempPath function to the latest development version.


Thanks, works too in theory. Have to check in real.


First rule in rule list:
(GET stored variable 'LastFolder')

var
  LastF:string;

begin
 if(GetCurrentFileIndex=1)then
    if(WideFileExists(WideGetTempPath +'\den4b_LastFolder.txt')) then
        LastF := FileReadContent(WideGetTempPath +'\den4b_LastFolder.txt');

  ShowMessage(LastF);
end.


Last rule in rule list:
(SET variable 'LastFolder' to stored for later reuse)

var
  ParentF:string;

begin
 if(GetCurrentFileIndex=GetTotalNumberOfFiles)then
   begin
       ParentF:=CalculateMetaTag(FilePath, 'File_FolderName');
       FileWriteContent(WideGetTempPath +'\den4b_LastFolder.txt',ParentF);
   end;
 
  ExecuteProgram('notepad ' + WideGetTempPath + '\den4b_LastFolder.txt',false);
end.

* To complete, there is also a delete command:
      WideDeleteFile(WideGetTempPath +'\den4b_LastFolder.txt');



* To store other variable use different files like 'den4b_LastUsed_INDEX.txt'



* Two thinks i see:
  - the second parameter for ExecConsoleApp() is mandatory, even i won't use it. But i have to create a var for this first. Not needed.
EDIT: just use "ExecuteProgram()" instead roll

  - and BTW: i can't use var name "out". I get an error message. Is this a kind of build-in var? Or an misbehavior?



* Please consider to add also WideGetReNamerPath to keep things together.
EDIT: and it surely works already relative:
FileWriteContent('.\den4b_LastFolder.txt',ParentF);
FileWriteContent('den4b_LastFolder.txt',ParentF);
Suggestion withdrawn.


.


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#8 2013-01-27 12:15

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,374

Re: Store variable for reuse (Get/Set) RegWrite / RegRead

Will you implement this feature to expand all env vars? Like
tmp := ExpandEnvironmentStrings( "%TEMP%" );
FileWriteContent(tmp + '\den4b.txt', 'test');

There is a function called WideGetEnvironmentVar in ReNamer:Pascal_Script:Functions#System.

- the second parameter for ExecConsoleApp() is mandatory, even i won't use it. But i have to create a var for this first. Not needed.
- and BTW: i can't use var name "out". I get an error message. Is this a kind of build-in var? Or an misbehavior?

ExecConsoleApp is designed for console applications and captures output of the executed program. "out" is the same as "var" in the function declaration, they signify that variable can be modified by the function. "out" notation is used to hint the user that function doesn't use it for input, only for output. If you don't need to capture the output, you can use ExecuteProgram with WaitForProgram=True.

Please consider to add also WideGetReNamerPath to keep things together.

You'll find GetApplicationPath and GetApplicationParams in ReNamer:Pascal_Script:Functions#Application.

Offline

#9 2013-01-27 12:59

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Store variable for reuse (Get/Set) RegWrite / RegRead

Thanks Denis. I will collect them all under one topic.
Time for an new wiki page?
(done > wiki/ReNamer:Scripts:Reuse_variable  > http://www.den4b.com/wiki/ReNamer:Scrip … _variable)


To store values for later reuse i have made a few additional test.


We can also use      FileAppendContent();  and a routine to read the lines of a common vars.txt.
But that is more  code then simply use different text files for different var values.

Here just as proof of concept:

Last rule:

     FileAppendContent('den4b_LastFolder2.txt','LastFolder=' + ParentF + #13#10);

First rule:
- read the vars.txt
- split into lines
- split line into 'name' and 'value'
- check if 'name' is a wanted var name, if yes get the value

var
  vars,v:string;
  Lines,CurrLine:TStringsArray;
  i:integer;

begin
 if(GetCurrentFileIndex=1)then
 begin
   if( WideFileExists('.\den4b_vars.txt') ) then
   begin
      vars := FileReadContent('.\den4b_vars.txt');
      ShowMessage('complete content:'+#10+vars);
      Lines:= WideSplitString(vars, #13#10);
      if( length(Lines) > 0 ) then
        begin
            for i:=0 to length(Lines)-1 do
            begin
               CurrLine := WideSplitString(Lines[i],'=');
               v := CurrLine[0];
               //ShowMessage(v);
               if ( WideCompareText( v, 'LastIndex' ) =0) then
                   ShowMessage( v + ' has value ' + CurrLine[1] );
               if ( WideCompareText( v, 'LastFolder' ) =0) then
                   ShowMessage( v + ' has value ' +  CurrLine[1] );
               if ( WideCompareText( v, 'LastString' ) =0) then
                   ShowMessage( v + ' has value ' +  CurrLine[1] );
            end;
        end;
   end;
 end;
end.

Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

Board footer

Powered by FluxBB