Пример #1
0
        internal static int MoveFilesToTemp(params string[] files)
        {
            // 0 = success
            // -1 = aborted by user
            // other value = error

            string from = string.Empty;

            foreach (string file in files)
            {
                from += file + "\0";
            }
            from += "\0";

            string sTemp = PluginUpdateHandler.GetTempFolder() + "\0\0";

            SHFILEOPSTRUCT lpFileOp = new SHFILEOPSTRUCT();

            lpFileOp.hwnd   = IntPtr.Zero;
            lpFileOp.wFunc  = FILE_OP_TYPE.FO_MOVE;
            lpFileOp.pFrom  = from;
            lpFileOp.pTo    = sTemp;
            lpFileOp.fFlags = FILE_OP_FLAGS.FOF_NOCONFIRMMKDIR | FILE_OP_FLAGS.FOF_NOCONFIRMATION | FILE_OP_FLAGS.FOF_ALLOWUNDO;
            lpFileOp.fAnyOperationsAborted = false;
            lpFileOp.hNameMappings         = IntPtr.Zero;
            lpFileOp.lpszProgressTitle     = string.Empty;

            int result = SHFileOperation(ref lpFileOp);

            if (result == 0 && lpFileOp.fAnyOperationsAborted)
            {
                result = -1;
            }
            PluginDebug.AddInfo("Move in UAC mode: " + result.ToString());
            return(result);
        }
Пример #2
0
        private void UpdatePlugins(bool bUpdateTranslationsOnly)
        {
            PluginDebug.AddInfo("UpdatePlugins start ", DebugPrint);
            Form fUpdateLog = null;

            m_slUpdatePlugins = StatusUtil.CreateStatusDialog(GlobalWindowManager.TopWindow, out fUpdateLog, PluginTranslate.PluginUpdateCaption, string.Empty, true, true);

            bool   success            = false;
            string sTempPluginsFolder = PluginUpdateHandler.GetTempFolder();

            ThreadStart ts = new ThreadStart(() =>
            {
                m_slUpdatePlugins.StartLogging(PluginTranslate.PluginUpdateCaption, false);

                PluginDebug.AddInfo("Use temp folder", PluginUpdateHandler.Shieldify.ToString(), sTempPluginsFolder, DebugPrint);

                //Download files
                foreach (PluginUpdate upd in PluginUpdateHandler.Plugins)
                {
                    if (!upd.Selected)
                    {
                        continue;
                    }
                    success |= UpdatePlugin(upd, sTempPluginsFolder, bUpdateTranslationsOnly);
                }
            });
            Thread t = new Thread(ts);

            t.IsBackground = true;
            t.Start();
            while (true && t.IsAlive)
            {
                if (!m_slUpdatePlugins.ContinueWork())
                {
                    t.Abort();
                    break;
                }
            }
            if (t != null && t.IsAlive)
            {
                t.Abort();
            }
            if (m_slUpdatePlugins != null)
            {
                m_slUpdatePlugins.EndLogging();
                m_slUpdatePlugins = null;
            }
            if (fUpdateLog != null)
            {
                fUpdateLog.Dispose();
            }

            //Move files from temp folder to plugin folder
            success &= PluginUpdateHandler.MoveAll(sTempPluginsFolder);
            foreach (var pu in PluginUpdateHandler.Plugins)
            {
                if (!pu.Selected)
                {
                    continue;
                }
                if (pu is OwnPluginUpdate)
                {
                    (pu as OwnPluginUpdate).UpdateTranslationInfo(true);
                }
            }
            if (success)
            {
                PluginUpdateHandler.Cleanup(sTempPluginsFolder);
            }
            success = true;
            //Restart KeePass to use new plugin versions
            PluginDebug.AddInfo("Update finished", "Succes: " + success.ToString(), DebugPrint);
            if (success && !bUpdateTranslationsOnly)
            {
                if (Tools.AskYesNo(PluginTranslate.PluginUpdateSuccess, PluginTranslate.PluginUpdateCaption) == DialogResult.Yes)
                {
                    if (m_bRestartInvoke)
                    {
                        m_host.MainWindow.Invoke(new KeePassLib.Delegates.GAction(() => { Restart(); }));
                    }
                    else
                    {
                        Restart();
                    }
                }
            }
        }