aIRC — File Browser
aIRCv0.8.69 / aIRCv0.8.69 / script / profiles.mrc
profiles.mrc — 7.95 KB — Download this file
;/**********************************************************************
; *
; * aIRC
; * Profiles
; *
; **********************************************************************/
;
alias _profiles { _dialog -m _profiles _profiles }
dialog _profiles {
size -1 -1 160 120
option dbu
title "User Profiles"
box "Profiles",1,5 5 150 110
list 1010,10 15 100 100
list 1011,10 15 100 70,hide
button "Generate &Empty profile (like a 'new' aIRC)",2101,10 93 140 15,hide
box "",2102,5 80 150 35,hide
button "&Load",2001,115 15 33 15,ok
button "&Spawn",2002,115 35 33 15,hide
button "&New",2003,115 55 33 15,hide
button "&Import",2004,115 75 33 15,hide
edit "",2502,165 15 140 95,hide autohs result
button "&Cancel",2992,5 120 33 15,cancel hide
}
ON *:DIALOG:_profiles:init:0:{
_mdx.init $_icofile(profiles.ico)
_dummy $_lang.loaddialog($dname,$dname,00086969,main.lang,$scriptdir)
_profiles.d.init
}
ON *:DIALOG:_profiles:sclick:2001:{
_profiles.load $did($dname,1010,$did($dname,1010).sel)
_unloadprofilesmrc
}
ON *:DIALOG:_profiles:sclick:2002:{ _profiles.spawn $did($dname,1010,$did($dname,1010).sel) }
ON *:DIALOG:_profiles:sclick:2003:{ _profiles.d.new }
ON *:DIALOG:_profiles:sclick:2004:{ _profiles.import }
ON *:DIALOG:_profiles:dclick:1010:{ _profiles.load $did($dname,1010,$did($dname,1010).sel) }
ON *:DIALOG:_profiles:sclick:2992:{ _unloadprofilesmrc }
alias _profiles.d.init {
var %d = _profiles,%dir = $mircdir $+ usr\,%current = $_getusrdir
if ($_not($dialog(%d))) { return }
if (%current == $null) || ($_not($_profiles.exists(%current))) { %current = default }
did -r %d 1010
did -a %d 1010 Default Profile $iif(%current == default,[loaded])
did -v %d 2002,2003,2004
_dummy $finddir(%dir,*,0,1,_profiles.d.initdir %d 1010 %current $1-)
}
alias _profiles.d.initdir {
var %d = $1,%p = $gettok($4-,-1,$asc(\)),%current = $3
if (%p != default) && ($_profiles.exists(%p)) { did -a $1 $2 %p $iif(%current == %p,[loaded]) }
}
alias _profiles.load { return $_profiles.open(l,$1) }
alias _profiles.spawn { return $_profiles.open(s,$1) }
alias _profiles.d.new { return $dialog(_newprofile,_profiles,-4) }
alias _profiles.bnew {
var %old = $1,%new = $2,%olddir,%newdir,%newmircini
if (%old == $null) { %olddir = $mircdir $+ etc\profile\ }
elseif ($_profiles.exists(%old)) { %olddir = $mircdir $+ usr\ $+ %old $+ \ }
else {
error.a Invalid Profile: $^'(%old)
return 1
}
%new = $_parameter(%new,1,Profiles [/profiles],alias:_profiles.isvalidnamefornewprofile,$null,New profile name:)
%newdir = $mircdir $+ usr\ $+ %new $+ \
%newmircini = %newdir $+ mirc.ini
.mkdir $"(%newdir)
_dummy $_xcopy(%olddir,%newdir,*,_)
if ($_not($isfile(%newmircini))) { .copy -o $"($mircini) $"(%newmircini) }
writeini $"(%newmircini) rfiles n0 usr\ $+ %new $+ \users.mrc
writeini $"(%newmircini) rfiles n1 usr\ $+ %new $+ \vars.mrc
_profiles.fixmircini2 %newmircini
if ($show) { info.a Generated new profile: $^'(%new) }
_profiles.d.init
}
; /_profiles.import <new profile> [mirc.ini]
alias _profiles.import {
var %new = $1,%mircini = $2-,%wc = $left($mircdir,3) $+ mirc.ini,%newdir,%newmircini,%olddir = $mircdir $+ etc\profile\
if (%mircini == $null) { %mircini = $$dir="Select 'mirc.ini':" %wc }
if ($_not($_profiles.ismircini(%mircini))) {
error.a Invalid mirc.ini: $^'(%mircini)
return 1
}
%new = $_parameter(%new,1,Profiles [/profiles],alias:_profiles.isvalidnamefornewprofile,$null,New profile name:)
%newdir = $mircdir $+ usr\ $+ %new $+ \
%newmircini = %newdir $+ mirc.ini
.mkdir $"(%newdir)
_dummy $_xcopy(%olddir,%newdir,*,_)
.copy -o $"(%mircini) $"(%newmircini)
_profiles.fixmircini1 %newmircini
writeini $"(%newmircini) rfiles n0 usr\ $+ %new $+ \users.mrc
writeini $"(%newmircini) rfiles n1 usr\ $+ %new $+ \vars.mrc
_profiles.fixmircini2 %newmircini
if ($show) { info.a Generated new profile: $^'(%new) (imported from $^'(%mircini) $+ ) }
_profiles.d.init
}
alias _profiles.ismircini {
var %file = $1-,%i
if ($isfile(%file)) && ($ini(%file,0)) {
if ($ini(%file,text)) { inc %i }
if ($ini(%file,channels)) { inc %i }
if ($ini(%file,pfiles)) { inc %i }
if ($ini(%file,afiles)) { inc %i }
if ($ini(%file,rfiles)) { inc %i }
if (%i > 1) { return 1 }
}
return 0
}
alias _profiles.fixmircini1 {
var %file = $1-
if ($_not($isfile(%file))) { return 1 }
saveini
_dummy $_initopic2initopic($mircini,%file,pfiles)
_dummy $_initopic2initopic($mircini,%file,clicks)
_dummy $_initopic2initopic($mircini,%file,dirs)
_dummy $_initopic2initopic($mircini,%file,dragdrop)
_dummy $_initopic2initopic($mircini,%file,extensions)
_dummy $_initopic2initopic($mircini,%file,rfiles)
_dummy $_initopic2initopic($mircini,%file,afiles)
_dummy $_initopic2initopic($mircini,%file,perform)
}
alias _profiles.fixmircini2 {
var %file = " $+ $1- $+ "
if ($_not($isfile(%file))) { return 1 }
writeini %file quit $ $+ _mircquit(Don't edit this line! (use "/msgedit"))
}
ON *:DIALOG:_newprofile:init:0:{
var %dir = $mircdir $+ usr\,%current = $_getusrdir
_mdx.init $_icofile(profiles.ico)
if (%current == $null) || ($_not($_profiles.exists(%current))) { %current = default }
dialog -t $dname Select Base Profile:
did -h $dname 1010
did -v $dname 1011,2101,2102
did -r $dname 1011
did -a $dname 1011 Default Profile $iif(%current == default,[loaded])
did -o $dname 2001 1 &Generate
_dummy $finddir(%dir,*,0,1,_profiles.d.initdir $dname 1011 $1-)
}
ON *:DIALOG:_newprofile:sclick:2101:{
.timer -o 1 0 _profiles.bnew
dialog -x $dname
_unloadprofilesmrc
}
ON *:DIALOG:_newprofile:sclick:2001:{ _newprofile.blahblehblih }
ON *:DIALOG:_newprofile:dclick:1011:{ _newprofile.blahblehblih }
alias -l _newprofile.blahblehblih {
if ($did($dname,1011,$did($dname,1011).sel) != $null) {
.timer -o 1 0 _profiles.bnew $ifmatch
dialog -x $dname
_unloadprofilesmrc
}
else { halt }
}
alias _profiles.open {
var %f = $1,%p = $2,%text,%stop = 0,%d = _profiles
if (%p == $null) { return ERR_NULL }
if (l isin %f) && (%p == $_getusrdir) {
if ($dialog(%d)) {
dialog -x %d
_unloadprofilesmrc
}
if (i !isincs %f) { info.a Profile already loaded: $^'(%p) }
return 0
}
if ($_not($_profiles.isvalidname(%p))) {
error.a Invalid profile name: $^'(%p)
return ERR_BADNAME
}
if ($_not($_profiles.exists(%p))) {
error.a Profile doesn't exists: $^'(%p)
return ERR_NOTFOUND
}
if ($lock(run)) {
error.a Can't $iif(l isin %f,load,spawn) profiles. The /run command is locked.
return ERR_RUNLOCK
}
if (l isin %f) { %text = Close the current session to load profile %p $+ ? }
elseif (s isin %f) { %text = Spawn a new session? (profile; %p $+ ) }
if (%text != $null) { %stop = $_not($_yesno(0,Profiles [/profiles],1,%text)) }
if (%stop) { return ERR_STOPPED }
if ($dialog(%d)) {
dialog -x %d
_unloadprofilesmrc
}
if (%p == default) { run $shortfn($mircexe) }
else { run $shortfn($mircexe) -i" $+ $mircdir $+ usr\ $+ %p $+ \mirc.ini $+ " }
if (l isin %f) {
info.s Loading Profile: $^'(%p) - Exiting...
_exit
}
elseif (s isin %f) { info.a Spawning Profile: $^'(%p) }
return 0
}
alias _profiles.isvalidnamefornewprofile {
var %p = $1-,%dir = $mircdir $+ usr\ $+ %p $+ \
if ($_profiles.isvalidname(%p)) {
if ($isdir(%dir)) { return 0 }
return 1
}
return 0
}
alias _profiles.exists {
var %p = $1-
if (%p == default) { return 1 }
if ($_profiles.isvalidname(%p)) {
var %mircini = $mircdir $+ usr\ $+ %p $+ \mirc.ini
if ($isfile(%mircini)) { return 1 }
}
return 0
}
alias _profiles.isvalidname {
var %p = $1-
if (%p == $null) { return 0 }
if ($len(%p) > 8) { return 0 }
if ($remove(%p,_) !isalnum) { return 0 }
return 1
}
;;;;
;;;;
alias -l _unloadprofilesmrc { _quickunload _profiles,_newprofile $script }