sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    [Code] Detect Window's VirtualStore

    Scheduled Pinned Locked Moved Developers' Forum
    9 Posts 2 Posters 2.0k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • thomthomT Offline
      thomthom
      last edited by

      I started to look into what happens when you try to write to the plugins folder with SketchUp Ruby when the user doesn't have admin rights. Ruby will say that the files a writable so I was having a hard time finding out how I could detect if the folder was in the virtual store or not. Initial test indicate that this snippet is able to detect if a file or folder exist in the VirtualStore. (Hoping "VirtualStore" is not localized - I think MS stopped doing that from Vista and onwards and XP didn't have the virtualstore.)

      <span class="syntaxdefault"><br />module&nbsp;FileHelper<br /><br />&nbsp;&nbsp;def&nbsp;self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">is_virtual</span><span class="syntaxkeyword">?(&nbsp;</span><span class="syntaxdefault">file&nbsp;</span><span class="syntaxkeyword">)<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxcomment">#&nbsp;(!)&nbsp;Windows&nbsp;check.<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">filename&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">basename</span><span class="syntaxkeyword">(&nbsp;</span><span class="syntaxdefault">file&nbsp;</span><span class="syntaxkeyword">)<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">filepath&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">dirname</span><span class="syntaxkeyword">(&nbsp;</span><span class="syntaxdefault">file&nbsp;</span><span class="syntaxkeyword">)<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxcomment">#&nbsp;Verify&nbsp;file&nbsp;exists.<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">unless&nbsp;File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">exist</span><span class="syntaxkeyword">?(&nbsp;</span><span class="syntaxdefault">file&nbsp;</span><span class="syntaxkeyword">)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">raise&nbsp;IOError</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxstring">"The&nbsp;file&nbsp;'#{file}'&nbsp;does&nbsp;not&nbsp;exist."<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">end<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxcomment">#&nbsp;See&nbsp;if&nbsp;it&nbsp;can&nbsp;be&nbsp;found&nbsp;in&nbsp;virtual&nbsp;store.<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">virtualstore&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">join</span><span class="syntaxkeyword">(&nbsp;</span><span class="syntaxdefault">ENV</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'LOCALAPPDATA'</span><span class="syntaxkeyword">],&nbsp;</span><span class="syntaxstring">'VirtualStore'&nbsp;</span><span class="syntaxkeyword">)<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">path&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">filepath</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">split</span><span class="syntaxkeyword">(</span><span class="syntaxstring">';'</span><span class="syntaxkeyword">)[</span><span class="syntaxdefault">1</span><span class="syntaxkeyword">]<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">virtualfile&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">join</span><span class="syntaxkeyword">(&nbsp;</span><span class="syntaxdefault">virtualstore</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">path</span><span class="syntaxkeyword">,&nbsp;</span><span class="syntaxdefault">filename&nbsp;</span><span class="syntaxkeyword">)<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">exist</span><span class="syntaxkeyword">?(&nbsp;</span><span class="syntaxdefault">virtualfile&nbsp;</span><span class="syntaxkeyword">)<br />&nbsp;&nbsp;</span><span class="syntaxdefault">end<br /><br />&nbsp;&nbsp;def&nbsp;self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">is_plugins_folder_virtual</span><span class="syntaxkeyword">?<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">plugins_path&nbsp;</span><span class="syntaxkeyword">=&nbsp;</span><span class="syntaxdefault">Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">find_support_file</span><span class="syntaxkeyword">(&nbsp;</span><span class="syntaxstring">'Plugins'&nbsp;</span><span class="syntaxkeyword">)<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="syntaxdefault">self</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">is_virtual</span><span class="syntaxkeyword">?(&nbsp;</span><span class="syntaxdefault">plugins_path&nbsp;</span><span class="syntaxkeyword">)<br />&nbsp;&nbsp;</span><span class="syntaxdefault">end<br /><br />end&nbsp;</span><span class="syntaxcomment">#&nbsp;module<br />&nbsp;</span><span class="syntaxdefault"></span>
      

      From what I remember of comments on this forum a non-admin user must give himself access to the plugin folder in order to allow Ruby to write to it. I guess there is no way to make Ruby set these permission - taking care of the problem for the user?

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        Can you read folder permissions via SU Ruby? And can these permissions be used to determine if a file is truly writeable or if it'll end up in the virtual store.

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          hm... if the file already exists it appear that Ruby avoids VirtualStore - so is there some system command one can issue to create a file?

          Thomas Thomassen — SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            @thomthom said:

            Can you read folder permissions via SU Ruby?

            You should be able to. A directory has always been treated as a "kind" of file.

            The mixin module FileTest can be mixed into your class, and is already mixed into class File.

            Also there is the File::Stat class.

            see the Ruby reference CHM.

            ADD: and do not forget about Kernel::test()

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              Permission appear to be identical even though creating a file on the Win8 machine will put it in VirtualStore...

              Win7 Admin

              
              #<File;;Stat
                dev=0x2,
                ino=0,
                mode=040755,
                nlink=1,
                uid=0,
                gid=0,
                rdev=0x2,
                size=0,
                blksize=nil,
                blocks=nil,
                atime=Mon Jun 11 12;44;30 +0200 2012,
                mtime=Mon Jun 11 12;44;30 +0200 2012,
                ctime=Wed Aug 03 13;33;27 +0200 2011
              >
              
              

              Win8

              
              #<File;;Stat
                dev=0x2, 
                no=0,
                mode=040755,
                nlink=1,
                uid=0,
                gid=0,
                rdev=0x2,
                size=0,
                blksize=nil,
                blocks=nil,
                atime=Thu Jun 14 16;02;35 +0200 2012,
                mtime=Thu Jun 14 16;02;35 +0200 2012,
                ctime=Fri Jun 01 10;44;03 +0200 2012
              >
              
              

              Thomas Thomassen — SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                I used "Run as Administrator" and SketchUp Ruby still wrote to VirtualStore... ❓ ❓

                Thomas Thomassen — SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • thomthomT Offline
                  thomthom
                  last edited by

                  @thomthom said:

                  I used "Run as Administrator" and SketchUp Ruby still wrote to VirtualStore... ❓ ❓

                  Seems that I didn't actually launch it as administrator - but when I actually did I found I could not drag and drop files from Explorer to a WebDialog.

                  (I'm allowing drag and drop of files to a webdialog for easy installation of Ruby plugins etc.)

                  Thomas Thomassen — SketchUp Monkey & Coding addict
                  List of my plugins and link to the CookieWare fund

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    So did "Run as Administrator" allow you to write files where you wanted, rather than the VirtualStore ??

                    And.. are you saying that file writing is even more of a P.I.T.B on Win8, than it was in previous versions ??

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • thomthomT Offline
                      thomthom
                      last edited by

                      @dan rathbun said:

                      So did "Run as Administrator" allow you to write files where you wanted, rather than the VirtualStore ??

                      Didn't try that - because my fileread was triggered by the drag and drop which was prevented. But it'd be worth testing.

                      @dan rathbun said:

                      And.. are you saying that file writing is even more of a P.I.T.B on Win8, than it was in previous versions ??

                      I don't know - I've always used an administrator account on Vista and Win7 with UAC disabled. I cannot compare because Win8 is the first Windows OS I've tried with default user access. I suspect it's the same as Win7 and Vista, but I need to verify this.

                      Thomas Thomassen — SketchUp Monkey & Coding addict
                      List of my plugins and link to the CookieWare fund

                      1 Reply Last reply Reply Quote 0
                      • 1 / 1
                      • First post
                        Last post
                      Buy SketchPlus
                      Buy SUbD
                      Buy WrapR
                      Buy eBook
                      Buy Modelur
                      Buy Vertex Tools
                      Buy SketchCuisine
                      Buy FormFonts

                      Advertisement