public jsonFolder mergeChildren(jsonFolder folder)
 {
     return this.mergeChildren(folder, false);
 }
 public jsonFolder mergeChildren(jsonFolder folder, bool overwrite)
 {
     for (int i = 0; i < folder.children.Count; i++) {
         jsonFolder child = this.hasChild(folder.children[i].key);
         if (child != null) {
             if (overwrite) child = folder.children[i];
         } else {
             this.children.Add(folder.children[i]);
         }
     }
     return this;
 }
Ejemplo n.º 3
0
        public void loadPersistantConfig(int nrMonitors)
        {
            #if (DEBUG)
                this.screensaver.debugLog.Add("loadPersistantConfig(" + nrMonitors + ")");
            #endif

            //SQLiteConnection connection =
            this.connectToDB();
            this.persistant = new Dictionary<string, object>();

            DataContext context = new DataContext(this.dbConnector.connection);
            var items = context.GetTable<Setting>();
            foreach(Setting item in items) {
                this.persistant.Add(item.Key, item.Value);
            }
            if (!this.persistant.ContainsKey("filterNrLines")) this.persistant["filterNrLines"] = 0;

            object regvalue = Registry.GetValue("HKEY_CURRENT_USER\\" + Constants.regkeyGPURendering, Constants.regkeyExecutable, 0);
            bool gpuRendering = (regvalue != null && (int)regvalue == 1);
            if (this.persistant.ContainsKey("gpuRendering")) this.persistant["gpuRendering"] = gpuRendering;
            else this.persistant.Add("gpuRendering", gpuRendering);

            //this.browser.Document.InvokeScript("initMonitorsAndFilterCount", new string[] { Convert.ToString(Screen.AllScreens.Length), Convert.ToString(this.persistant["filterNrLines"]) });
            this.browser.Document.InvokeScript("initMonitors", new string[] { Convert.ToString(Screen.AllScreens.Length) });

            if (!this.persistant.ContainsKey("folders") || this.persistant["folders"] == null || this.getPersistantString("folders").Trim().Length == 0) {
                string path = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + Environment.NewLine +
                                                        Environment.GetFolderPath(Environment.SpecialFolder.MyVideos);
                if (!this.persistant.ContainsKey("folders")) {
                    this.persistant.Add("folders", path);
                } else {
                    this.persistant["folders"] = path;
                }
            }

            if (!this.persistant.ContainsKey("rawFolder") || this.persistant["rawFolder"] == null || Convert.ToString(this.persistant["rawFolder"]).Trim().Length == 0) {
                string path = Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                    Constants.AppName,
                    Constants.RawCacheFolder
                );

                if (!this.persistant.ContainsKey("rawFolder")) {
                    this.persistant.Add("rawFolder", path);
                } else {
                    this.persistant["rawFolder"] = path;
                }
            }

            if (this.persistant.ContainsKey("effects") && this.persistant["effects"] != null && Convert.ToString(this.persistant["effects"]) != "null" && Convert.ToString(this.persistant["effects"]).Trim().Length > 0) {
                this.effects = JsonConvert.DeserializeObject<jsonFolder>(Convert.ToString(this.persistant["effects"]));
            } else {
                this.effects = new jsonFolder();
            }
            string jsonPath = Constants.getDataFolder(Constants.EffectsJsonFile);
            if (File.Exists(jsonPath)) {
                //this.effects = new jsonFolder();
                JsonSerializer serializer = new JsonSerializer();
                serializer.NullValueHandling = NullValueHandling.Ignore;
                using (StreamReader sr = new StreamReader(jsonPath))
                using (JsonReader reader = new JsonTextReader(sr)) {
                    jsonFolder newEffects = serializer.Deserialize<jsonFolder>(reader);
                    this.effects.mergeChildren(newEffects);
                }
            }

            HtmlElementCollection hec = this.GetElementsByTagName("input");
            foreach (HtmlElement e in hec) {
                if (this.persistant.ContainsKey(e.GetAttribute("id")) || (e.GetAttribute("type") == "radio" && this.persistant.ContainsKey(e.GetAttribute("name")))) {
                    switch (e.GetAttribute("type")) {
                        case "checkbox":
                            if (this.getPersistantBool(e.GetAttribute("id")) == true) {
                                e.SetAttribute("checked", "true");
                            } else {
                                e.SetAttribute("checked", "");
                            }
                            break;
                        case "radio":
                            if (this.getPersistantString(e.GetAttribute("name")) == e.GetAttribute("value")) {
                                e.SetAttribute("checked", "true");
                            }
                            break;
                        default:
                            e.SetAttribute("value", this.getPersistantString(e.GetAttribute("id")));
                            break;
                    }
                } else {
                    switch (e.GetAttribute("type")) {
                        case "checkbox":
                            this.persistant[e.GetAttribute("id")] =  this.getDomCheckboxValue(e.GetAttribute("id"));
                        break;
                        case "radio":
                            this.persistant[e.GetAttribute("name")] =  this.getDomRadioValue(e.GetAttribute("name"));
                        break;
                        default:
                            this.persistant[e.GetAttribute("id")] =  this.getDomValue(e.GetAttribute("id"));
                        break;
                    }

                    // Set persistant value with default
                }
            }

            hec = this.browser.Document.GetElementsByTagName("textarea");
            foreach (HtmlElement e in hec) {
                if (this.persistant.ContainsKey(e.GetAttribute("id"))) {
                    e.SetAttribute("value", Utils.HtmlDecode(Convert.ToString(this.persistant[e.GetAttribute("id")])));
                } else {
                    this.persistant[e.GetAttribute("id")] = Utils.HtmlDecode(this.getDomValue(e.GetAttribute("id")));
                }
            }

            hec = this.browser.Document.GetElementsByTagName("select");
            foreach (HtmlElement e in hec) {
                if (this.persistant.ContainsKey(e.GetAttribute("id"))) {
                    e.SetAttribute("value", Convert.ToString(this.persistant[e.GetAttribute("id")]));
                } else {
                    this.persistant[e.GetAttribute("id")] = this.getDomValue(e.GetAttribute("id"));
                }
            }

            string classes = null;
            if (nrMonitors > 1) classes += " multi ";
            Config.setBrowserBodyClasses(this.browser, this.screensaver.action, classes);

            this.browser.Document.InvokeScript("persistantConfigLoaded", new string[] { Convert.ToString(Screen.AllScreens.Length) });

            if (this.screensaver.action == Screensaver.Actions.Preview && this.screensaver.monitors != null) {
                this.screensaver.monitors[0].defaultShowHide();
            }
        }
