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

Writing a config or temp file in Plugins folder

Scheduled Pinned Locked Moved Developers' Forum
20 Posts 7 Posters 937 Views 7 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.
  • T Offline
    tomasz
    last edited by 20 Sept 2010, 09:39

    I have a big headache trying to save a config file in 'Plugins/MyPlugin' folder.
    I work always as an administrator on my computer and have full right to the folder, but many plugin users don't.
    Moreover.. under Win Vista \ 7 there is the worst thing on the Earth .. the UAC. I really hate it.

    Is there a way to successfully save a file into Plugins whatever permissions are there or at least help users grant such a permission to themselves - like starting folder properties window?

    Even when I would give an user an option to select a different, writable folder, I have to save this location in a config file somehow!

    Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

    1 Reply Last reply Reply Quote 0
    • P Offline
      Pixero
      last edited by 20 Sept 2010, 10:40

      @unknownuser said:

      Moreover.. under Win Vista \ 7 there is the worst thing on the Earth .. the UAC. I really hate it.

      Me too. I work as administrator too, and even if I have UAC off, quite often when trying to save something from the internet (IE) says I dont have write permission. Then if I try again I can and it overwrites a dummy 0kb file with a real sized file. Any ideas?

      Not a solution to your question, but for people who cant stand UAC is to use the free TweakUAC to turn it off. πŸ‘
      I had a drive that "dissapeared" and Vista said it wasn't formatted...tried hard until I turned UAC off. Then it all came back.
      If you're interested you can read about my struggle here: http://forums.sketchucation.com/viewtopic.php?f=72&t=17248

      1 Reply Last reply Reply Quote 0
      • T Offline
        thomthom
        last edited by 20 Sept 2010, 10:57

        hm... My Selection Toys write to a config file in its subfolder - I don't recall any trouble with that when I ran it on my Notebook with UAC enabled...

        @unknownuser said:

        Even when I would give an user an option to select a different, writable folder, I have to save this location in a config file somehow!

        Sketchup.write_default ?

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

        1 Reply Last reply Reply Quote 0
        • T Offline
          thomthom
          last edited by 20 Sept 2010, 11:04

          @thomthom said:

          hm... My Selection Toys write to a config file in its subfolder - I don't recall any trouble with that when I ran it on my Notebook with UAC enabled...

          Mind you - the account was still an administrator account - I have never tried a User account...

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

          1 Reply Last reply Reply Quote 0
          • N Offline
            notareal
            last edited by 20 Sept 2010, 11:33

            @thomthom said:

            @thomthom said:

            hm... My Selection Toys write to a config file in its subfolder - I don't recall any trouble with that when I ran it on my Notebook with UAC enabled...

            Mind you - the account was still an administrator account - I have never tried a User account...

            I think there many that struggles with this issue (administrated environments). For some running as administrator is simply impossible and/or against corporate security policy.

            Welcome to try [Thea Render](http://www.thearender.com/), Thea support | [kerkythea.net](http://www.kerkythea.net/) -team member

            1 Reply Last reply Reply Quote 0
            • T Offline
              thomthom
              last edited by 20 Sept 2010, 11:56

              So the issue here is users without admin privileges won't be able to run plugins that need to write to the plugins folder?

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

              1 Reply Last reply Reply Quote 0
              • N Offline
                notareal
                last edited by 20 Sept 2010, 13:48

                @thomthom said:

                So the issue here is users without admin privileges won't be able to run plugins that need to write to the plugins folder?

                Yes. It's simply a no good route in Vista/win7 (possibly in XP too), if a strict security policy is in use - user cannot write anything in application folders. It can even be restricted from admins (by group policy).

                Welcome to try [Thea Render](http://www.thearender.com/), Thea support | [kerkythea.net](http://www.kerkythea.net/) -team member

                1 Reply Last reply Reply Quote 0
                • C Offline
                  Chris Fullmer
                  last edited by 20 Sept 2010, 14:55

                  @notareal said:

                  if a strict security policy is in use - user cannot write anything in application folders.

                  So what folder does Windows expect people should be able to write to? - somewhere in the users folders probably, right? Could you set it up to write to a special folder in the users MyDocuments or something? And then like Thom suggests, use write_default to save the location of the file.

                  Lately you've been tan, suspicious for the winter.
                  All my Plugins I've written

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    thomthom
                    last edited by 20 Sept 2010, 15:14

                    You'd have to make a Win32 API call to get the correct path.

                    What about OSX, any restriction there?

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

                    1 Reply Last reply Reply Quote 0
                    • jeff hammondJ Offline
                      jeff hammond
                      last edited by 20 Sept 2010, 15:47

                      @thomthom said:

                      What about OSX, any restriction there?

                      yeah, there are restrictions there.
                      for instance, using fredoscale as an example (which has the default parameter file), i can only change those defaults from my admin account.. if i try doing it from a user acct then the changes don't stick.
                      i can however, as an admin, give the user acct. read/write permissions to the entire plugin folder or specific files in which case a user can make changes to fredoscale's parameters which will affect both the user's sketchup and the admin's sketchup.

                      [and if i remember correctly, there were some problems with the fredoscale.def file being created in the first place when someone was trying to install from a non-admin acct.. ie- it didn't work]

                      dotdotdot

                      1 Reply Last reply Reply Quote 0
                      • TIGT Offline
                        TIG Moderator
                        last edited by 20 Sept 2010, 15:55

                        Why does it have to be a file made in the ../Plugins/ folder ?
                        There are many places that a user will have access rights - e.g. C:\Temp ?
                        You can also get the User's very own 'TEMP' folder using ENV["TEMP"] for PC or ENV["TMPDIR"] for MAC - e.g. C:\Users\TIG\AppData\Local\Temp

                        πŸ€“

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • T Offline
                          thomthom
                          last edited by 20 Sept 2010, 16:03

                          The temp folder doesn't work well when you want to store persistent config files.

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

                          1 Reply Last reply Reply Quote 0
                          • T Offline
                            thomthom
                            last edited by 20 Sept 2010, 16:09

                            What we need in the API is a method that will return the path to where one can store application data on each OS.

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

                            1 Reply Last reply Reply Quote 0
                            • T Offline
                              thomthom
                              last edited by 20 Sept 2010, 16:12

                              On Win7 I see this key:
                              LOCALAPPDATA - C:\Users\Thomas\AppData\Local

                              Is there something on OSX?

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

                              1 Reply Last reply Reply Quote 0
                              • TIGT Offline
                                TIG Moderator
                                last edited by 20 Sept 2010, 16:18

                                My ENV example combined with a simple OS test lets you find the User's own TEMP file...
                                The PC's ENV["LOCALAPPDATA"] would allow you to then make a specific sub-folder to contain the config file - on a MAC what is it ?

                                BUT you can save config info in other ways...

                                To save them
                                If it's entity specific use entity.set_attributes(dict,key,value)
                                If it's model specific use model.set_attributes(dict,key,value)
                                If it's Sketchup specific use Sketchup.write_default(section,variable,value)
                                [if it's a file-path with '' you'll need to use tr("\\","/") before writing it]

                                To retrieve them use
                                entity.get_attributes(dict,key,default)
                                model.get_attributes(dict,key,default)
                                Sketchup.read_default(section,variable,value)
                                [if it's a file-path you'll need to use tr("/","\\") after reading it and before using it]
                                πŸ€“

                                TIG

                                1 Reply Last reply Reply Quote 0
                                • T Offline
                                  thomthom
                                  last edited by 20 Sept 2010, 16:32

                                  @tig said:

                                  [if it's a file-path with '' you'll need to use tr("\","/") before writing it]

                                  Or use File.expand_path

                                  @unknownuser said:

                                  I have to try if once again. If my memory doesn't deceive me I haven't had good results with it in the past.

                                  I use it quite frequently. But beware that it doesn't handle Length objects well - so convert them into floats first. (I made a wrapper to handle conversion of Length and Symbol for write/read_default)

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

                                  1 Reply Last reply Reply Quote 0
                                  • T Offline
                                    tomasz
                                    last edited by 20 Sept 2010, 16:47

                                    @tig said:

                                    Why does it have to be a file made in the ../Plugins/ folder ?

                                    It doesn't have to be. If I would have just a chance to write a path to the config file then it would be ok...
                                    I have forgotten about Sketchup.write_default. Thanks Thomas!
                                    I have to try it once again. If my memory doesn't deceive me I haven't had good results with it in the past.

                                    Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

                                    1 Reply Last reply Reply Quote 0
                                    • TIGT Offline
                                      TIG Moderator
                                      last edited by 20 Sept 2010, 19:47

                                      Note that read/write_defaults is best with Strings - convert then from/to Float [or whatever] afterwards... πŸ˜‰

                                      TIG

                                      1 Reply Last reply Reply Quote 0
                                      • T Offline
                                        thomthom
                                        last edited by 20 Sept 2010, 20:08

                                        works fine with floats, integers, even arrays in my experience...

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

                                        1 Reply Last reply Reply Quote 0
                                        • N Offline
                                          notareal
                                          last edited by 20 Sept 2010, 20:10

                                          For windows %appdata% ?

                                          Welcome to try [Thea Render](http://www.thearender.com/), Thea support | [kerkythea.net](http://www.kerkythea.net/) -team member

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

                                          Advertisement