Пример #1
0
/*
 *      public void addIdToMetadataQueue(long monitorId, DataRow image) {
 *          this.fileDatabase.addIdToMetadataQueue(monitorId, image);
 *      }
 */
        private void DoWorkImageFolder(object sender, DoWorkEventArgs e)
        {
//            Debug.WriteLine(this.config.getPersistant("folders"));
            BackgroundWorker worker = sender as BackgroundWorker;

            // Lower priority to ensure smooth working of main screensaver
            System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.BelowNormal;
            this.bwSender = sender;
            this.bwEvents = e;
            if (!this.screensaver.readOnly)
            {
                this.swFileScan = new System.Diagnostics.Stopwatch();
                this.swMetadata = new System.Diagnostics.Stopwatch();
                // Folder purge done in main thread
                this.swFileScan.Start();
                this.processFolders();
                this.swFileScan.Stop();
                Debug.WriteLine("FileScan: " + swFileScan.ElapsedMilliseconds + "ms");
                this.swMetadata.Start();
                this.processMetadata();
                this.swMetadata.Stop();
                Debug.WriteLine("Metadata: " + swMetadata.ElapsedMilliseconds + "ms");
            }

            if (!this.backgroundWorker.CancellationPending)
            {
                this.fileDatabase.purgeMetadata();
            }
            //if (Convert.ToDateTime(this.config.setValue("wallpaperLastChange")).Equals(DateTime.Today));
            if (!this.backgroundWorker.CancellationPending)
            {
                Wallpaper wallpaper = new Wallpaper(this.screensaver);
                if (wallpaper.changeWallpaper())
                {
                    switch (this.config.getPersistantString("wallpaperSource"))
                    {
                    case "on":     // Backwards compatability old settings
                    case "current":
                        wallpaper.generateWallpaper();
                        break;

                    case "filter":
                        string sql = this.config.getPersistantString("wallpaperSourceFilterSQL");
                        if (sql != "")
                        {
                            wallpaper.generateWallpaperFromSQL(sql);
                        }
                        break;
                    }
                }
            }

            //this.cancelCompleteEvent.Set();

/*
 *          var command = new SQLiteCommand(conn);
 *          command.CommandText = @"SELECT COUNT(id) FROM `FileNodes`;";
 *          //SQLiteDataReader reader = command.ExecuteReader();
 *          //while (reader.Read()) {
 *          Debug.WriteLine("Rows in DB: " + Convert.ToInt32(command.ExecuteScalar()));
 */
        }
