ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Wish List (https://www.esoui.com/forums/forumdisplay.php?f=177)
-   -   [implemented] Programmatical way to get the API version (https://www.esoui.com/forums/showthread.php?t=1849)

zgrssd 06/25/14 04:29 PM

[implemented] Programmatical way to get the API version
 
There are cases where I would like to get the API version to make checks with in my code. In specific I need a way to detect if the API version changed and manaully reset the stored data to defaults then.

My Addon UTC can store the Categoreis that are enabeled for each tab in each chat container. I asume the current code will be good for a few more years, as there is no even remotely botusable function in the chat part I touch and I use Loops based on #Table and GetNum Functions.

However every time the API version changes the order of chat categories might change. So at least in the first start after a version change I have to reset the settings & data. Doing this via the existing Saved Var Versioning system is not viable (or nessesary for that matter).

All I need is a function "getAPIVersion()" that returns a int or string with the version (either works for me. Only doing an inequality check). Asuming it was not added with the 1.2.3 patch.

farangkao 06/25/14 05:12 PM

As far as i know it's not there, however...

you can use the trick to check for new Functions or Globals (introduced in a certain version)

for example:
Lua Code:
  1. function GetAPIVersion()
  2.   if GetTradingHouseListingItemLink then return 10007 end  
  3.   return 10003
  4. end
I've not tested this example code (just in my mind), basically if a function doesn't exists it returns nil, and therefore the "if" statement fails and goes to the next line.

Halja 06/25/14 06:29 PM

I don't think so. Where I look is in the file AddOnSettings.txt. It's in the same folder as UserSettings and the parent of the Addons folder for the game. The first line declares the API version. It could be in a cVar the new EULA for Addons are. (ViewedAddOnEULAVersion and AcceptedAddOnEULAVersion) Those are exposed in the UserSettings file.
--halja

zgrssd 06/26/14 05:10 AM

Quote:

Originally Posted by farangkao (Post 9754)
As far as i know it's not there, however...

you can use the trick to check for new Functions or Globals (introduced in a certain version)

for example:
Lua Code:
  1. function GetAPIVersion()
  2.   if GetTradingHouseListingItemLink then return 10007 end  
  3.   return 10003
  4. end
I've not tested this example code (just in my mind), basically if a function doesn't exists it returns nil, and therefore the "if" statement fails and goes to the next line.

That is a way if I know of a specific change beforehand (because it was on the PTS). But it requires me to design the code for each new version.
Better then just deletion everytime _VERSION (the build version of the client) changed.

Shinni 06/26/14 05:50 AM

not a perfect way but this should work:
Lua Code:
  1. local AddOnManager = GetAddOnManager()
  2. for i = 1, AddOnManager:GetNumAddOns() do
  3.         local name, title, author, description, enabled, state, isOutOfDate = AddOnManager:GetAddOnInfo(i)
  4.     if title == "myaddonname" then
  5.         if isOutOfDate then
  6.             --api change!
  7.         end
  8.     end
  9. end
it doesn't retrieve the api version but if the addon was uptodate, it will know if there was an API change.

zgrssd 06/26/14 08:03 AM

Quote:

Originally Posted by Shinni (Post 9779)
not a perfect way but this should work:
Lua Code:
  1. local AddOnManager = GetAddOnManager()
  2. for i = 1, AddOnManager:GetNumAddOns() do
  3.         local name, title, author, description, enabled, state, isOutOfDate = AddOnManager:GetAddOnInfo(i)
  4.     if title == "myaddonname" then
  5.         if isOutOfDate then
  6.             --api change!
  7.         end
  8.     end
  9. end
it doesn't retrieve the api version but if the addon was uptodate, it will know if there was an API change.

Very nice idea. Just need to store if this OOD state was already detected before.

Since that is propably better to be left to a library to gather all this data once, I made it a Feature Request for OrangUtils.
But I am going to test it a bit via a button. If he thinks it is out of scope, I just make it library myself.


All times are GMT -6. The time now is 04:10 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI