summaryrefslogtreecommitdiff
path: root/VRCSDK3Avatars/Assets/Resources/RalivDynamicPenetrationSystem/Plugins/Xiexes-Unity-Shaders-development/Editor/XSUpdater.cs
blob: 0d9d6dd5757d4b7447346e2ce4439fd32f5da3b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
using UnityEngine;
using UnityEngine.Networking;
using UnityEditor;
using System.Collections.Generic;
using System.IO;
namespace XSToonDynamicPenetration
{
    public class XSUpdater : EditorWindow
    {
        [MenuItem("Tools/Xiexe/XSToon/About - Updater")]
        // Use this for initialization
        static public void Init()
        {
            XSUpdater window = EditorWindow.GetWindow<XSUpdater>(true, "XSToon: Docs & Updater", true);
            window.minSize = new Vector2(400, 300);
            window.maxSize = new Vector2(401, 501);
        }

        private static string[] patrons = {};
        private static string path;
        
        static int tab = 0;
        static string updateUrl = "https://api.github.com/repos/Xiexe/Xiexes-Unity-Shaders/releases/latest";
        static string docsURL = "https://docs.google.com/document/d/1xJ4PID_nwqVm_UCsO2c2gEdiEoWoCGeM_GDK_L8-aZE";
        static string patronsURL = "https://raw.githubusercontent.com/Xiexe/thefoxden/master/assets/patronlist/patronlist.txt";
        
        static UnityWebRequest www;
        static string changelog;
        static string publishdate;
        static string curVer;
        static string downloadLink;
        bool hasCalledPatronlist = false;
        static bool showInfo = false;
        Vector2 scrollPos;

        public void OnGUI()
        {
            tab = GUILayout.Toolbar (tab, new string[] {"Documentation", "Updater", "Social"});
             XSStyles.SeparatorThin();
                switch(tab) {
                    case 0:
                        //show Docs from git
                        XSStyles.doLabel("You can find Documentation here.");
                        if(GUILayout.Button("Open Documentation"))
                            Application.OpenURL(docsURL);
        
                    break;

                    case 1: 
                        EditorGUI.BeginChangeCheck();
                            
                            XSStyles.HelpBox("The currently installed version is: v" + XSStyles.ver + "\n\nTo check for updates, use the update button. If you choose to download an update, you will need to manually overwrite the old install by extracting the .zip into the project using the windows explorer. \n\nDo not drag the update directly into Unity - it won't ask to overwrite - it'll just create a duplicate and break.", MessageType.Info);
                            XSStyles.SeparatorThin();
                            if (GUILayout.Button("Check for Updates"))
                            {
                                req(updateUrl);
                                EditorApplication.update += changelogEditorUpdate;
                                showInfo = true;
                            }

                            if(showInfo){
                            
                                scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
                                    Repaint();
                                    XSStyles.doLabelLeft("Newest version: ");
                                    XSStyles.doLabelSmall(curVer);
                                    XSStyles.SeparatorThin();
                                    
                                    XSStyles.doLabelLeft("Release Date: ");
                                    XSStyles.doLabelSmall(publishdate);
                                    XSStyles.SeparatorThin();
                                    
                                    XSStyles.doLabelLeft("Changelog: ");
                                    XSStyles.doLabelSmall(changelog);
                                    
                                EditorGUILayout.EndScrollView();
                                XSStyles.SeparatorThin();
                                if (GUILayout.Button("Download")){
                                    Application.OpenURL(downloadLink);
                                }
                            
                            }
                            else{
                                XSStyles.doLabel("Hit 'Check for Updates' to begin");
                            }
                        EditorGUI.EndChangeCheck();
                       
                    break;

                    case 2:
                        //show Patrons

                        XSStyles.doLabel("Thank you to my patreon supporters, and the people who have helped me along the way, you guys are great!\n Note: You must be in the Discord server to show on this list.");
                        XSStyles.SeparatorThin();
                        XSStyles.doLabel("Current Patrons");
                        XSStyles.SeparatorThin();
                        scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
                        if(!hasCalledPatronlist)
                        {      
                            hasCalledPatronlist = true; 
                            req(patronsURL);
                            EditorApplication.update += EditorUpdate;
                        }
                        for(int i = 0; i < patrons.Length; i++)
                        {
                            XSStyles.doLabel(" - " + patrons[i]);
                        }
                        EditorGUILayout.EndScrollView();

                        XSStyles.SeparatorThin();
                        //show social links
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.FlexibleSpace();
                            XSStyles.discordButton(70, 30);
                            XSStyles.patreonButton(70, 30);
                            XSStyles.githubButton(70, 30);
                        GUILayout.FlexibleSpace();
                        EditorGUILayout.EndHorizontal();
                    break;
                }
            
           
        }

        static void req(string url)
        {
            www = UnityWebRequest.Get(url);
            www.SendWebRequest();
            //Debug.Log("Checking for updates...");
        }
        static void EditorUpdate()
        {
            while (!www.isDone)
                return;

            if (www.isNetworkError)
                Debug.Log(www.error);
            else
            {
               patrons = www.downloadHandler.text.Split('\n');
               Debug.Log("Fetching Patron list of: " + patrons.Length);
            }       
            EditorApplication.update -= EditorUpdate;
        }

        static void updateHandler(string apiResult)
        {
            gitAPI git = JsonUtility.FromJson<gitAPI>(apiResult);
                bool option = EditorUtility.DisplayDialog("XSToon: Updater",
                                            "You are on version: \nv" + XSStyles.ver + "\n\nThe latest version is: \n" + git.tag_name + "\n\n You can view the changelog either on my Discord, or at the Github page for this release." + "\n\nWould you like to update?",
                                            "Download", "Cancel");

                switch (option)
                {
                    case true:
                        Application.OpenURL(git.zipball_url);
                        break;

                    case false:
                        Debug.Log("Cancelled Update.");
                        break;
                }
          //  Debug.Log(apiResult);
        }

        static void changelogEditorUpdate()
        {
            while (!www.isDone)
                return;

            if (www.isNetworkError)
                Debug.Log(www.error);
            else
                fetchChangelog(www.downloadHandler.text);
                
            EditorApplication.update -= changelogEditorUpdate;
        }

        static void fetchChangelog(string apiResult)
        {
            gitAPI git = JsonUtility.FromJson<gitAPI>(apiResult);
            
            publishdate = git.published_at;
            curVer = git.tag_name;
            changelog = git.body;
            downloadLink = git.zipball_url;
            //oldChangelog = 
               
               // Debug.Log(git.body);
               // Debug.Log(apiResult);
                // Debug.Log(git.tag_name);
                // Debug.Log(git.html_url);
                // Debug.Log(git.published_at);
                // Debug.Log(git.zipball_url);
                // Debug.Log(git.body);
               
        }

        public class gitAPI
        {
            public string name;
            public string tag_name;
            public string html_url;
            public string published_at;
            public string zipball_url;
            public string body;
        }

    }
}