[SOLVED] Mblock Setup.py

Questions about WAPT Packaging / Requests and help regarding Wapt packages.
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
User avatar
sfonteneau
WAPT Expert
Messages: 2318
Registered: July 10, 2014 - 11:52 PM
Contact :

December 29, 2017 - 12:31

Code: Select all

sfonteneau, pour éviter de perdre du temps et faire ça bien, peux-tu nous aider dans la rédaction du session_setup STP?
If you have a method that works every time, yes, I can.. :) But for now it's a bit unclear

The simplest solution in this case would be to contact a developer:

http://www.mblock.cc/contactus/

Ultimately, in my opinion, it will end up with the software detecting the system language upon first startup :D and set this language as the default at startup.

I have already contacted some application developers about this kind of thing and they can be quite receptive.

Up to you !
forget-me-nots
Messages: 5
Registered: December 26, 2017 - 4:34 PM

December 29, 2017 - 2:34 PM

This involves copying a /com.makeblock.Scratch3.4.11/Local Store file "formatted" in French into the AppData/Roming/ directory of each user
, and also ensuring that it works for the interactive or current user as well, in French...
User avatar
sfonteneau
WAPT Expert
Messages: 2318
Registered: July 10, 2014 - 11:52 PM
Contact :

December 29, 2017 - 5:18 PM

myosotis wrote: Dec 29, 2017 - 2:34 PM It involves copying a /com.makeblock.Scratch3.4.11/Local Store file "formatted" in French into the AppData/Roming/ directory of each user
and also ensuring that it works for the interactive or current user as well, in French...
For the part:
myosotis wrote: Dec 29, 2017 - 2:34 PM Also make sure that it works for interactive or current user as well, in French
I don't quite understand.

On the other hand, you can indeed create a working com.makeblock.Scratch3.4.11, copy it during the def install() into a folder on the machine and then copy it in reverse during the session_setup into the user's %appdata%.

The next question is what to do if the com.makeblock.Scratch3.4.11 folder already exists during session setup. Do we overwrite it, even if the user has already configured their settings? Or do we just overwrite it?

https://dev.tranquil.it/sphinxdocs/sour....copytree2
forget-me-nots
Messages: 5
Registered: December 26, 2017 - 4:34 PM

December 29, 2017 - 6:12 PM

I'll try to copy my code for you as soon as possible. Thank you so much for your help.

I did try using copytree2. It works on a path that isn't relative to the user (I'm doing this as a prerequisite since a session setup() prevents accessing a file or folder provided in the package; so I copy "my source code" from the package into a folder in ProgramData and then try to access it... without success so far).

Overwriting the personal folder in AppData is not an option. In our production environment, the user isn't encouraged to save anything locally.

Rereading your message, I get the impression that the focus shouldn't be on the user, but on AppData. Perhaps that's where I'm going wrong...?!!
forget-me-nots
Messages: 5
Registered: December 26, 2017 - 4:34 PM

December 31, 2017 - 4:06 PM

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *

# Importation des fichiers de personalisation 
copytree2(r'Perso',r'C:\ProgramData\mBlock') #Import du dossier fourni dans le paquet
filecopyto(r'Copy.cmd',r'C:\ProgramData\mBlock') #Import d'un fourni egalement avec le paquet

key = "{1E9DFEBB-4088-4693-A521-C755318BD492}_is1"
uninstallkey = ['{1E9DFEBB-4088-4693-A521-C755318BD492}_is1']

#Creation d'un targetdir en faisant usage de user_appdata qui selon la doc renvoit à /userX/appdata/roaming/
targetdir = makepath(user_appdata(),'com.makeblock.Scratch3.4.11')
print targetdir # ça c'est pour moi ;) - ca m'affiche bien le dossier souhaité... malheureusement l'exploit est nulle

#uninstallstring = [r' ""C:\Program Files (x86)\mBlock\unins000.exe" /SILENT {1E9DFEBB-4088-4693-A521-C755318BD492}_is1']

def install():

        versionpaquet = control['version'].split('-',1)[0]

        print('Importation de drivers')

        with disable_file_system_redirection():
             run('regedit.exe /s usbserial_arduino.reg')
             run(r'"%s" /VERYSILENT' % makepath('drivers','Driver_for_Windows.exe'))

        print('Installation de util-mblock')
        install_exe_if_needed("mBlock_win_V"+versionpaquet+".exe",
                            silentflags="/VERYSILENT",
                            key=key,
                            min_version=versionpaquet,
                            killbefore="mBlock.exe")
				
		#suppression de la clé de désinstallation pour pouvoir faire une désinstallation silencieuse. Voir def uninstall():
        #uninstallkey.remove(key) # FONCTION pas dispo dans Setuphelpers v1.3.5
		
        #suppression du raccourci bureau
        #remove_desktop_shortcut('mBlock')
		
	print "Post installation"
	lang = makepath(targetdir)
		
	if not isdir(lang):
		os.makedirs(lang)
		copytree2('Perso','targetdir') #Tentative d'import de com.makeblock.Scratch3.4.11 via fonction copytree2 + user_appdata() : Resultat non probant
		session_setup()
		   
		
def uninstall():
    print('Désinstallation de util-mblock')
    run(r'"%s\unins000.exe" /VERYSILENT' % install_location(key))		
		
		
