Author Topic: customizing save command  (Read 9385 times)

hs2

  • Senior Community Member
  • Posts: 2735
  • Hero Points: 287
Re: customizing save command
« Reply #30 on: July 22, 2014, 08:38:24 am »
I guess 'does (not) contain "labx"' is the filter for (not) making backups.
Seems ok as far as I can see. And your own tests will easily tell you if it's working as expected ;)
Good luck, HS2

vineetvijay12

  • Community Member
  • Posts: 29
  • Hero Points: 0
Re: customizing save command
« Reply #31 on: July 28, 2014, 07:53:12 am »
i caught up in a condition where some of the users mapped vvijay_test_protocols_test_lbx_wtl as some drive lets say k
so when i open a file in slickedit i get K:\wvv-test\makedoc not getting vvijay_test_protocols_test_lbx_wtl , is there a way i can get full path including network drive in such case.

if no way directly on lsickedit, can i run some commands to get windows registery key values.
« Last Edit: July 28, 2014, 09:30:59 am by vineetvijay12 »

hs2

  • Senior Community Member
  • Posts: 2735
  • Hero Points: 287
Re: customizing save command
« Reply #32 on: July 28, 2014, 09:41:31 am »
I guess they subst'd the mounted share. So you could either invoke 'subst' as shell command, redirect and parse it's output to retrieve and store (static variable) the mapping automagically or add a (static) variable and let the user enter the mapping manually.
Concerning the 1st approach you should do it (silently) on demand ie. on failure and not during each save.
The 2nd way is much simpler, of course. You could prompt the user to enter the mapping on failure.
HS2

hs2

  • Senior Community Member
  • Posts: 2735
  • Hero Points: 287
Re: customizing save command
« Reply #33 on: July 28, 2014, 09:49:29 am »
And yes - SE supports registry queries on Windows.
There are some (I think undocumented) SE functions '_ntRegQueryValue', '_ntRegFindValue', etc.
Try to lookup '_ntReg' in the SE macro sources ('<SE install dir>/macros') to find out howto use them.
Good luck, HS2

vineetvijay12

  • Community Member
  • Posts: 29
  • Hero Points: 0
Re: customizing save command
« Reply #34 on: July 28, 2014, 10:08:22 am »
i want to fetch drive letter of source path, i am using below expression to get path except drive letter
src := strip_filename(p_buf_name, 'DN');
 what expression should i use to get drive letter alone

hs2

  • Senior Community Member
  • Posts: 2735
  • Hero Points: 287
Re: customizing save command
« Reply #35 on: July 28, 2014, 10:18:04 am »
substr( p_buf_name, 1, 2 ); to get e.g. 'K:'. see the docs for 'substr' details.
HS2

vineetvijay12

  • Community Member
  • Posts: 29
  • Hero Points: 0
Re: customizing save command
« Reply #36 on: July 28, 2014, 11:36:28 am »
if i pass  static value to _ntRegQueryValue, it is working fine but it is not if i  pass some dynamic value.

Working:
src1 := _ntRegQueryValue(HKEY_CURRENT_USER, "Network\\F", "", "RemotePath");

Not working:
drivepath := "Network\\" :+ Drive;
 src1 := _ntRegQueryValue(HKEY_CURRENT_USER, "drivepath", "", "RemotePath");

hs2

  • Senior Community Member
  • Posts: 2735
  • Hero Points: 287
Re: customizing save command
« Reply #37 on: July 28, 2014, 12:18:54 pm »
Don't quote your variable drivepath: "drivepath" -> drivepath
HS2

vineetvijay12

  • Community Member
  • Posts: 29
  • Hero Points: 0
Re: customizing save command
« Reply #38 on: July 28, 2014, 01:58:07 pm »
i got atatched error when tried this

 if (Drive != "M")
         {
         drivepath := "Network\\" :+ Drive;
          src1 := _ntRegQueryValue(HKEY_CURRENT_USER, drivepath, "", "RemotePath")

     _str pparts1[];
     split(src1, FILESEP, pparts1);  // split path, get root
   
     if (pparts1._length() > 2)
   {
      _str uparts[];
      split(pparts1[3], '_', uparts);   // split root, get usr (1st), viewtype (2nd last) and site (last)
      if (uparts._length() > 2)
      {
         usr = uparts[0];
         site = uparts[uparts._length() -1];
         viewtype = uparts[uparts._length() -2];

      }
     }
       }
« Last Edit: July 28, 2014, 01:59:45 pm by vineetvijay12 »

hs2

  • Senior Community Member
  • Posts: 2735
  • Hero Points: 287
Re: customizing save command
« Reply #39 on: July 28, 2014, 06:30:56 pm »
@vineetvijay12: Sorry, but your report lacks the minimum level of detail needed to do anything.
Which function call / source line failed ? What's the input ?
You should post code with proper formatting. There is this cool '#' button to CODE-tag a selection (see the example below - note the very useful Select link)
Your code is incomplete and contains a syntax error.
SE tells you on loading your macro code that there is no ';' at the end of line
Code: [Select]
_ntRegQueryValue(HKEY_CURRENT_USER, drivepath, "", "RemotePath")
So maybe again you're trapped by running the previous / last successfully compiled macro causing the error b/c you ignored the compile error ?

What did you try yourself solving your own problem and what's your question where you're stuck ?
I assume you don't expect that someone else solves all your problems ;)

Good luck,
HS2

vineetvijay12

  • Community Member
  • Posts: 29
  • Hero Points: 0
