Quantcast
Download
(4 Kb)
Download
Updated: 11/26/20 09:05 AM
Pictures
File Info
Compatibility:
Markarth (6.2.5)
Stonethorn (6.1.5)
Greymoor (6.0.5)
Updated:11/26/20 09:05 AM
Created:05/05/18 10:27 AM
Monthly downloads:2,746
Total downloads:53,662
Favorites:7
MD5:
6.2.5
LibSaveToDisk  Popular! (More than 5000 hits)
Version: 1.3g r6
by: tomtomhotep [More]
This is a library for Addon Authors. If you are a normal user, you have no use for this.

Greetings fellow addon authors.

As we all know, your saved variables aren't saved until the user reloads or logs out. And if their game crashes before that, any changes made to the saved variables are lost!

For some addons, it's not a big deal, but for other addons (like FCOIS or Notebook) it could be HUGE!

One day I lost 30 minutes worth of work setting/changing FCOIS markers and writing out a Guild Mail in Notebook because my game client crashed.

That's when I decided to make this library. It warns the user when one or more addons have substantially changed their saved variables.

What you consider a substantial change is up to you as the addon author using this library.


Just like any other library, get a reference to it with LibStub:


Lua Code:
  1. local STD = LibStub("LibSaveToDisk")


There are 2 library functions you may call:

To register a MAJOR savedvars change with the library:
(i.e. Tell the library you just made a major change)

Lua Code:
  1. STD.CriticalChange("your-addon-name")


To register a MINOR savedvars change with the library:
(i.e. Tell the library you just made a minor change)

Lua Code:
  1. STD.NonCriticalChange("your-addon-name")



There is one major difference between this and the more common libraries:

You must keep the manifest txt file when you embed this library in your addon. Do not remove it!
This is because this library has its own savedVariables file and addon settings panel.

I decided to give this its own settings so the user would have one central place to control how often they want to be bothered by the warning, how long the delay should be when they click "remind me later", and that sort of thing. (See the first screenshot image.)
1.3g r6 - api bump
1.3f r6 - api bump
1.3e r6 - api bump
1.3d r6 - api bump
1.3c r6 - api bump
1.3b r6 - api bump, un-bundled LibStub and LibAddonMenu-2.0
1.3a r5 - api bump
1.3 r4 - api bump
1.2 r3 - made it so that the Prompt Window does not pop up while in Combat
1.1 r2 - updated LibAddonMenu to r26
1.0 r1 - initial release
Archived Files (10)
File Name
Version
Size
Uploader
Date
1.3f r6
4kB
tomtomhotep
04/01/20 01:18 PM
1.3e r6
5kB
tomtomhotep
11/08/19 04:29 PM
1.3d r6
4kB
tomtomhotep
08/29/19 12:53 PM
1.3c r6
4kB
tomtomhotep
05/25/19 12:30 PM
1.3b r6
4kB
tomtomhotep
03/16/19 08:53 AM
1.3a r5
47kB
tomtomhotep
10/27/18 08:32 AM
1.3 r4
47kB
tomtomhotep
09/15/18 03:07 PM
1.2 r3
47kB
tomtomhotep
08/11/18 01:07 PM
1.1 r2
47kB
tomtomhotep
05/28/18 11:42 AM
1.0
47kB
tomtomhotep
05/05/18 10:27 AM


Post A Reply Comment Options
Unread 11/26/20, 03:41 PM  
Akopian Atrebates

Forum posts: 6
File comments: 187
Uploads: 0
Would Be Useful...

Truly it would be useful if more authors did use a reminder to the user to save their work. As for myself, I have a brain injury and have the same problem of making changes that do not stick because I did not relog before a crash or whatever.

The only addon that ever prompts me to relog is one that records all the books you read so that you can read them later (every book, note, whatever).

I do not know the importance of the Libstub argument and how having that library running can mess up other addons that do not use it. Just seems like a lot of Libstub addons break, but maybe that is just related to them being older and not updated in general.

If this addon uses a part of Libstub that is unique, allowing for a relog message trigger, then perhaps a paired down version of Libstub is in order ... Or maybe instead of a new Libstub, you just incorporate whatever code you need from Libstub directly into your own code.

