SketchUcation Plugin Store

 

 

[Code] Detect Window's VirtualStore

[Code] Detect Window's VirtualStore

Postby thomthom » Wed Jun 13, 2012 3:30 pm

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.)

Code: Select all

module FileHelper

  def self
.is_virtual?( file )
    
# (!) Windows check.
    
filename File.basenamefile )
    
filepath File.dirnamefile )
    
# Verify file exists.
    
unless File.exist?( file )
      
raise IOError"The file '#{file}' does not exist."
    
end
    
# See if it can be found in virtual store.
    
virtualstore File.joinENV['LOCALAPPDATA'], 'VirtualStore' )
    
path filepath.split(':')[1]
    
virtualfile File.joinvirtualstorepathfilename )
    
File.exist?( virtualfile )
  
end

  def self
.is_plugins_folder_virtual?
    
plugins_path Sketchup.find_support_file'Plugins' )
    
self.is_virtual?( plugins_path )
  
end

end 
# module
 


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
User avatar
thomthom
Global Moderator
 
Posts: 17556
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: [Code] Detect Window's VirtualStore

Postby thomthom » Thu Jun 14, 2012 2:58 pm

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
User avatar
thomthom
Global Moderator
 
Posts: 17556
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: [Code] Detect Window's VirtualStore

Postby thomthom » Thu Jun 14, 2012 3:06 pm

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
User avatar
thomthom
Global Moderator
 
Posts: 17556
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: [Code] Detect Window's VirtualStore

Postby Dan Rathbun » Thu Jun 14, 2012 3:30 pm

thomthom wrote: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()
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: [Code] Detect Window's VirtualStore

Postby thomthom » Fri Jun 15, 2012 10:17 am

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

Win7 Admin
Code: Select all
#<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
Code: Select all
#<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
User avatar
thomthom
Global Moderator
 
Posts: 17556
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: [Code] Detect Window's VirtualStore

Postby thomthom » Fri Jun 15, 2012 11:49 am

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
User avatar
thomthom
Global Moderator
 
Posts: 17556
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: [Code] Detect Window's VirtualStore

Postby thomthom » Fri Jun 15, 2012 1:13 pm

thomthom wrote: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
User avatar
thomthom
Global Moderator
 
Posts: 17556
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

Re: [Code] Detect Window's VirtualStore

Postby Dan Rathbun » Fri Jun 15, 2012 8:05 pm

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 ??
User avatar
Dan Rathbun
Top SketchUcator
 
Posts: 4069
Joined: Tue Oct 06, 2009 3:06 am
Location: Florida, USA
Name: Dan Rathbun
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: education
Level of SketchUp: Advanced

Re: [Code] Detect Window's VirtualStore

Postby thomthom » Sat Jun 16, 2012 1:44 am

Dan Rathbun wrote: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 wrote: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
User avatar
thomthom
Global Moderator
 
Posts: 17556
Joined: Tue Nov 13, 2007 12:47 pm
Location: Trondheim, Norway
Name: thomthom
Operating system: Windows
SketchUp version: 8
License type: Pro
SketchUp use: architecture
Level of SketchUp: Advanced

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago

Keyframe Animation plugin - animate your SketchUp model by adding movement to any object.

Premium Members get 20% discount!

Ad Machine
Robot
 
Posts: 2012


Return to Developers' Forum

Who is online

Users browsing this forum: No registered users and 3 guests