David Daily 2020-01-14 09:37:08 -06:00
parent 6893b85b86
commit e6a3caec5a
2 changed files with 34 additions and 2 deletions

34
GloVar.md Normal file

@ -0,0 +1,34 @@
# Global Variables
I created something so that I can always have multiple strings at my fingertips. Its like a clipboard manager but different.
## Top-level overview
What it does is take an ini (based off [this](https://daviddaily.dev/david/d3k/src/branch/master/glovarsource)) and turn it into hotstrings that start with `$` automagically. The Key (left side of the `=`) is the hotstring, the Value (right side of the `=`) is what it gets replaced with.
### Why?
This way I'm not copying and pasting twenty different things, mixing up similar serial numbers or other information. It also doubles as a replacement to a WPF-based application the in-house IT created that generates ugly output and is a pain to use.
## Why aren't you using JSON? Its so much better
You aren't wrong, it would be much easier to manipulate the data. However, **since I'm actively modifying this during a call, I don't want there to be a possibility for me to mess up the syntax.** `ini` has the easiest syntax and can be easily read at a glance.
## How?
Regex mainly. Code starts [here](https://daviddaily.dev/david/d3k/src/branch/master/D3K.ahk#L66), its not really that unreadable, but I'll walk though it here too.
One of the most important things to do is not modify the file while it is still being edited. VSCode does not like it and throws an error if the file it is saving is different than it was before it was modified by the user. However it does *not* care if an open file is being modified by something else. For that we do `WinWaitNotActive, GloVar.ini` right before we modify the file, just to make sure.
To keep track if the file was changed, we check it's last modified time with `FileGetTime, gvModNew, %glovarini%`, and then in the script after we modify the file we do `FileGetTime, gvMod, %glovarini%` so that it doesn't edit the file and say "*Oh look it was modified, must mean there's new info there!*" and run extra times it doesn't need to.
If the last stored modified time the script made is different than its last modified time, we process its data: `if !(gvModNew = gvMod){...}`
Every time we process the `ini`, we completely destroy the automagically created file because that is the easiest way to make sure there isn't any extra stuff in there.
Next, we loop though each line, with regex putting the section name in `RESection` and if it is a Key/Value pair it puts the Key in `REKey` and the Value in `REValue` (wow, what a surprise). If it is under the "Serial Numbers" section it gets made uppercase and the uppercase value is written to the ini. If it is under the "Operations Center" section and the key is `usr` (use it for username, usually only have one), it does the same thing. If the Key is `case`, it strips the `( )` off the front and the back.
If the Key is `xid`, we do some more work. I have a CSV I keep of people I talk to ([example here](https://daviddaily.dev/david/d3k/src/branch/master/emails.example.csv)) that is up to 387 lines. It is also easily added to with [addemail.ahk](https://daviddaily.dev/david/d3k/src/branch/master/addemail.ahk). If the unique identifier of the caller (xID) is found in the CSV, it fills in the details in the `ini` and in the hostrings. If it is not found, we run [addemail.ahk](https://daviddaily.dev/david/d3k/src/branch/master/addemail.ahk) to add their info to the table.
If the section name is changed to `clear`, the contens of the documentation file (where I keep notes on the call / what goes in the case management system) and the contents of the `ini` are appended to a log file that I've had since I came up with the idea in August 2017. Its only 63747 lines long as of writing, but then again its just a `.txt` file. We also copy [the template](https://daviddaily.dev/david/d3k/src/branch/master/glovarsource) to the ini with the overwrite option enabled.
That's it.

@ -1,2 +0,0 @@
# Why not JSON?
Since I'm actively modifying this during a call, I don't want there to be a possibility for me to mess up the syntax. ini has the easiest syntax and can be easily read at a glance.