Nevertheless, all that takes time, and I understand that for sure. I thank you for doing what you do, and expect nothing more from you. Anything else is gravy. So thanks so much for your work so far, and all your addons like that nice trading one.
Last edited by Akopian Atrebates : 11/26/20 at 03:42 PM.
Report comment to moderator  
Reply With Quote
Unread 11/26/20, 12:12 PM  
tomtomhotep
 
tomtomhotep's Avatar
AddOn Author - Click to view AddOns

Forum posts: 21
File comments: 213
Uploads: 6
Originally Posted by Baertram
blah ... blah ... libStub ...
Yeah, I don't have time for that.
Report comment to moderator  
Reply With Quote
Unread 11/26/20, 11:03 AM  
Baertram
 
Baertram's Avatar
AddOn Author - Click to view AddOns

Forum posts: 3287
File comments: 3992
Uploads: 64
Hey Tomtomhotep,

pelase remove libStub from that library.
LibStub is obsolete since Summerset and shouldn't be used anymore.

Just use the designed manifest txt entries like ## IsLibrary: true and ## AddOnversion: integer so that the game handles what LibStub did.
Remove the calls AND the DependsOn and just provide a global variable which addons are able to use, e.g. LibSaveToDisk (if not already given).

That's all.

Lua Code:
  1. [email protected] lib @classdef LibSaveToDisk
  2. --local lib = LibStub:NewLibrary("LibSaveToDisk", 6)
  3.  
  4. --Lib was already loaded?
  5. if LibSaveToDisk and LibSaveToDisk.initialized == true then return end
  6.  
  7. local lib = {}
  8.  
  9. ...
  10.  
  11.  
  12. --local LAM = LibStub("LibAddonMenu-2.0")
  13. local LAM = LibAddonMenu2
  14.  
  15. ...
  16.  
  17. --At the bottom of the file
  18. LibSaveToDisk = lib

Code:
# Title: |c3366ffLib|r|cff6633SaveToDisk|r
## APIVersion: 100033 100034
## SavedVariables: LibSaveToDiskVars
## Author: |[email protected]|r|c3366ffhotep|r
## AddOnVersion: 102
## IsLibrary: true
## DependsOn: LibAddonMenu-2.0>=31

LibSaveToDisk.lua
LibSaveToDisk.xml
Also add the >=31 to LAM 2.0 so the newst version is needed and no OLD version will be loaded where the global LibAddonMenu2 is missing.
Attention: In your lua file change calls to LAM from LibStub to LibAddonMenu2 !!!
Lua Code:
  1. local LAM = LibAddonMenu2
Last edited by Baertram : 11/26/20 at 11:08 AM.
Report comment to moderator  
Reply With Quote
Unread 05/26/19, 07:21 AM  
tomtomhotep
 
tomtomhotep's Avatar
AddOn Author - Click to view AddOns

Forum posts: 21
File comments: 213
Uploads: 6
Originally Posted by Rhyono
Thanks, Rhyono. From that discussion, it sounds like this library is still needed for addons like Notebook 2018, especially when an addon author would like to prompt the user to save the variables immediately.
Report comment to moderator  
Reply With Quote
Unread 05/25/19, 10:51 PM  
Rhyono
AddOn Author - Click to view AddOns

Forum posts: 658
File comments: 1276
Uploads: 19
Report comment to moderator  
Reply With Quote
Unread 10/27/18, 12:55 PM  
tomtomhotep
 
tomtomhotep's Avatar
AddOn Author - Click to view AddOns

Forum posts: 21
File comments: 213
Uploads: 6
Originally Posted by SlippyCheeze
Does this now handle the addon auto-save stuff appropriately, with the new release?
What auto-save stuff?
Report comment to moderator  
Reply With Quote
Unread 10/27/18, 10:03 AM  
SlippyCheeze
AddOn Author - Click to view AddOns

Forum posts: 52
File comments: 234
Uploads: 1
Does this now handle the addon auto-save stuff appropriately, with the new release?
Report comment to moderator  
Reply With Quote
Unread 05/05/18, 04:42 PM  
Baertram
 