Re: customizing save command
« Reply #40 on: July 28, 2014, 07:06:25 pm »
Even i thought that it might be due to old macro as i am trying out something countinously.

I already tried with fresh installation.
here i am trying to acheive that if Drive is not m then get the second parameter vvijay_... from registry key.
somehow i missed semicolon while pasting the code.
so if i pass  static value to _ntRegQueryValue it is working fine but it is not if i  pass some dynamic value.

Working:
src1 := _ntRegQueryValue(HKEY_CURRENT_USER, "Network\\F", "", "RemotePath");

Not working:
drivepath := "Network\\" :+ Drive;
 src1 := _ntRegQueryValue(HKEY_CURRENT_USER, drivepath, "", "RemotePath");

here is code snip

Code: [Select]
#pragma option(strict,on)
#include 'slick.sh'

void _cbsave_vvijay  (...)
{
   src := strip_filename(p_buf_name, 'DN');
   Drive := substr(p_buf_name, 1, 1 );
   _str usr = "", site = "", viewtype = "";

      if (Drive != "M")
         {
         drivepath := "Network\\" :+ Drive;
    src1 := _ntRegQueryValue(HKEY_CURRENT_USER, drivepath, "", "RemotePath");

     _str pparts1[];
     split(src1, FILESEP, pparts1);  // split path, get root
     _message_box("pparts1 is '" pparts1[3] "'");

     if (pparts1._length() > 2)
   {
      _str uparts[];
      split(pparts1[3], '_', uparts);   // split root, get usr (1st), viewtype (2nd last) and site (last)
      if (uparts._length() > 2)
      {
         usr = uparts[0];
         site = uparts[uparts._length() -1];
         viewtype = uparts[uparts._length() -2];

      }
     }
       }

      else
      {
   _str pparts[];
   split(src, FILESEP, pparts);  // split path, get root
   if (pparts._length() > 2)
   {
      _str uparts[];
      split(pparts[1], '_', uparts);   // split root, get usr (1st), viewtype (2nd last) and site (last)
      if (uparts._length() > 2)
      {
         usr = uparts[0];
         site = uparts[uparts._length() -1];
         viewtype = uparts[uparts._length() -2];
      }
   }
      }

   if (viewtype == "labx")
   {
         message("view is a labx view, will copy file to stage area under your home directory");
       if ( (site :!= "blr") || (site :!= "wtl") )
       //if ( (usr._length() == 0) || (site._length() == 0) )
   {
      _message_box("error: unexpected src path naming");
      return;
    }

   
   dst := '\\' :+ site :+ "home-1\\" :+ "home\\" :+ get_env("USERNAME") :+ "\\stage_area" :+ src;

   if ( !path_exists(dst) )
   {
      int err = make_path(dst);
      if (err)
      {
         _message_box("make_path '" dst "' failed - rc =" err);
         return;
      }
   }

   dst :+= strip_filename(p_buf_name, 'DP');
   //message("backing up '" src "' to '" dst "' ... ");
   err := copy_file(p_buf_name, dst);
   if ( err )
   {
      _message_box("copy_file '" dst "' failed - rc = " err);
   } 
   
   } 
}
« Last Edit: July 28, 2014, 07:10:58 pm by vineetvijay12 »

hs2

  • Senior Community Member
  • Posts: 2735
  • Hero Points: 287
Re: customizing save command
« Reply #41 on: July 28, 2014, 08:40:17 pm »
So drivepath is also set to something like 'Network\\F' ?
Did you verify the contents of 'drivepath' using e.g.
Code: [Select]
say( "drivepath '" drivepath "' -> src1 '" src1 "'");
Be more careful with arrays ;)
This is safe (with _length > 3 you can access element 3):
Code: [Select]
      if ( pparts1._length() > 3 )
      {
         _message_box("pparts1 is '" pparts1[3] "'");

         _str uparts[];
         split(pparts1[3], '_', uparts);   // split root, get usr (1st), viewtype (2nd last) and site (last)
...

I can't see any problem using variable 'drivepath' set to sth. like 'Network\\F' and a literal string 'Network\\F' at the moment ...

I even tried this tiny but basically similar example accessing a registry key and it works as expected:
Code: [Select]
      drivepath := "SOFTWARE\\Microsoft\\VisualStudio\\" :+ "12.0";
      src1 := _ntRegQueryValue(HKEY_LOCAL_MACHINE, drivepath,"","InstallDir");
      say( "drivepath '" drivepath "' -> src1 '" src1 "'");

HS2

hs2

  • Senior Community Member
  • Posts: 2735
  • Hero Points: 287
Re: customizing save command
« Reply #42 on: July 28, 2014, 10:25:43 pm »
Another hint especially in your case:
Since your code is involved in saving files it's a critical path also affecting compile/saving your macro file.
So better move the code out of the '_cbsave_' callback to a normal macro command like this:
Code: [Select]
_command void vijay_cb_save() name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_EDITORCTL)
{
...
}
With this you can easily develop and test the code until it's working properly without any trouble when saving files.
You can simply invoke it on SE command line after loading it (enter: vijay-cb-save) and/or bind it to a shortcut for faster testing.
When done just add/uncomment the call to it in your '_cb_save' callback and comment it before modifying the code again until it's finished.
In addition you could use:
Code: [Select]
if ( _get_extension( p_buf_name ) == 'e' ) return;to bail out as early as possible if you're compile/saving SE macro files which you don't want to backup and to skip your macro code when working with macro files.
This should help to avoid SE re-installs just to recover from a broken 'file save' macro code path.

HS2