1. IMPORTANT:
    We launched a new online community and this space is now closed. This community will be available as a read-only resources until further notice.
    JOIN US HERE

Script to locate file in folder

Discussion in 'Scripting Workshop' started by Itariel Bandeira, Apr 11, 2018.

  1. Itariel Bandeira

    Itariel Bandeira NI Product Owner

    Messages:
    34
    Good Morning.
    I need to create a script that looks for a certain file in some folder just like it does for example the load_ir_sample.
    My idea would be to find some files necessary for the proper functioning of the library in some folder of my choice, making anyone who obtains the library without my authorization, do not locate this file.
    Thanks
     
  2. Itariel Bandeira

    Itariel Bandeira NI Product Owner

    Messages:
    34
    Another example that would serve me is a script that says where the Resources folder is instead of having to select it in the Instrument Option.
     
  3. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    It is not a good idea to distribute your library with the Resources folder. Repack the NKR (simply by creating it again and overwriting the old one), this is all you need to distribute with your library, just the NKR. Not the Resources folder.
     
  4. Itariel Bandeira

    Itariel Bandeira NI Product Owner

    Messages:
    34
    Thank you Evil. My idea is to try and block the distribution of my library by having the person you buy depend on me to make it work. I thought then to put some essential file for the operation of it in some folder of the system and by script to do the nki to look for this file. So even the person compacting and sending the library who receives it would depend on this file to function. I do not know if you understand me
     
  5. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Yeah that won't really work since such a method can easily be reversed...
     
  6. Lindon

    Lindon NI Product Owner

    Messages:
    322
    ..sigh, we constantly have this response...

    and its partly correct in that it can easily be reversed, and its partly wrong in that (despite this) it really does work and by that I mean your product gets hacked MUCH later if at all...(in my experience)

    Put your "file" in the Data folder and search for it there. - that's what i used to do when I distributed a separate "key file"
     
  7. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    In your but not everyone's experience, for sure. There are no rules, really. Some libraries without any such protection schemes get leaked much later than some others, for whatever reason. i.e. Red Room Audio's Palette which I worked on, has been out for months now, and it didn't leak (knock on wood). Explain that. :p
     
    Last edited: Apr 12, 2018
  8. Lindon

    Lindon NI Product Owner

    Messages:
    322
    which is precisely what I said.
     
  9. Itariel Bandeira

    Itariel Bandeira NI Product Owner

    Messages:
    34
    Yes, I know it can be reversed, but here in Brazil the staff is layman in Kontakt and programming and this would not solve but would make it difficult if there was. Is there any script that I could pull a file from outside the Library folder?
     
  10. Lindon

    Lindon NI Product Owner

    Messages:
    322
    use the load_array command
     
  11. Itariel Bandeira

    Itariel Bandeira NI Product Owner

    Messages:
    34
    The idea is to put this piece of code at the script beginning



    declare $foundfile

    $foundfile := load_ir_sample("c:\windows\temp\ACME.wav",0,1)

    if ($foundfile = 0) { A possible error returned if the file is not found}
    exit { to stop the variants declaration and all the script}
    end if
     
  12. Lindon

    Lindon NI Product Owner

    Messages:
    322
    ..or just open an array, and read the contents - lets say 4 numbers - and compare them in some way to make sure its a valid authorisation code.
     
  13. Itariel Bandeira

    Itariel Bandeira NI Product Owner

    Messages:
    34
    Would it be too much to ask an example? Some areas are still gaining knowledge. Thank you
     
  14. Lindon

    Lindon NI Product Owner

    Messages:
    322
    read the manual on how to use the load_array command. You are looking for mode = 1 this might help:

    Code:
    on init
        declare %auth_array[4]
        declare auth_switch := 0
        declare auth_id
    
        auth_id := load_array(%auth_array, 1)
        while auth_id # -1
            wait(1000)
        end while
    
        if %auth_array[0] + %auth_array[1] = %auth_array[2]
            if abs(%auth_array[0] - %auth_array[1]) = %auth_array[3]
                auth_switch := 1
            end if
        end if
    
    end on
    
    on async_complete
        if $NI_ASYNC_ID = $auth_id
            $auth_id := -1
        end if
    end if
    
    on note
        if auth_switch = 0
            exit
        end if
    end on
    you need a much better set of element tests as this will work for 0,0,0,0
     
    Last edited: Apr 12, 2018
  15. Itariel Bandeira

    Itariel Bandeira NI Product Owner

    Messages:
    34
    Thank you, I'll test and put the result.
     
  16. Lindon

    Lindon NI Product Owner

    Messages:
    322
    ..you will of course have to create a file to load with some values in it.
     
  17. Itariel Bandeira

    Itariel Bandeira NI Product Owner

    Messages:
    34
    I'll think about it here because you entered an area that I do not know much about, but thank you very much for giving the way.
     
  18. Itariel Bandeira

    Itariel Bandeira NI Product Owner

    Messages:
    34
    I added "$" to auth_id and auth_switch, however in line 7 of the error "(" expected

    "while $ auth_id # -1"
     
  19. Itariel Bandeira

    Itariel Bandeira NI Product Owner

    Messages:
    34
    Apparently the wait command was giving callback error not allowed (on init).
    However, I was able to remove the wait (1000), I do not know if this would affect the script. I'm using your example to learn. After doing the script what should I put in this file that you quoted?
     
  20. Lindon

    Lindon NI Product Owner

    Messages:
    322
    you are going to have to wait to make sure the load happens - its asynchronous... maybe move the code to the OPC