mIRC Homepage
Posted By: sparta $submenu - 06/09/07 08:50 AM
I using this code:
Code:
$submenu($disks($1))

alias disks {
  if ($1 == 1) && ($disk(c)) return Disk &C $chr(187) Size $+ $chr(58) $hd1 :{ diskziz 99 }
  if ($1 == 2) && ($disk(d)) return Disk &D $chr(187) Size $+ $chr(58) $hd2 :{ diskziz 100 }
  if ($1 == 3) && ($disk(e)) return Disk &E $chr(187) Size $+ $chr(58) $hd3 :{ diskziz 101 }
}

and it working ok, but i have one problem, that's the $hd1 - $hd2 - $hd3 .. it wont return the size of the disk, how ever if i echo it to me, then it return the size, any ideas why it's not shown in popups? smirk
Posted By: jaytea Re: $submenu - 06/09/07 09:53 AM
it should be working, it's just part of the command. the first : indicates the end of the item name, even if you escape it with $chr(58). there's no way around this unfortunately ;( choose a different character to use after 'Size'

Posted By: sparta Re: $submenu - 06/09/07 10:04 AM
Ty, that solved the problem smile

a new problem tho crazy

Now my code looks like:
Code:
alias disks {
  var %id = 1
  var %dz = 99
  while (%dz <= 122) {
    if ($1 == %id) && ($disk($chr(%dz))) return Disk $upper($+(&,$chr(%dz))) Size $chr(149) $hd :/
    inc %id
    inc %dz
  }
}
alias hd {
  if ($disk($chr(%dz)).type == cdrom) { return CD-Rom }
  return $calc(%HDD_total + $bytes($disk($chr(%dz)).size,g))
}

But it return the same size for all the disks, and i can't get it to return if the disk/drive is a CD or a hard drive, someone that can point me in the right direction here?
Posted By: Bekar Re: $submenu - 06/09/07 01:09 PM
pass %dz to $hd (i.e. $hd(%dz)), and use $1 in the 'alias hd' instead. Just make sure it's not some weird sort of scope issue.

Also, what's this %HDD_total thing?
Posted By: sparta Re: $submenu - 06/09/07 06:45 PM
I cant get it to work, and the %HDD_total is something i used befor, i trying to change all my alias for something faster.
Code:
alias hd {
  var %x = 99
  while (%x <= 122) {
    if ($disk($chr(%_zd)).type == cdrom) { return CD-Rom }
    return $calc($bytes($disk($chr(%x)).size,g))
    inc %x
  }
}

the code wont loop true all disk's, it send me the size of C no mather what.. smirk
Posted By: LonDart Re: $submenu - 06/09/07 07:32 PM
using echo rather than return, the following worked well in my status window
Code:
alias hd {
  var %dz = 99
  var %dcnt = $disk(0) + %dz
  while ( %dz < %dcnt ) {
    if ($disk($chr(%dz)).type == cdrom) { echo 3 -s Disk $upper($chr(%dz)) - CD-Rom }
    else echo -s Disk $upper($chr(%dz)) - $bytes($disk($chr(%dz)).size,g) GB
    inc %dz
  }
}


When I had %dz <= 122, I got an 'insufficient parameters' error for non-existent drives.
Don't need $calc with $bytes.
It appears size for CDrom drives is always 0.

In your last post you didn't have all your variables changed to %x (typo?)

hth
Posted By: Wims Re: $submenu - 06/09/07 07:49 PM
If he used return, it's maybe because he wants return all infos about disks at the same moment :
Code:
alias dinfo return $regsubex($str(t $chr(32),$calc($disk(0))),/t/g,$iif($disk($calc(\n +1)) || $disk($calc(\n +1)).type == cdrom,$disk($calc(\n + 1)).path -> $iif($disk($calc(\n +1)).type == cdrom,Cd-rom,$bytes($disk($calc(\n +1)).size,g).suf) -))


It's much cleaner with a while but I just post this for fun smile
Posted By: sparta Re: $submenu - 06/09/07 07:57 PM
No typo, i tested to rewrite it, and i changed the %var since it was a new code.
Posted By: sparta Re: $submenu - 06/09/07 08:00 PM
Nope, that code didnt do the trick ether, so dunno why it wont work. crazy
Posted By: Wims Re: $submenu - 06/09/07 08:02 PM
I make a typo lol. i use "alias $dinfos" instead of "alias dinfos"
I've edited...
If it still doesn't works, can you detail ?
Posted By: sparta Re: $submenu - 06/09/07 08:22 PM
I noticed you named it wrong wink and if i use //echo your code , then it working as it should, but when i try use it in my submenu, then it return nothing to the menu smirk
Code:
alias disks {
  var %id = 1
  var %dz = 99
  while (%dz <= 122) {
    if ($1 == %id) && ($disk($chr(%dz))) return Disk $upper($+(&,$chr(%dz))) Size $chr(149) $hd :/
    inc %id
    inc %dz
  }
}

this is the submenu i try to return the info to..
Posted By: Wims Re: $submenu - 06/09/07 09:17 PM
Hum, use this :

Code:
alias disks {
  var %a = $disk(0)
  while (%a) {
    if ($1 == %a) { return $left($disk(%a).path,1) : echo -a $iif($disk(%a).type == cdrom,Cd-rom,$bytes($disk(%a).size,g).suf) }
    dec %a
  }
}


I use $left for the path because if not, mirc parse the ":" (of C:\ for exemple) like a command and said : "\ Unknown command"
I've tried a lot of thing to prevent this but without success.
Posted By: sparta Re: $submenu - 06/09/07 09:24 PM
hmm, tested your code, the result was that it takes around 3 sec to open up popups, so nothing i can use, sorry confused
Posted By: Bekar Re: $submenu - 06/09/07 09:39 PM
Ok, lets look at this in a step-by-step process:

$submenu($disks($1)) will call 'disks' with arguments 1, 2, 3, etc..

As you were permenantly setting %id to 1, you'll be looping pointlessly many many times.

If you have any breaks in your drive letter sequence, it won't get the latter drive references.

Now, all that aside, you want something that looks like this:

Code:
alias -l disks {
  if ($1 == begin) {
    var %dz = 99
    while (%dz <= 122) {
      if ($disk($chr(%dz))) {
        %drivelist = $addtok(%drivelist, $chr(%dz), 124)
      }
      inc %dz
    }
  }
  elseif ($1 == end) {
    unset %drivelist
  }
  elseif ($1 isnum && $1 <= $numtok(%drivelist, 124)) {
    return Disk $upper($+(&,$gettok(%drivelist, $1, 124))) Size $chr(149) $hd($gettok(%drivelist, $1, 124)) :/
  }
}
alias -l hd {
  if ($disk($$1).type == cdrom) { return CD-Rom }
  return $calc($bytes($disk($$1).size,g))
}
menu status {
  Disk state:
  .$submenu($disks($1))
}

This is tested. To explain it out a bit..

In the 'begin', we generate a list of drive devices, and then store it in %drivelist.

In the 'end', we clear out the no-longer needed variable.

In the 'isnum' section, we see if our $submenu() call has exceeded the number of tokens in our %drivelist. If not, we return the details for the drive we're up to in our $submenu() automated loop.

Hope this helps
Posted By: Wims Re: $submenu - 06/09/07 09:57 PM
Originally Posted By: Sparta
hmm, tested your code, the result was that it takes around 3 sec to open up popups, so nothing i can use, sorry


This is normal, and i can't change this behavior, the while loop will try to return a value for each disk, and especially for A:\.
Look into A:\ take so long time, so the pop up just show after the execution of the while, but you can avoid the problem by not returning something for A:\ :

Code:
alias dinfos1 {
  var %a 1 ,%b = $disk(0)
  while (%a <= %b) {
    if ($1 == 1) return -
    elseif ($1 == %a) { return $left($disk(%a).path,1) : echo -a $iif($disk(%a).type == cdrom,Cd-rom,$bytes($disk(%a).size,g).suf) }
    inc %a
  }
}


on my computer, $disk(1) represent A:\, don't know if it's the case on any computer so maybe you have to change the "1" in this line :
Code:
if ($1 == 1) return -
Posted By: hixxy Re: $submenu - 06/09/07 09:59 PM
What's the point in looping %a when you can just use $disk($1) ? confused
Posted By: Wims Re: $submenu - 06/09/07 10:06 PM
Yes you're right lol, after some test and some /echo, it seems that $submenu already doing a while itself so the alias can be simplified :

alias dinfos1 {
if ($1 == 1) return -
else { return $left($disk($1).path,1) : echo -a $iif($disk($1).type == cdrom,Cd-rom,$bytes($disk($1).size,g).suf) }
}

Edit : I did not see Bekar's answer
Posted By: hixxy Re: $submenu - 06/09/07 10:12 PM
Submenu loops until you don't return a value, and then it will send "end" as $1

If you do this for example:

Code:
alias infinite_loop { return $1: noop }

menu menubar {
  $submenu($infinite_loop($1))
}


You'll see that it adds hundreds of items to the menu.
Posted By: Wims Re: $submenu - 06/09/07 10:27 PM
Ok thx, $submenu isn't something i often use (i'm sure i'm not only wink )
Posted By: Horstl Re: $submenu - 07/09/07 12:53 PM
I like this one, should be fast enough (tested with some HDDs, USBremovable and 1 optical drive (I have no floppy drive).
Code:
alias -l sub.drives {
  ; cycle drives
  if ($1 == begin) {
    var %asc = 99
    while (%asc <= 122) {
      if ($disk($chr(%asc))) {
        var %d = $upper($chr(%asc))
        ; store sums of fixed/removable drives
        if ($istok(fixed removable,$disk(%d).type,32)) {
          set -u %sub.drive.list $addtok(%sub.drive.list,%d 1 $disk(%d).size $disk(%d).free,124)
          inc -u %sub.drive.total $disk(%d).size
          inc -u %sub.drive.free $disk(%d).free
        }
        ; other drives: store only type
        else { set -u %sub.drive.list $addtok(%sub.drive.list,%d $disk(%d).type 0 0,124) }
      }
      inc %asc
    }
  }
  ; return drive info
  elseif (($1 isnum) && ($gettok(%sub.drive.list,$1,124))) {
    var %d = $gettok($v1,1,32),%ty = $gettok($v1,2,32), %t = $gettok($v1,3,32), %f = $gettok($v1,4,32)
    return Drive %d $chr(149) $iif((%ty != 1),$upper($v1) $qt($disk(%d).label),$qt($disk(%d).label) $chr(149) $&
      $bytes(%t,g) GB $+([,free $bytes(%f,g) GB = $round($calc(%f / %t *100),1),$chr(37),])) : run $disk($1).path
  }
  ; return totals
  elseif ($1 == end) {
    return --TOTAL-- $bytes(%sub.drive.total,g) GB $+([,free $bytes(%sub.drive.free,g) GB = $&
      $round($calc(%sub.drive.free / %sub.drive.total *100),1),$chr(37),]) : noop
  }
}

menu status {
  Drive Info
  .$submenu($sub.drives($1))
}

Atm it's looking up "C:" to "Z:".
To start with "A:", change this line's value to "97":
var %asc = 99
Posted By: sparta Re: $submenu - 07/09/07 01:29 PM
That one looks nice.. grin i try figure out how it works, didn't look too advanced tho smile thnx to all that helped out smile

; edit

It working, but i noticed one problem, if the label = null, then it only return "" , $qt($disk(%d).label) <- that part, how ever if i try change it the menu if f*ed up, or it wont return any labels for any disks, i tested add if ($qt($disk(%d).label) == $null) and also $iif($qt($disk(%d).label),$null) and no result, can someone explain to me how i would use the if statement in this code? i know i can remove quotas by remove $qt()..
Posted By: Horstl Re: $submenu - 07/09/07 02:00 PM
$iif(($disk(%d).label),$qt($v1)) should work (used 2 times). My $iif is a mess to be honest smile
Posted By: sparta Re: $submenu - 07/09/07 02:01 PM
I noticed one more problem, atlest here. If i want to brows C: true that code, then it can't open it, and if i open drive D:, then it opens C:, so it's like the path is one less then what it says in the menu.
Posted By: Horstl Re: $submenu - 07/09/07 02:04 PM
You're right, it should be $disk(%d).path not $disk($1).path
Posted By: sparta Re: $submenu - 07/09/07 02:05 PM
working as a charm smile i nether have a: .. no flopys here wink thats something from the stoneage whistle
© mIRC Discussion Forums