public static void Save(this PrinterSettings settings, string filePath, bool userDrivenChange = true)
        {
            // TODO: Rewrite to be owned by ProfileManager and simply mark as dirty and every n period persist and clear dirty flags
            lock (writeLock)
            {
                string json = settings.ToJson();

                var printerInfo = ProfileManager.Instance[settings.ID];
                if (printerInfo != null)
                {
                    printerInfo.ContentSHA1 = settings.ComputeSHA1(json);

                    if (printerInfo.ServerSHA1 == printerInfo.ContentSHA1)
                    {
                        // Any change that results in our content arriving at the last known server content fingerprint, should clear the dirty flag
                        printerInfo.IsDirty = false;
                    }
                    else
                    {
                        printerInfo.IsDirty |= userDrivenChange;
                    }

                    ProfileManager.Instance.Save();
                }

                File.WriteAllText(filePath, json);
            }

            if (ApplicationController.Instance.ActivePrinters.FirstOrDefault(p => p.Settings.ID == settings.ID) is PrinterConfig printer)
            {
                ApplicationController.Instance.ActiveProfileModified.CallEvents(printer.Settings, null);
            }
        }
Esempio n. 2
0
        public static void Save(this PrinterSettings settings, string filePath)
        {
            // TODO: Rewrite to be owned by ProfileManager and simply mark as dirty and every n period persist and clear dirty flags
            lock (writeLock)
            {
                string json = settings.ToJson();

                var printerInfo = ProfileManager.Instance[settings.ID];
                if (printerInfo != null)
                {
                    printerInfo.ContentSHA1 = settings.ComputeSHA1(json);
                    ProfileManager.Instance.Save();
                }

                File.WriteAllText(filePath, json);
            }

            if (ApplicationController.Instance.ActivePrinters.FirstOrDefault(p => p.Settings.ID == settings.ID) is PrinterConfig printer)
            {
                ApplicationController.Instance.ActiveProfileModified.CallEvents(printer.Settings, null);
            }
        }