def session_setup():

	targetdir = makepath(user_appdata(),'com.makeblock.Scratch3.4.11')

	if not isdir(targetdir):
			print('creation du dossier com.makeblock.Scratch3.4.11')
			mkdirs(makepath(user_appdata(),'com.makeblock.Scratch3.4.11'))
			#copytree2('C:\ProgramData\mBlock','targetdir')
			run(r'C:\ProgramData\mBlock\Copy.cmd')
		#ci-dessus vs avez mes 2 tentatives : (1) via copytree2;, l'autre via le run d'un cmd que j'ai essayé de runner pour injecter les fichiers adéquats. Ni l'une, ni l'autre des méthodes ne fonctionnent.
	
	else:
		#remove_file(makepath(user_appdata(),'com.makeblock.Scratch3.4.11'))
		#copytree2('C:\ProgramData\mBlock','targetdir')
		run(r'C:\ProgramData\mBlock\Copy.cmd')
		#copytree2(r'C:\ProgramData\mBlock',r'%USERPROFILE%\AppData\Roaming')
		
#Personalisation de mblock pour l'interactive User - Alternative try		
run(r'"Copy.cmd"')
+ Copy of my cmd

Code: Select all

if not exist C:\Users\%username%\AppData\Roaming\com.makeblock.Scratch3.4.11 mkdir C:\Users\%username%\AppData\Roaming\com.makeblock.Scratch3.4.11 
xcopy C:\ProgramData\mBlock\com.makeblock.Scratch3.4.11 C:\Users\%username%\AppData\Roaming\com.makeblock.Scratch3.4.11 /E /C /Y
...it doesn't work...no more than with %appdata%

:'( .... can't we interact with the current user's appdata while a package is being deployed?
User avatar
sfonteneau
WAPT Expert
Messages: 2318
Registered: July 10, 2014 - 11:52 PM
Contact :

December 31, 2017 - 6:15 PM

myosotis wrote: Dec 31, 2017 - 4:06 PM Can't we interact with the current user's appdata while a package is being deployed?
It's possible, but it's more complicated; session setup makes things simpler:

Code: Select all

# -*- coding: utf-8 -*-
from setuphelpers import *

uninstallkey = []

key = "{1E9DFEBB-4088-4693-A521-C755318BD492}_is1"

profil_name = 'com.makeblock.Scratch3.4.11'
profil_mblock_appdata = makepath('c:','ProgramData','mblock',profil_name)
profil_mblock = makepath(application_data(),profil_name)

def install():

        versionpaquet = control['version'].split('-',1)[0]

        print('Importation des drivers')

        with disable_file_system_redirection():
             run('regedit.exe /s usbserial_arduino.reg')
             run(r'"%s" /VERYSILENT' % makepath('drivers','Driver_for_Windows.exe'))

        print('installing aiz-mblock')
        install_exe_if_needed("mBlock_win_V"+versionpaquet+".exe",
                            silentflags="/VERYSILENT",
                            key=key,
                            min_version=versionpaquet,
                            killbefore="mBlock.exe")

        #suppression de la clé de désinstallation pour pouvoir faire une désinstallation silencieuse. Voir def uninstall():
        uninstallkey.remove(key)

        #suppression du raccourci bureau
        remove_desktop_shortcut('mBlock')


        if isdir(profil_mblock_appdata):
            remove_tree(profil_mblock_appdata)
        copytree2(profil_name,profil_mblock_appdata)


def session_setup():
    if isdir(profil_mblock):
        remove_tree(profil_mblock)
    copytree2(profil_mblock_appdata,profil_mblock)

def uninstall():
    print('uninstalling aiz-mblock')
    run(r'"%s\unins000.exe" /VERYSILENT' % install_location(key))

The profile "com.makeblock.Scratch3.4.11" will be overwritten at the next login.
This way, even if the user profile doesn't exist yet, it will work perfectly!

Don't forget to increment the package version number after each modification to the session setup!
forget-me-nots
Messages: 5
Registered: December 26, 2017 - 4:34 PM

January 9, 2018 - 4:11 PM

Hello sfonteneau,

after multiple tests and attempts, we still haven't managed to access the appdata of the user who downloads the package; in short, the initial objective hasn't been achieved.

Nevertheless, the proposed mechanism, implemented via session_setup(), works, and therefore, upon reopening the session, the software is in French.

Finally, I suggest a small modification to your excellent script: Modify the profil_mblock_appdata variable. Since it's then used in raw mode, it was necessary to define it as follows: profil_mblock_appdata = makepath('c:\\', 'ProgramData', 'mblock', profil_name).


Best wishes! Thank you for your help. In my opinion, the issue is resolved. Some limitations have been reached.
User avatar
sfonteneau
WAPT Expert
Messages: 2318
Registered: July 10, 2014 - 11:52 PM
Contact :

January 9, 2018 - 7:20 PM

myosotis wrote: January 9, 2018 - 4:11 PM
Finally, I suggest a small modification to your excellent script: Modification of the profil_mblock_appdata variable. Since it is then used in raw format, it was necessary to define it like this: profil_mblock_appdata = makepath('c:\\','ProgramData','mblock',profil_name)
No problems here, what version of Wapt do you have?
myosotis wrote: Jan 9, 2018 - 4:11 PM Some limits have been reached.
If you really want to copy this folder during installation, you need to do something like this:

Code: Select all

for locprof in local_users_profiles():
        if isdir(makepath(locprof,'AppData','Roaming',profil_name)):
        	remove_tree(makepath(locprof,'AppData','Roaming',profil_name))
	copytree2(profil_name,makepath(locprof,'AppData','Roaming',profil_name))
So, does that mean stopping the mblock that's currently running?
Locked