Baertram's Avatar
AddOn Author - Click to view AddOns

Forum posts: 3287
File comments: 3992
Uploads: 64
Ay, got it. Thanks for the explanation!

Originally Posted by tomtomhotep
Originally Posted by Baertram
I like the idea thanks for the lib.
But I do not really understand how this works, maybe you could explain it a bit more or add more description text to the library's description:

If I just register my addon name to the function
Lua Code:
  1. STD.CriticalChange("your-addon-name")
:

How does it check if something was changed or not within the addon?
And is every change within the savedvars of this addon affected then, or only some?
What's the difference between critical and non-critical changes then?

Thanks for an explanation.

No, wrong concept. The library can't tell when your saved variables change. YOU must tell IT.

You call CriticalChange whenever YOU make whatever YOU consider to be a "major" change of saved variables. (like in FCOIS maybe when user does /fcois backup)

You call NonCriticalChange whenever YOU make whatever YOU consider to be a "minor" change of saved variables.

What you consider major or minor is completely up to you.

The addon then prompts the user according to their settings for LibSaveToDisk.

With default settings, they should be prompted less than 15 seconds after any addon calls CriticalChange, unless the user set a minimum minutes between critical change warnings.

Basically, call CriticalChange if you think the user should reloadui as soon as possible.


"non-critical" (or minor) changes are counted by the library until NonCriticalChange has been called x times (by any and all addons), where x is the user's setting for "Minimum Non-critical Changes" (default 10, slider currently allows 1 to 40). When that count reaches x, the user is prompted to reloadui.



Oh, and if the user clicks "I'll Take My Chances" on the warning window, all counters are reset to 0, but the library is not disabled, i.e. new calls to the library functions still perform the same.
Report comment to moderator  
Reply With Quote
Unread 05/05/18, 02:01 PM  
tomtomhotep
 
tomtomhotep's Avatar
AddOn Author - Click to view AddOns

Forum posts: 21
File comments: 213
Uploads: 6
Originally Posted by Baertram
I like the idea thanks for the lib.
But I do not really understand how this works, maybe you could explain it a bit more or add more description text to the library's description:

If I just register my addon name to the function
Lua Code:
  1. STD.CriticalChange("your-addon-name")
:

How does it check if something was changed or not within the addon?
And is every change within the savedvars of this addon affected then, or only some?
What's the difference between critical and non-critical changes then?

Thanks for an explanation.

No, wrong concept. The library can't tell when your saved variables change. YOU must tell IT.

You call CriticalChange whenever YOU make whatever YOU consider to be a "major" change of saved variables. (like in FCOIS maybe when user does /fcois backup)

You call NonCriticalChange whenever YOU make whatever YOU consider to be a "minor" change of saved variables.

What you consider major or minor is completely up to you.

The addon then prompts the user according to their settings for LibSaveToDisk.

With default settings, they should be prompted less than 15 seconds after any addon calls CriticalChange, unless the user set a minimum minutes between critical change warnings.

Basically, call CriticalChange if you think the user should reloadui as soon as possible.


"non-critical" (or minor) changes are counted by the library until NonCriticalChange has been called x times (by any and all addons), where x is the user's setting for "Minimum Non-critical Changes" (default 10, slider currently allows 1 to 40). When that count reaches x, the user is prompted to reloadui.



Oh, and if the user clicks "I'll Take My Chances" on the warning window, all counters are reset to 0, but the library is not disabled, i.e. new calls to the library functions still perform the same.
Report comment to moderator  
Reply With Quote
Unread 05/05/18, 01:09 PM  
Baertram
 
Baertram's Avatar
AddOn Author - Click to view AddOns

Forum posts: 3287
File comments: 3992
Uploads: 64
I like the idea thanks for the lib.
But I do not really understand how this works, maybe you could explain it a bit more or add more description text to the library's description:

If I just register my addon name to the function
Lua Code:
  1. STD.CriticalChange("your-addon-name")
:

How does it check if something was changed or not within the addon?
And is every change within the savedvars of this addon affected then, or only some?
What's the difference between critical and non-critical changes then?

Thanks for an explanation.
Report comment to moderator  
Reply With Quote
Post A Reply



Category Jump: