INI Edit — File Browser

INIEditv1.1 / INIEditv1.1 / INIEdit / iniedit.mrc

iniedit.mrc — 17.52 KB — Download this file

;INI Edit v1.1
;by. 2LAYER

;Copyright (c) 2004, 2LAYER
;All rights reserved.
;Redistribution and use in source forms, with or without modification, are permitted provided that the following conditions are met:
;* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
;* Redistributions in source form must reproduce the above copyright notice, this list of conditions and the following disclaimer
;  in the documentation and/or other materials provided with the distribution.
;* Neither the name of the 2LAYER nor the names of its contributors may be used to endorse or promote products derived
;  from this software without specific prior written permission.
;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
;INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
;IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
;OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
;OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
;OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
;EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

menu * { 
  INI Edit 
  .INI Edit { iniedit } 
  .Readme { run notepad.exe $scriptdir $+ readme.txt }
  .Unload
  ..Unload {
    if ($input(Are you sure you want to unload INI Edit $readini(iniedit.ini, options, version) $+ ?,8) == $true) { 
      if ($input(Do you want to delete iniedit.ini $+ $chr(44) iniedit1.ini $+ $chr(44) inieditU.ini and inieditR.ini?,8) == $true) { 
        if ($exists($mircdir $+ iniedit.ini) == $true) {
          remove $mircdir $+ iniedit.ini
        }
        if ($exists($mircdir $+ iniedit1.ini) == $true) {
          remove $mircdir $+ iniedit1.ini
        }
        if ($exists($mircdir $+ inieditU.ini) == $true) {
          remove $mircdir $+ inieditU.ini
        }
        if ($exists($mircdir $+ inieditR.ini) == $true) {
          remove $mircdir $+ inieditR.ini
        }
      }
      unload -rs iniedit.mrc
    }
  }
}
alias iniedit.init {
  var %iniedit.options.file = $readini(iniedit.ini, options, file)
  if ($exists(%iniedit.options.file) == $true) {
    did -rz iniedit 1
    did -rza iniedit 2 %iniedit.options.file
    var %iniedit.sections.max = $ini(%iniedit.options.file,0)
    var %iniedit.sections.i = 1
    while (%iniedit.sections.i <= %iniedit.sections.max) { 
      did -a iniedit 1 $ini(%iniedit.options.file,%iniedit.sections.i)
      inc %iniedit.sections.i 
    }
  }
}
alias iniedit.section {
  var %iniedit.options.file = $readini(iniedit.ini, options, file)
  if ($exists(%iniedit.options.file) == $true) {
    did -rz iniedit 6
    did -r iniedit 12
    did -r iniedit 13
    var %iniedit.items.max = $ini(%iniedit.options.file,$did(1).seltext,0)
    var %iniedit.items.i = 1
    did -ra iniedit 8 $did(1)
    while (%iniedit.items.i <= %iniedit.items.max) { 
      did -a iniedit 6 $ini(%iniedit.options.file,$did(1).seltext,%iniedit.items.i) $+ = $+ $readini(%iniedit.options.file,$did(1).seltext,$ini(%iniedit.options.file,$did(1).seltext,%iniedit.items.i))
      inc %iniedit.items.i 
    }
  }
}
alias iniedit.new.item {
  if ($exists($readini(iniedit.ini, options, file)) == $true) && ($did(1) != $null) {
    var %iniedit.item = $input(Add New Item to $did(1),aeq,New Item)
    if (%iniedit.item != $null) {
      var %iniedit.value = $input(Add New Value to %iniedit.item,aeq,New Value)
      if (%iniedit.value != $null) {
        iniedit.undoer
        remini $readini(iniedit.ini, options, file) $did(1) %iniedit.item
        writeini -n $readini(iniedit.ini, options, file) $did(1) %iniedit.item %iniedit.value
        iniedit.section
      }
    }
    dialog -vie iniedit iniedit
  }
}
alias iniedit.new.section {
  if ($exists($readini(iniedit.ini, options, file)) == $true) {
    var %iniedit.section = $input(Add New Section to $readini(iniedit.ini, options, file),aeq,New Section)
    if (%iniedit.section isnum) halt
    if (%iniedit.section != $null) {
      iniedit.undoer
      remini $readini(iniedit.ini, options, file) %iniedit.section
      write $readini(iniedit.ini, options, file) $chr(91) $+ %iniedit.section $+ $chr(93)
      iniedit.init
    }
    dialog -vie iniedit iniedit
  }
}
alias iniedit.rem.section {
  if ($did(1) != $null) {
    iniedit.undoer
    remini $readini(iniedit.ini, options, file) $did(1)
    did -r iniedit 12
    did -r iniedit 13
    did -r iniedit 6
    did -d iniedit 1 $did(1).sel
    did -ra iniedit 8 $did(1)
    iniedit.section
  }
}
alias iniedit.rem.item {
  if ($did(1) != $null) && ($did(6) != $null) {
    iniedit.undoer
    remini $readini(iniedit.ini, options, file) $did(1) $gettok($did(6),1,61)
    did -d iniedit 6 $did(6).sel
    did -ra iniedit 12 $gettok($did(6),1,61)
    did -ra iniedit 13 $gettok($did(6),2,61)
  }
}
alias iniedit.new.file {
  writeini -n $mircdir $+ iniedit.ini options file $mircdir $+ iniedit1.ini
  write -c $mircdir $+ inieditU.ini
  write -c $mircdir $+ inieditR.ini
  write -c $mircdir $+ iniedit1.ini
  did -ra iniedit 2 Untitled
  dialog -t iniedit Untitled - INI Edit $readini($mircdir $+ iniedit.ini,options,version)
  did -rz iniedit 1
  did -rz iniedit 6
  did -r iniedit 8
  did -r iniedit 12
  did -r iniedit 13
  did -b iniedit 27
  did -b iniedit 31
  did -b iniedit 30
  dialog -vie iniedit iniedit
}
alias iniedit.redo {
  copy -o $mircdir $+ iniedit1.ini $mircdir $+ inieditU.ini
  copy -o $mircdir $+ inieditR.ini $mircdir $+ iniedit1.ini
  var %iniedit.options.file = $mircdir $+ iniedit1.ini
  if (%iniedit.options.file != $null) {
    writeini -n iniedit.ini options file %iniedit.options.file
    did -rz iniedit 1
    did -rz iniedit 6
    did -r iniedit 8
    did -r iniedit 12
    did -r iniedit 13
    did -b iniedit 31
    did -e iniedit 30
    var %iniedit.sections.max = $ini(%iniedit.options.file,0)
    var %iniedit.sections.i = 1
    while (%iniedit.sections.i <= %iniedit.sections.max) { 
      did -a iniedit 1 $ini(%iniedit.options.file,%iniedit.sections.i)
      inc %iniedit.sections.i 
    }
  }
}
alias iniedit.undo {
  copy -o $mircdir $+ iniedit1.ini $mircdir $+ inieditR.ini
  copy -o $mircdir $+ inieditU.ini $mircdir $+ iniedit1.ini
  var %iniedit.options.file = $mircdir $+ iniedit1.ini
  if (%iniedit.options.file != $null) {
    writeini -n iniedit.ini options file %iniedit.options.file
    did -rz iniedit 1
    did -rz iniedit 6
    did -r iniedit 8
    did -r iniedit 12
    did -r iniedit 13
    did -b iniedit 30
    did -e iniedit 31
    var %iniedit.sections.max = $ini(%iniedit.options.file,0)
    var %iniedit.sections.i = 1
    while (%iniedit.sections.i <= %iniedit.sections.max) { 
      did -a iniedit 1 $ini(%iniedit.options.file,%iniedit.sections.i)
      inc %iniedit.sections.i 
    }
  }
}
alias iniedit.browse {
  var %iniedit.options.file = $sfile($mircdir $+ *.ini,INI Edit,Open)
  if (%iniedit.options.file != $null) {
    dialog -t iniedit %iniedit.options.file - INI Edit $readini($mircdir $+ iniedit.ini,options,version)
    writeini -n iniedit.ini options file %iniedit.options.file
    did -ra iniedit 2 %iniedit.options.file
    did -rz iniedit 1
    did -rz iniedit 6
    did -r iniedit 8
    did -r iniedit 12
    did -r iniedit 13
    did -b iniedit 31
    did -b iniedit 30
    var %iniedit.sections.max = $ini(%iniedit.options.file,0)
    var %iniedit.sections.i = 1
    while (%iniedit.sections.i <= %iniedit.sections.max) { 
      did -a iniedit 1 $ini(%iniedit.options.file,%iniedit.sections.i)
      inc %iniedit.sections.i 
    }
  }
}
alias iniedit.save {
  if ($readini($mircdir $+ iniedit.ini, options, file) != $mircdir $+ iniedit1.ini) && ($readini($mircdir $+ iniedit.ini, options, file) != $mircdir $+ iniedit.ini) && ($readini($mircdir $+ iniedit.ini, options, file) != $mircdir $+ inieditU.ini) && ($readini($mircdir $+ iniedit.ini, options, file) != $mircdir $+ inieditR.ini) { }
  else {
    if ($input(Can't save information to temp file! Do yo want to Save As?,wy,Error) == $true) { 
      iniedit.saveas
      halt
    }
  }
  if ($readini(iniedit.ini,options,file) != $null) {
    if ($file($mircdir $+ iniedit1.ini).size > 65536) {
      if ($input(Size of $readini($mircdir $+ iniedit.ini,options,file) is more than 64k. Do you want to continue?,wy) == $false) { halt }
    }
    copy -o $mircdir $+ iniedit1.ini " $+ $readini($mircdir $+ iniedit.ini,options,file) $+ "
    did -b iniedit 30
    did -b iniedit 31
    dialog -t iniedit $did(2) - INI Edit $readini($mircdir $+ iniedit.ini,options,version)
  }
}
alias iniedit.saveas {
  var %iniedit.options.file = $sfile($mircdir $+ *.ini,INI Edit,Save As)
  if (%iniedit.options.file != $mircdir $+ iniedit1.ini) && (%iniedit.options.file != $mircdir $+ iniedit.ini) && (%iniedit.options.file != $mircdir $+ inieditR.ini) && (%iniedit.options.file != $mircdir $+ inieditU.ini) { }
  else { if ($input(Can't save information to temp file! Change file location.,wo,Error) == $true) { halt } }
  if (%iniedit.options.file != $null) {
    if ($file($mircdir $+ iniedit1.ini).size > 65536) {
      if ($input(Size of %iniedit.options.file is more than 64k. Do you want to continue?,wy) == $false) { halt }
    }
    copy -o $mircdir $+ iniedit1.ini " $+ %iniedit.options.file $+ "
    writeini -n $mircdir $+ iniedit.ini options file %iniedit.options.file
    did -e iniedit 27
    did -b iniedit 30
    did -b iniedit 31
    dialog -t iniedit %iniedit.options.file - INI Edit $readini($mircdir $+ iniedit.ini,options,version)
  }
}
alias iniedit.undoer { 
  did -e iniedit 30
  did -b iniedit 31
  copy -o $mircdir $+ iniedit1.ini $mircdir $+ inieditU.ini
  dialog -t iniedit $did(2) (Modified) - INI Edit $readini($mircdir $+ iniedit.ini,options,version)
}
alias iniedit.exitchanges {
  var %iniedit.result = $input(The text in the $did(2) has been changed. Do you want to save the changes?,wvn,INI Edit $readini($mircdir $+ iniedit.ini,options,version))
  if (%iniedit.result == $true) { 
    iniedit.save 
    dialog -x iniedit iniedit
  }
  elseif (%iniedit.result == $false) { halt }
  else { dialog -x iniedit iniedit } 
}
alias iniedit { if ($dialog(iniedit) == $null) dialog -mdie iniedit iniedit }
dialog iniedit {
  size -1 -1 291 167
  option dbu
  combo 1, 1 29 100 105, size hsbar vsbar
  edit "", 2, 15 3 227 10, disable
  text "File:", 3, 2 4 12 8
  button "Browse", 4, 244 3 45 10
  text "Section:", 5, 1 19 26 8
  combo 6, 103 29 139 105, size hsbar vsbar
  text "Item&&Value:", 7, 103 19 29 8
  edit "", 8, 25 135 218 10
  text "Section:", 9, 2 136 22 8
  text "Item:", 10, 2 146 22 8
  text "Value:", 11, 2 156 22 8
  edit "", 12, 25 145 218 10
  edit "", 13, 25 155 218 10
  button "Change", 14, 244 135 45 10
  button "Change", 15, 244 145 45 10
  button "Change", 16, 244 155 45 10
  button "New File", 17, 244 29 45 10
  button "Rem Section", 18, 244 59 45 10
  button "Clear File", 19, 244 79 45 10
  button "New Section", 20, 244 39 45 10
  button "New Item", 21, 244 49 45 10
  button "Del File", 22, 244 89 45 10
  button "Rem Item", 23, 244 69 45 10
  menu "File", 24
  item "New File", 25, 24
  item break, 43
  item "Open", 26, 24
  item break, 44
  item "Save", 27, 24
  item "Save As", 28, 24
  item break, 45
  item "Exit", 40, 24
  menu "Edit", 29
  item "Undo", 30, 29
  item "Redo", 31, 29
  item break, 41
  item "New Section", 32, 29
  item "New Item", 33, 29
  item break, 42
  item "Rem Section", 34, 29
  item "Rem Item", 35, 29
  menu "Help", 36
  item "Readme", 37, 36
  item "Version info", 38, 36
  item break, 46
  item "About", 39, 36
}
on *:dialog:iniedit:init:*:{ 
  if ($exists($mircdir $+ iniedit.ini) == $false) {
    writeini -n iniedit.ini options version v1.1
  }
  if ($readini($mircdir $+ iniedit.ini, options, version) == $null) {
    writeini -n iniedit.ini options version v1.1
  }
  iniedit.init 
  did -b iniedit 30
  did -b iniedit 31
  dialog -t iniedit INI Edit $readini(iniedit.ini, options, version)
  if ($readini(iniedit.ini, options, file) != $mircdir $+ iniedit.ini) && ($readini(iniedit.ini, options, file) != $mircdir $+ iniedit1.ini) && ($readini(iniedit.ini, options, file) != $mircdir $+ inieditR.ini) && ($readini(iniedit.ini, options, file) != $mircdir $+ inieditU.ini) { }
  else { did -b iniedit 27 }
  if ($exists($readini(iniedit.ini, options, file)) == $false) {
    iniedit.new.file
  }
}
;FILE Menu
on *:dialog:iniedit:menu:25:{ iniedit.new.file }
on *:dialog:iniedit:menu:26:{ iniedit.browse }
on *:dialog:iniedit:menu:27:{ iniedit.save }
on *:dialog:iniedit:menu:28:{ iniedit.saveas }
on *:dialog:iniedit:menu:40:{
  if ($wildtokcs($dialog(iniedit).title,(M*d),$wildtokcs($dialog(iniedit).title,(M*d),0,32),32) == $chr(40) $+ Modified $+ $chr(41)) { iniedit.exitchanges }
  else { dialog -x iniedit iniedit }
}
;EDIT Menu
on *:dialog:iniedit:menu:30:{ iniedit.undo }
on *:dialog:iniedit:menu:31:{ iniedit.redo }
on *:dialog:iniedit:menu:32:{ iniedit.new.section }
on *:dialog:iniedit:menu:33:{ iniedit.new.item }
on *:dialog:iniedit:menu:34:{ iniedit.rem.section }
on *:dialog:iniedit:menu:35:{ iniedit.rem.item }
;HELP Menu
on *:dialog:iniedit:menu:37:{ run notepad.exe $scriptdir $+ readme.txt }
on *:dialog:iniedit:menu:38:{ run notepad.exe $scriptdir $+ Version_info.txt }
on *:dialog:iniedit:menu:39:{
  if ($input(INI Edit $readini(iniedit.ini, options, version) (c): 2LAYER,io,About) == $true) { }
}

;Item change
on *:dialog:iniedit:sclick:15:{
  if ($did(8) != $null) && ($exists($readini(iniedit.ini, options, file)) == $true) && ($did(12) != $null) && ($did(6) != $null) && ($did(13) != $null) {
    if ($did(6) == $did(12)) halt
    iniedit.undoer
    var %iniedit.file = $readini(iniedit.ini, options, file)
    var %iniedit.lines = $lines($readini(iniedit.ini, options, file))
    var %iniedit.i = 1
    while (%iniedit.i <= %iniedit.lines) {
      if ($read(%iniedit.file,%iniedit.i) == $did(12)) { remini %iniedit.file $did(1) $did(12) }
      if ($read(%iniedit.file,%iniedit.i) == $did(6)) { var %iniedit.editline = %iniedit.i }
      inc %iniedit.i
    }
    if (%iniedit.editline != $null) {
      write -dl $+ %iniedit.editline %iniedit.file $did(12) $+ = $+ $did(13)
      write -il $+ %iniedit.editline %iniedit.file $did(12) $+ = $+ $did(13)
    }
    iniedit.section
  }
}

;Section change
on *:dialog:iniedit:sclick:14:{
  if ($did(1) != $null) && ($exists($readini(iniedit.ini, options, file)) == $true) && ($did(8) != $null) {
    if ($did(8) isnum) halt
    if ($did(1) == $did(8)) halt
    iniedit.undoer
    var %iniedit.file = $readini(iniedit.ini, options, file)
    var %iniedit.lines = $lines($readini(iniedit.ini, options, file))
    var %iniedit.i = 1
    while (%iniedit.i <= %iniedit.lines) {
      if ($read(%iniedit.file,%iniedit.i) == $chr(91) $+ $did(8) $+ $chr(93)) { remini %iniedit.file $did(8) }
      if ($read(%iniedit.file,%iniedit.i) == $chr(91) $+ $did(1) $+ $chr(93)) { var %iniedit.editline = %iniedit.i }
      inc %iniedit.i
    }
    if (%iniedit.editline != $null) {
      write -dl $+ %iniedit.editline %iniedit.file $chr(91) $+ $did(8) $+ $chr(93)
      write -il $+ %iniedit.editline %iniedit.file $chr(91) $+ $did(8) $+ $chr(93)
    }
    iniedit.init
  }
}

;Value change
on *:dialog:iniedit:sclick:16:{
  if ($did(1) != $null) && ($exists($readini(iniedit.ini, options, file)) == $true) && ($did(12) != $null) && ($did(6) != $null) {
    if ($did(6) == $did(13)) { halt }
    iniedit.undoer
    writeini -n $readini(iniedit.ini, options, file) $did(1) $gettok($did(6),1,61) $did(13)
    iniedit.section
  }
}

;New item
on *:dialog:iniedit:sclick:21:{ iniedit.new.item }

;New Section
on *:dialog:iniedit:sclick:20:{ iniedit.new.section }

;New file
on *:dialog:iniedit:sclick:17:{ iniedit.new.file }

;Rem section
on *:dialog:iniedit:sclick:18:{ iniedit.rem.section }

;Rem item
on *:dialog:iniedit:sclick:23:{ iniedit.rem.item }

;Del file
on *:dialog:iniedit:sclick:22:{ 
  if ($exists($readini(iniedit.ini, options, file)) == $true) && ($input(Delete $nopath($readini(iniedit.ini, options, file))?,8) == $true) { 
    iniedit.undoer
    remove $readini(iniedit.ini, options, file)
    remini iniedit.ini options file
    did -rz iniedit 1
    did -rz iniedit 6
    did -r iniedit 2
    did -r iniedit 8
    did -r iniedit 12
    did -r iniedit 13
  }
  dialog -vie iniedit iniedit
}

;Clear file
on *:dialog:iniedit:sclick:19:{ 
  if ($exists($readini(iniedit.ini, options, file)) == $true) && ($input(Clear $nopath($readini(iniedit.ini, options, file))?,8) == $true) { 
    iniedit.undoer
    write -c $readini(iniedit.ini, options, file)
    did -rz iniedit 1
    did -rz iniedit 6
    did -r iniedit 8
    did -r iniedit 12
    did -r iniedit 13
  }
  dialog -vie iniedit iniedit
}

;Section combo
on *:dialog:iniedit:sclick:1:{ iniedit.section }

;item&Value combo
on *:dialog:iniedit:sclick:6:{
  if ($did(6) != $null) {
    did -ra iniedit 12 $gettok($did(6),1,61)
    did -ra iniedit 13 $gettok($did(6),2,61)
  }
}

;Browse
on *:dialog:iniedit:sclick:4:{ iniedit.browse }

;Script loaded first time
on *:LOAD:{ if ($exists($scriptdir $+ readme.txt) == $true) { run notepad.exe $scriptdir $+ readme.txt } }