Ejemplo n.º 4
0
 public void jsSetSelectedEffects(string jsonEffects)
 {
     this.effects = JsonConvert.DeserializeObject<jsonFolder>(jsonEffects);
     this.persistant["effects"] = jsonEffects;
 }
Ejemplo n.º 5
0
        /****
         * Called from config.js
         * dumdum variable is used to avoid calling the function when testing with
         * if (typeof(window.external.getInitialFoldersJSON) !== "undefined") in JavaScript
         ****/
        public string getInitialFoldersJSON(bool dumdum)
        {
            List<jsonFolder> folders = new List<jsonFolder>();
            //MessageBox.Show("getInitialFoldersJSON()");
            //            folders.Add(new jsonFolder());
            //          folders.Add(new jsonFolder(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos)));
            /*
                        jsonFolder network = new jsonFolder("Network");
                        network.key = "\\";
                        folders.Add(network);
                        DirectoryEntry root = new DirectoryEntry("WinNT:");
                        foreach (DirectoryEntry networkComputers in root.Children) {
                            foreach (DirectoryEntry networkComputer in networkComputers.Children) {
                                if (networkComputer.Name != "Schema") {
                                    jsonFolder networked = new jsonFolder(networkComputer.Name);
                                    networked.lazy = true;
                                    network.children.Add(networked);

                                    try {
                                        ManagementObjectSearcher searcher =
                                            new ManagementObjectSearcher("root\\CIMV2",
                                            "SELECT * FROM Win32_Share");

                                        foreach (ManagementObject queryObj in searcher.Get()) {
                                            Debug.WriteLine("-----------------------------------");
                                            Debug.WriteLine("Win32_Share instance");
                                            Debug.WriteLine("-----------------------------------");
                                            Debug.WriteLine("Name: {0}", queryObj["Name"]);
                                        }
                                    } catch (ManagementException e) {
                                        MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
                                    }
                                    //textBox1.Text += computer.Name + "\r\n";
                                }
                            }
                        }
                        */
            jsonFolder computer = new jsonFolder("Computer");
            computer.expanded = true;
            folders.Add(computer);
            DriveInfo[] info = DriveInfo.GetDrives();

            foreach (DriveInfo di in info) {
                string drive = "(" + di.Name.Replace("\\", "") + ")";
                jsonFolder f = new jsonFolder(drive);
                f.lazy = true;
                f.key = di.Name;

                string extraInfo = "";
                if (di.IsReady) {
                    extraInfo += di.VolumeLabel + " ";
                } else {
                    f.unselectable = true;
                    f.extraClasses = "dim";
                }
                switch (di.DriveType) {
                    case DriveType.Removable:
                        if (extraInfo == "") extraInfo += "Removable Disk ";
                        break;
                }
                if (extraInfo != "") f.title = extraInfo + f.title;
                computer.children.Add(f);
            }

            if (this.persistant == null || this.getPersistant("folders") == null) {
                this.loadPersistantConfig();
            }

            foreach (string folder in Convert.ToString(this.getPersistant("folders")).Split(new string[] { Environment.NewLine, "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries)) {
                if (folder.Substring(0, 2) == "\\\\") {
                    string[] parts = folder.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);
                    int i = 0;
                    jsonFolder network = new jsonFolder("Network");
                    folders.Add(network);
                    jsonFolder node = network;
                    while (i < parts.Length) {
                        jsonFolder newNode = new jsonFolder(parts[i]);
                        node.children.Add(newNode);
                        i++;
                        if (i == parts.Length) {
                            newNode.selected = true;
                            jsonFolder dummy = new jsonFolder("dummy");
                            dummy.selected = false;
                            //dummy.unselectable = false;
                            dummy.extraClasses = "hidden";
                            node.children.Add(dummy);
                        }
                        node = newNode;
                    }
                } else {
                    jsonFolder node = computer;
                    string basePath = "";
                    string[] parts = folder.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);

                    int i = 0;
                    while (i < parts.Length) {
                        string key = parts[i].ToLower();
                        if (key.IndexOf(':') > -1) key = key.ToUpper() + "\\";
                        jsonFolder newNode = node.hasChild(key);

                        if (newNode == null) {
                            // Add children if not found
                            node.children.AddRange(this.getFolder(basePath));
                            node = node.hasChild(key);
                            if (node == null) break; // Escape while loop if still not found
                        } else {
                            node = newNode;
                        }
                        //node.expanded = true;
                        node.selected = true;
                        basePath += parts[i] + "\\";
                        i++;
                    }
                    if (node != null) node.selected = true;
                }
            }
            return JsonConvert.SerializeObject(folders);
        }
Ejemplo n.º 6
0
 public List<jsonFolder> getFolder(string folder)
 {
     List<jsonFolder> children = new List<jsonFolder>();
     if (!Directory.Exists(folder)) return children;
     string[] dirs = Directory.GetDirectories(folder);
     foreach (string dir in dirs) {
         try {
             FileInfo fi = new FileInfo(dir);
             if ((fi.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) {
                 jsonFolder d = new jsonFolder(fi.Name.ToLower());
                 d.lazy = (Directory.GetDirectories(dir).Length > 0);
                 children.Add(d);
             }
         } catch (Exception e) {
             Debug.WriteLine("getFolder " + e.Message);
             // No access
         }
     }
     return children;
 }
 public jsonFolder mergeChildren(jsonFolder folder)
 {
     return(this.mergeChildren(folder, false));
 }