Utilitaire runprogram

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Avatar de l’utilisateur
cage
Messages : 506
Inscription : ven. 16/oct./2015 18:22
Localisation : France
Contact :

Utilitaire runprogram

Message par cage »

Bonjour a tous,
Voici un petit utilitaire que je me suis fait pour mes besoins personnels.
Donner un nom parlant au fichier compilé.
A l'exécution de l'exécutable, un fichier exécutable.ini est créé.
Documenter au minimum le champ Program de ce fichier.
Je vous laisse juge de son utilité.
Merci de vos retours.
cage

Exemple de fichier .ini

Code : Tout sélectionner

[RUNPROGRAM]
;
;start ["<Title>"] [/d <Path>] [/i] [{/min | /max}] [/wait]
;      [{/separate | /Shared}]
;      [{/low | /normal | /high | /realtime | /abovenormal | belownormal}]
;      [/affinity <HexAffinity>]
;      [/b {<Command> | <Program>} [<Parameters>]]
;
;Program    = Full path of the executable
Program     = "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe"
;
;Parameters = Optional program parameter(s)
Parameters  = --fullscreen "http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_surround-fix.avi"
;
;Options    = Optional, [/d <Path>] [/i] [{/min | /max}] [{/separate | /Shared}] [/wait]
Options     = 
;
;Priority   = Optional, [{/low | /normal | /high | /realtime | /abovenormal | /belownormal}]
Priority    = /low
;
;Affinity   = Optional, [/affinity <HexAffinity>]
Affinity    = /affinity 2
Voici le programme

Code : Tout sélectionner

;
;***********************************************
;Titre      : runprogram  (x86/x64)
;Auteur     : (C) 2017 CAGE
;Date       : 2017/08/04
;Version PB : PureBasic 5.60 (Windows - x86)
;Version PB : PureBasic 5.60 (Windows - x64)
;Compiler Options
;Compiler Options : Enable moderm theme support (for Windows X and above)
;Compile/Run      : Create temporary executable in the source directory
;
;Libairies:
;***********************************************

; start ["<Title>"]
;       [/d <Path>]
;       [/i]
;       [{/min | /max}];
;       [{/separate | /Shared}]
;       [{/low | /normal | /high | /realtime | /abovenormal | belownormal}]
;       [/affinity <HexAffinity>]
;       [/wait] [/b {<Command> | <Program>} [<Parameters>]]

EnableExplicit ; all the variables must be declared

OnErrorGoto(?ErrorHandler)

Define PROGRAM.s, PARAMETERS.s, FOLDER.s

Define START = #False
Define OPTIONS.s, PRIORITY.s, AFFINITY.s

Define OUTFILE

Define MYPATH.s = GetPathPart(ProgramFilename())
Define CONFIG.s = GetFilePart(ProgramFilename(),#PB_FileSystem_NoExtension) + ".ini"

CONFIG = MYPATH + CONFIG

If OpenPreferences(CONFIG)
  PreferenceGroup("RUNPROGRAM")
    PROGRAM    = Trim(ReadPreferenceString("Program"    , #Null$))
    PARAMETERS = Trim(ReadPreferenceString("Parameters" , #Null$))
    OPTIONS    = Trim(ReadPreferenceString("Options"    , #Null$))
    PRIORITY   = Trim(ReadPreferenceString("Priority"   , #Null$))
    AFFINITY   = Trim(ReadPreferenceString("Affinity"   , #Null$))
  ClosePreferences()
Else
  OUTFILE = OpenFile(#PB_Any, CONFIG)
  If OUTFILE
    WriteStringN(OUTFILE, "[RUNPROGRAM]")
    WriteStringN(OUTFILE, ";")
    WriteStringN(OUTFILE, ";start ["+Chr(34)+"<Title>"+Chr(34)+"] [/d <Path>] [/i] [{/min | /max}] [/wait]")
    WriteStringN(OUTFILE, ";      [{/separate | /Shared}]")
    WriteStringN(OUTFILE, ";      [{/low | /normal | /high | /realtime | /abovenormal | belownormal}]")
    WriteStringN(OUTFILE, ";      [/affinity <HexAffinity>]")
    WriteStringN(OUTFILE, ";      [/b {<Command> | <Program>} [<Parameters>]]")
    WriteStringN(OUTFILE, ";")
    WriteStringN(OUTFILE, ";Program    = Full path of the executable")
    WriteStringN(OUTFILE, "Program     = ")
    WriteStringN(OUTFILE, ";")
    WriteStringN(OUTFILE, ";Parameters = Optional program parameter(s)")
    WriteStringN(OUTFILE, "Parameters  = ")
    WriteStringN(OUTFILE, ";")
    WriteStringN(OUTFILE, ";Options    = Optional, [/d <Path>] [/i] [{/min | /max}] [{/separate | /Shared}] [/wait]")
    WriteStringN(OUTFILE, "Options     = ")
    WriteStringN(OUTFILE, ";")
    WriteStringN(OUTFILE, ";Priority   = Optional, [{/low | /normal | /high | /realtime | /abovenormal | /belownormal}]")
    WriteStringN(OUTFILE, "Priority    = ")
    WriteStringN(OUTFILE, ";")
    WriteStringN(OUTFILE, ";Affinity   = Optional, [/affinity <HexAffinity>]")
    WriteStringN(OUTFILE, "Affinity    = ")
  EndIf
  End
EndIf

If PROGRAM <> #Null$
  FOLDER  = GetPathPart(PROGRAM) : If FOLDER  = #Null$ : End : EndIf
  PROGRAM = GetFilePart(PROGRAM) : If PROGRAM = #Null$ : End : EndIf
Else
  End
EndIf

PRIORITY = ReplaceString(PRIORITY,Chr(34),#Null$)
AFFINITY = ReplaceString(AFFINITY,Chr(34),#Null$)

If OPTIONS <> #Null$
  START = #True
EndIf

Select LCase(PRIORITY)
  Case "/low", "/normal", "/high", "/realtime", "/abovenormal", "/belownormal"
    START = #True
  Default
    PRIORITY = #Null$
EndSelect

Select LCase(Left(AFFINITY,10))
  Case "/affinity "
    START = #True
  Default
    AFFINITY = #Null$
EndSelect

If START
  Define CMDLINE.s = OPTIONS+" "+PRIORITY+" "+AFFINITY+" "+PROGRAM+" "+PARAMETERS
  Debug CMDLINE
  RunProgram("cmd.exe", "/c start "+CMDLINE, FOLDER)
;;RunProgram("cmd.exe", "/c start "+OPTIONS+" "+PRIORITY+" "+AFFINITY+" "+PROGRAM+" "+PARAMETERS, FOLDER)
;;RunProgram("cmd.exe", "/c start "+OPTIONS+" "+PRIORITY+" "+AFFINITY+" "+PROGRAM+" "+PARAMETERS, FOLDER, #PB_Program_Hide)
Else
  RunProgram(PROGRAM, PARAMETERS, FOLDER)
EndIf

ErrorHandler:

End
■ Win10 64-bit (Intel Celeron CPU N2920 @ 1.86GHz, 4,0GB RAM, Intel HD Graphics) & PB 6.00 LTS
■ Vivre et laisser vivre.
■ PureBasic pour le fun
■ Gérard sur le forum Anglais
■ Mes sites: http://pbcage.free.fr - http://yh.toolbox.free.fr