private static void Load() { #if !FORCE_INVOICE try { string oldPath = Path.Combine(Application.persistentDataPath, Path.Combine(NGLicensesManager.intermediatePath, NGLicensesManager.LicensesPath)); string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Path.Combine(NGLicensesManager.intermediatePath, NGLicensesManager.LicensesPath)); if (File.Exists(oldPath) == true) { try { Directory.CreateDirectory(Path.GetDirectoryName(path)); File.Move(oldPath, path); } catch { if (File.Exists(path) == false) { path = oldPath; } } } if (File.Exists(path) == true) { string rawContent = File.ReadAllText(path).Substring(1); byte[] b = Convert.FromBase64String(rawContent); rawContent = Encoding.ASCII.GetString(b); string[] content = rawContent.Split('\n'); for (int i = 0; i + 3 < content.Length; i += 4) { License l = new License() { invoice = content[i], assetName = content[i + 1], status = (Status)int.Parse(content[i + 2]), active = content[i + 3] == "true" ? true : false, }; NGLicensesManager.invoices.Add(l); } if ((DateTime.Now - File.GetLastWriteTime(path)).TotalMinutes < NGLicensesManager.MinimumMinutesBeforeInvoicesUpdate) { return; } List <string> invoices = new List <string>(); for (int i = 0; i < NGLicensesManager.invoices.Count; i++) { if (NGLicensesManager.invoices[i].active == true) { invoices.Add(NGLicensesManager.invoices[i].invoice); } } File.SetLastWriteTime(path, DateTime.Now); NGLicensesManager.VerifyActiveLicenses(invoices.ToArray()); } } catch { NGLicensesManager.invoices.Clear(); } finally { if (NGLicensesManager.LicensesLoaded != null) { NGLicensesManager.LicensesLoaded(); } } #else NGLicensesManager.invoices.Add(new License() { active = true, assetName = "NG Tools Pro", invoice = "3181282670", status = 0 }); NGLicensesManager.VerifyLicenses(NGLicensesManager.invoices[0].invoice); if (NGLicensesManager.LicensesLoaded != null) { NGLicensesManager.LicensesLoaded(); } #endif }
public static void RevokeSeat(string invoice, string deviceName, string userName, Action <string, string, string> onCompleted) { StringBuilder buffer = Utility.GetBuffer(NGLicensesManager.ServerEndPoint + "revoke_seats.php?i="); buffer.Append(invoice); buffer.Append("&dn="); buffer.Append(SystemInfo.deviceName); buffer.Append("&un="); buffer.Append(Environment.UserName); buffer.Append("&sdn[]="); buffer.Append(deviceName); buffer.Append("&sun[]="); buffer.Append(userName); NGLicensesManager.RequestServer(Utility.ReturnBuffer(buffer), (error, result) => { if (error == false) { if (result == "1") { EditorApplication.delayCall += () => { lock (NGLicensesManager.invoices) { License license = NGLicensesManager.invoices.Find(l => l.invoice == invoice); if (license != null) { license.active = false; license.status = 0; NGLicensesManager.SaveLicenses(); } } onCompleted(invoice, deviceName, userName); InternalEditorUtility.RepaintAllViews(); EditorUtility.DisplayDialog(NGLicensesManager.Title, "Seat \"" + deviceName + " " + userName + "\" revoked.", "OK"); }; } else { string message; if (result == "0") // Not using { message = "The server could not revoke the seat \"" + deviceName + " " + userName + "\". Please contact the author."; } else { message = "Server has encountered an issue. Please contact the author."; } EditorApplication.delayCall += () => { EditorUtility.DisplayDialog(NGLicensesManager.Title, message, "OK"); }; } } else { EditorApplication.delayCall += () => { EditorUtility.DisplayDialog(NGLicensesManager.Title, "Request has failed.", "OK"); }; } }, invoice); }