Пример #2
0
        public void PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) {
            // Ignore shortcut keys when Config screen is visible
            // Ignore repeated keys
            if (this.previousKey == e.KeyCode) {
                this.previousKey = 0;
                //Console.WriteLine("PreviousKey:" + e.KeyCode.ToString());
            } else {
                //Console.WriteLine("Key:" + e.KeyCode.ToString());
                if (this.config.ActiveControl != null) Console.WriteLine(this.config.ActiveControl.Name);
                else Console.WriteLine("null");
                if (this.config.Visible && this.config.WindowState != FormWindowState.Minimized) {
                    switch (e.KeyCode) {
                        case Keys.Escape:
                            if (this.config.WindowState == FormWindowState.Minimized) {
                                this.config.WindowState = FormWindowState.Normal;
                            } else {
                                if (this.action == Actions.Config) {
                                    this.config.Config_FormClosing(this, null);
                                    //this.OnExit();
                                } else {
                                    this.configHidden = true;
                                    this.config.Hide();
                                }
                            }
                        break;
                        #if (DEBUG)
                        case Keys.F12:
                            this.config.saveDebug();   
                            MessageBox.Show(this.config.jsonAllPersistant());
                            /*string log = "HTML saved";
                            foreach(string s in this.debugLog) {
                                log += s + Environment.NewLine;
                            }
                            MessageBox.Show(log, "Debug log:");*/
                        break;
                        #endif
                        case Keys.S:
                            if (this.config != Form.ActiveForm) {
                                this.config.Activate();
                            }
                        break;
                    }
                } else {
		            Keys KeyCode = e.KeyCode;
		            // fix German keyboard codes for [ ]
		            if (e.Alt && e.Control) {
			            switch (e.KeyCode) {
				            case Keys.D8: 
                                KeyCode = Keys.OemOpenBrackets;
				            break;
				            case Keys.D9:
					            KeyCode = Keys.OemCloseBrackets;
				            break;
			            }
		            }
                    if (e.Control && KeyCode >= Keys.D0 && KeyCode <= Keys.D5) {
                        // Control + 0 ... 5 set Rating
                        this.stopTimers();
                        int rating = KeyCode - Keys.D0;

                        for (int i = 0; i < this.monitors.Length; i++) {
                            if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                this.monitors[i].rateImage(rating);
                            }
                        }
                        this.fileNodes.resetFilter();
                        this.startTimers();
                    } else switch (KeyCode) {
                        case Keys.Escape:
                            if (!this.configHidden) {
                                this.OnExit();
                            }
                            this.configHidden = false;
                        break;
                        case Keys.A:
                            Utils.RunTaskScheduler(@"OpenUrl", "http://www.abscreensavers.com");                    
                        break;
                        case Keys.B:
                            Utils.RunTaskScheduler(@"OpenUrl", "http://www.abscreensavers.com/random-photo-screensaver/version-information/");
                            //this.monitors[i].showInfoOnMonitor("Opened in Explorer Window", false, true);
                            //Process.Start("http://www.abscreensavers.com");
                        break;
                        case Keys.C:
                            string c;
                            if (!e.Control && this.clipboardReady ) c = Clipboard.GetText();
                            else c = "";
                            for (int i = 0; i < this.monitors.Length; i++) {
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    if (this.monitors[i].imagePath() != null) {
                                        c += this.monitors[i].imagePath() + Environment.NewLine;
                                        if (e.Control) {
                                            c += this.monitors[i].quickMetadata.getAsString() + Environment.NewLine + Environment.NewLine;
                                            this.monitors[i].showInfoOnMonitor("Metadata copied to clipboard");
                                        } else this.monitors[i].showInfoOnMonitor("Image path added to clipboard");
                                    }
                                }
                            }
                            if (c != "") {
                                Clipboard.SetText(c);
                                this.clipboardReady = true;
                            }
                        break;
                        case Keys.E:
                            for (int i = 0; i < this.monitors.Length; i++) {
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    if (this.monitors[i].imagePath() != null) {
                                        if (e.Control) {
                                            if (!File.Exists(Convert.ToString(this.config.getPersistant("externalEditor")))) {
                                                this.monitors[i].showInfoOnMonitor("External editor: '" + this.config.getPersistant("externalEditor") + "' not found.", true, true);
                                            } else {
                                                if (Utils.RunTaskScheduler(@"OpenInEditor" + Convert.ToString(i), Convert.ToString(this.config.getPersistant("externalEditor")), "\"" + this.monitors[i].imagePath() + "\"")) {
                                                    this.monitors[i].showInfoOnMonitor("Opened in external editor", false, true);
                                                }
                                            }
                                        } else {
                                            if (Utils.RunTaskScheduler(@"OpenInExplorer" + Convert.ToString(i), "explorer.exe", "/e,/select,\"" + this.monitors[i].imagePath() + "\"")) { 
                                                this.monitors[i].showInfoOnMonitor("Opened in Explorer Window", false, true);
                                            }
                                        }
                                    }
                                }
                            }
                            if (Convert.ToBoolean(this.config.getPersistantBool("closeAfterImageLocate"))) this.OnExit();
                        break;
                        case Keys.F:
                        case Keys.NumPad7:
                            for (int i = 0; i < this.monitors.Length; i++) {
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    this.config.setPersistant("showFilenameM" + (i + 1), Convert.ToString(this.monitors[i].InvokeScript("toggle", new string[] { "#filename" })));
                                }
                            }
                        break;
                        case Keys.H:
                            for (int i = 0; i < this.monitors.Length; i++) {
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    if (this.monitors[i].imagePath() != null) {
                                        FileAttributes attributes = File.GetAttributes(this.monitors[i].imagePath());
                                        if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden) {
                                            attributes = attributes & ~FileAttributes.Hidden;
                                            this.monitors[i].showInfoOnMonitor("Showing image<br/>(Hidden file attribute cleared)", false, true);
                                        } else {
                                            attributes = attributes | FileAttributes.Hidden;
                                            this.monitors[i].showInfoOnMonitor("Hiding image<br/>(Hidden file attribute set and removed from DB)", false, true);
                                            this.fileNodes.deleteFromDB(this.monitors[i].imagePath());
                                        }
                                        File.SetAttributes(this.monitors[i].imagePath(), attributes);
                                    }
                                }
                            }
                            if (Convert.ToBoolean(this.config.getPersistantBool("closeAfterImageLocate"))) this.OnExit();
                        break;
                        case Keys.I:
                            for (int i = 0; i < this.monitors.Length; i++) {
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    this.monitors[i].browser.Document.InvokeScript("identify");
                                }
                            }
                        break;
                        case Keys.M:
                        case Keys.N:
                            for (int i = 0; i < this.monitors.Length; i++) {
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    this.config.setPersistant("showQuickMetadataM" + (i + 1), Convert.ToString(this.monitors[i].InvokeScript("toggle", new string[] { "#quickMetadata" })));
                                }
                            }
                        break;
                        case Keys.P:
                            for (int i = 0; i < this.monitors.Length; i++) {
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    if (!this.config.syncMonitors() || i == 0) {
                                        this.monitors[i].paused = !this.monitors[i].paused;
                                        this.monitors[i].timer.Enabled = !this.monitors[i].paused;
                                    } else {
                                        this.monitors[i].paused = this.monitors[0].paused;
                                        this.monitors[i].timer.Enabled = !this.monitors[0].paused;
                                    }
                                    if (this.monitors[i].timer.Enabled) this.monitors[i].showInfoOnMonitor("|>");
                                    else this.monitors[i].showInfoOnMonitor("||");
                                }
                            }
                        break;
                        case Keys.R: case Keys.NumPad1:
                            if (this.config.changeOrder() == Config.Order.Random) {
                                this.showInfoOnMonitors("Randomising");
                            } else {
                                int monitor = this.currentMonitor;
                                if (this.currentMonitor == CM_ALL) monitor = 0;
                                if (this.monitors[monitor].currentImage != null) {
                                    this.fileNodes.currentSequentialSeedId = Convert.ToInt32(this.monitors[monitor].currentImage["id"]);
                                }
                                this.showInfoOnMonitors("Sequential");
                            };
                        break;
                        case Keys.S:
                            // Don't hide config screen if application is in Config mode
                            if (this.action != Actions.Config) {
                                if (this.config.Visible && this.config.WindowState != FormWindowState.Minimized)  this.config.Hide();
                                else {
                                    this.config.Activate();
                                    this.config.Show();
                                    this.config.WindowState = FormWindowState.Normal;
                                }
                            }
                        break;
                        case Keys.T: case Keys.NumPad5:
                            for (int i = 0; i < this.monitors.Length; i++) {
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    string display = "true";
                                    string clockType = "current";
                                    switch(Convert.ToString(this.config.getPersistant("clockM" + (i + 1)))) {
                                        case "none":
                                            this.config.setPersistant("currentClockM" + (i + 1), "checked");
                                            clockType = "current";
                                        break;
                                        case "current":
                                            this.config.setPersistant("elapsedClockM" + (i + 1), "checked");
                                            clockType = "elapsed";
                                        break;
                                        case "elapsed":
                                            this.config.setPersistant("noClockM" + (i + 1), "checked");
                                            clockType = "none";
                                            display = "false";
                                        break;
                                    }
                                    this.config.setPersistant("clockM" + (i + 1), clockType);
                                    this.monitors[i].InvokeScript("setClockType", new string[] { clockType  });
                                    this.monitors[i].InvokeScript("toggle", new string[] { "#clock", display });
                                    this.monitors[i].InvokeScript("setClockFormat", new string[] { this.config.getPersistantString("clockFormatM" + (i + 1)) });
                                }
                            }
                        break;
                        case Keys.U:
                            string updateFilename = this.config.updateFilename();
                            if (updateFilename == null) {
                                this.showUpdateStatus = true;
                                this.showInfoOnMonitors("Checking for updates.", true, true);
                                this.config.timerCheckUpdates_Tick(this, null);
                            } else {
                                if (e.Control) {
                                    string update = this.config.getUpdateVersion();
                                    if (update != null) {
                                        this.config.setPersistant("ignoreVersion", update);
                                        this.config.setPersistant("ignoreUpdate", Convert.ToString(true));
                                        this.hideUpdateInfo();
                                        this.showInfoOnMonitors("Update " + update + " will be ignored.", true, true);
                                    }
                                } else {
                                    switch (this.config.isUpdateNewer()) { 
                                        case true:
                                            this.showInfoOnMonitors("Activating update", true, true);
                                            if (File.Exists(updateFilename) && Utils.VerifyMD5(updateFilename, this.config.updateFileMD5())) {
                                                // Keep call to explorer.exe otherwise update won't start!
                                                Utils.RunTaskScheduler(@"Run", "explorer.exe", updateFilename);
                                            } else {
                                                Utils.RunTaskScheduler(@"Run", "explorer.exe", this.config.updateDownloadUrl());
                                            }
                                            this.OnExit();
                                        break;
                                        case false:
                                            this.showAllUpToDate();
                                        break;
                                        case null:
                                        break;
                                    }
                                }
                            }
                        break;
                        case Keys.W:
                            string[] paths = new string[this.monitors.Length];
                            for (int i = 0; i < this.monitors.Length; i++) {
                                paths[i] = Convert.ToString(this.monitors[i].imagePath());
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    this.monitors[i].showInfoOnMonitor("Setting as wallpaper");
                                }
                            }
                            Wallpaper wallpaper = new Wallpaper(this);
                            wallpaper.generateWallpaper(this.currentMonitor, paths);
                        break;
                        case Keys.X:
                            this.hideUpdateInfo();
                        break;
                        case Keys.D0:
                            this.currentMonitor = CM_ALL;
                            for (int i = 0; i < this.monitors.Length; i++) {
                                this.monitors[i].browser.Document.InvokeScript("identify");
                                this.monitors[i].showInfoOnMonitor("Offset (" + this.monitors[i].offset + ")");
                            }
                            break;
                        case Keys.D1:case Keys.D2:case Keys.D3:
                        case Keys.D4:case Keys.D5:case Keys.D6:
                        case Keys.D7:case Keys.D8:case Keys.D9:
                            int monitorId = e.KeyValue-49;
                            if (monitorId < this.monitors.Length) {
                                this.currentMonitor = monitorId;
                                this.monitors[monitorId].browser.Document.InvokeScript("identify");
                                this.monitors[monitorId].showInfoOnMonitor("Offset (" + this.monitors[monitorId].offset + ")");
                            }
                        break;
                        case Keys.NumPad4: case Keys.Left:
                            this.actionPrevious(this.getStep(e));
                        break;
                        case Keys.NumPad6: case Keys.Right:
                            this.actionNext(this.getStep(e));
                        break;
                        case Keys.NumPad2: case Keys.Down:
                            this.stopTimers();
                            for (int i = 0; i < this.monitors.Length; i++) {
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    this.monitors[i].timer.Stop();
                                    this.monitors[i].offsetImage(this.getStep(e));
                                    this.monitors[i].showImage(this.config.getPersistantBool("useTransitionsOnInput"));
                                    this.monitors[i].showInfoOnMonitor("v (" + this.monitors[i].offset + ")");
                                    this.monitors[i].startTimer();
                                }
                            }
                            this.startTimers();
                        break;
                        case Keys.NumPad8: case Keys.Up:
                            this.stopTimers();
                            for (int i = 0; i < this.monitors.Length; i++) {
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    this.monitors[i].timer.Stop();
                                    this.monitors[i].offsetImage(this.getStep(e)*-1);
                                    this.monitors[i].showImage(this.config.getPersistantBool("useTransitionsOnInput"));
                                    this.monitors[i].showInfoOnMonitor("^ (" + this.monitors[i].offset + ")");
                                    this.monitors[i].startTimer();
                                }
                            }
                            this.startTimers();
                        break;
                        case Keys.F2:
                        for (int i = 0; i < this.monitors.Length; i++) {
                            if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                this.monitors[i].renameFile();
                            }
                        }
                        break;
                        case Keys.F12:
                            for (int i = 0; i < this.monitors.Length; i++) {
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    string path = this.monitors[i].saveDebug();
                                    if (e.Control) {
                                        if (Utils.RunTaskScheduler(@"OpenInExplorer" + Convert.ToString(i), "explorer.exe", "/e,/select,\"" + path + "\"")) {
                                            this.monitors[i].showInfoOnMonitor("Opened in Explorer Window", false, true);
                                        }
                                    }
                                }
                            }
                        break;
                        case Keys.OemOpenBrackets:
                        case Keys.OemCloseBrackets: 
                        case Keys.Oemplus:
                            this.stopTimers();
                            int deg = 0;
                            string message = "";
                            switch (KeyCode) {
                                case Keys.OemOpenBrackets: 
                                    deg = 270;
                                    message = "Rotating 270° clock wise";
                                break;
                                case Keys.OemCloseBrackets: 
                                    deg = 90;
                                    message = "Rotating 90° clock wise";
                                break;
                                case Keys.Oemplus: 
                                    deg = 180;
                                    message = "Upside down you're turning me";
                                break;
                            }

                            for (int i = 0; i < this.monitors.Length; i++) {
                                if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                    this.monitors[i].info = message;
                                    this.monitors[i].showInfoOnMonitor(message, true, true);
                                    this.monitors[i].rotateImage(deg);
                                }
                            }
                            //this.fileNodes.toggleMetadataTransaction();
                            this.fileNodes.resetFilter();
                            this.startTimers();
                        break;
                        case Keys.Delete:
                        if (this.config.getPersistantBool("deleteKey")) {
                                this.pauseAll(false);
                                for (int i = 0; i < this.monitors.Length; i++) {
                                    if (this.currentMonitor == CM_ALL || this.currentMonitor == i) {
                                        bool deleteFile = true;
                                        string filename = this.monitors[i].imagePath();
                                        if (filename != null && filename.Length > 0 && File.Exists(filename)) {
                                            Cursor.Show();
                                            this.monitors[i].Focus();
                                            if (DialogResult.Yes == MessageBox.Show("Are you sure you want to delete '" + Path.GetFileName(filename) + "'?", "Confirm File Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)) {
                                                deleteFile = true;
                                            } else {
                                                deleteFile = false;
                                            }
                                            Cursor.Hide();
                                            if (deleteFile) {
                                                BackgroundWorker bgwDeleteFile = new BackgroundWorker();
                                                bgwDeleteFile.DoWork += new DoWorkEventHandler(DoWorkDeleteFile);
                                                bgwDeleteFile.RunWorkerAsync(new Object[] {i, filename});
                                            }
                                        }
                                    }
                                }
                                this.resumeAll(false);
                            }
                        break;
                        default:
        		            if (!e.Alt && !e.Control && !e.Shift) {
                                if (!this.config.getPersistantBool("onlyEscapeExits")) {
                                    this.OnExit();
                                }
                            }
                        break;
                    }
                    this.previousKey = e.KeyCode;
                }
            } 
        }
 public bool resetWallpaper()
 {
     Wallpaper wallpaper = new Wallpaper(this.screensaver);
     wallpaper.resetDefaultWallpaper();
     return true;
 }
        /*
        public void addIdToMetadataQueue(long monitorId, DataRow image) {
            this.fileDatabase.addIdToMetadataQueue(monitorId, image);
        }
        */
        private void DoWorkImageFolder(object sender, DoWorkEventArgs e)
        {
            //            Debug.WriteLine(this.config.getPersistant("folders"));
            BackgroundWorker worker = sender as BackgroundWorker;
            // Lower priority to ensure smooth working of main screensaver
            System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.BelowNormal;
            this.bwSender = sender;
            this.bwEvents = e;
            if (!this.screensaver.readOnly) {
                this.swFileScan = new System.Diagnostics.Stopwatch();
                this.swMetadata = new System.Diagnostics.Stopwatch();
                // Folder purge done in main thread
                this.swFileScan.Start();
                this.processFolders();
                this.swFileScan.Stop();
                Debug.WriteLine("FileScan: " + swFileScan.ElapsedMilliseconds + "ms");
                this.swMetadata.Start();
                this.processMetadata();
                this.swMetadata.Stop();
                Debug.WriteLine("Metadata: " + swMetadata.ElapsedMilliseconds + "ms");
            }

            if (!this.backgroundWorker.CancellationPending) this.fileDatabase.purgeMetadata();
            //if (Convert.ToDateTime(this.config.setValue("wallpaperLastChange")).Equals(DateTime.Today));
            if (!this.backgroundWorker.CancellationPending) {

                Wallpaper wallpaper = new Wallpaper(this.screensaver);
                if (wallpaper.changeWallpaper()) {
                    switch (this.config.getPersistantString("wallpaperSource")) {
                        case "on": // Backwards compatability old settings
                        case "current":
                            wallpaper.generateWallpaper();
                        break;
                        case "filter":
                            string sql = this.config.getPersistantString("wallpaperSourceFilterSQL");
                            if (sql != "") wallpaper.generateWallpaperFromSQL(sql);
                        break;
                    }
                }
            }

            //this.cancelCompleteEvent.Set();

            /*
            var command = new SQLiteCommand(conn);
            command.CommandText = @"SELECT COUNT(id) FROM `FileNodes`;";
            //SQLiteDataReader reader = command.ExecuteReader();
            //while (reader.Read()) {
            Debug.WriteLine("Rows in DB: " + Convert.ToInt32(command.ExecuteScalar()));
            */
        }
 public void ConfigDocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
 {
     if (this.screensaver.action == Screensaver.Actions.Wallpaper) {
         this.screensaver.initForScreensaverAndWallpaper();
         Wallpaper wallpaper = new Wallpaper(this.screensaver);
         wallpaper.generateWallpaper();
         Application.Exit();
     } else {
         this.screensaver.initializeMonitors();
         if (!this.configInitialised) {
             this.setInnerHTML("version", Constants.getNiceVersion());
             this.setInnerHTML("versionIE", "(IE:" + this.browser.Version.Major.ToString() + "." + this.browser.Version.Minor.ToString() + ")");
             this.browser.Document.InvokeScript("initFancyTreeFolder");
             this.browser.Document.InvokeScript("initFancyTreeTransitions");
             this.configInitialised = true;
         }
     }
 }