Beispiel #1
0
        public static bool Start(bool callReplaceFiles)
        {
            if (callReplaceFiles)
            {
                Local.ReplaceFiles();
            }
            else
            {
                ExclusiveLocker replaceLock = new ExclusiveLocker();
                replaceLock.id = Local.ReplaceLockId;
                try
                {
                    if (!replaceLock.Lock(2000))
                    {
                        return(false);
                    }
                }
                finally
                {
                    replaceLock.Dispose();
                }
            }
            InitLocalFiles();
            int startCount = RemoteFile.Start(localFiles);

            return(startCount <= 0);  // true for gui
        }
Beispiel #2
0
        // false if replace needed but could not get lock
        public static bool ReplaceFiles()
        {
            ExclusiveLocker replaceLock = new ExclusiveLocker();

            replaceLock.id = Local.ReplaceLockId;
            try
            {
                if (!replaceLock.Lock(0))
                {
                    return(false);
                }
                if (!Config.Default.NewVersionFileTag)
                {
                    return(true);
                }
                RawLog.Default.Log("rep>");
                string tempDir    = Config.Default.GetPath(null, true, true);
                string workingDir = Config.Default.GetPath(null, false, true);
                if (!Directory.Exists(tempDir))
                {
                    Config.Default.NewVersionFileTag = false;
                    return(true);
                }
                if (!Utils.CheckFullAccess(workingDir))
                {
                    RawLog.Default.Log("!work");
                    return(true);
                }
                if (!Utils.CheckFullAccess(tempDir))
                {
                    RawLog.Default.Log("!temp");
                    return(true);
                }

                ArrayList localFilesTmp      = null;
                ArrayList remoteFilesTmp     = null;
                ArrayList localFilesAsocTmp  = new ArrayList();
                ArrayList remoteFilesAsocTmp = new ArrayList();

                string localFileTmp  = Config.Default.GetFileListPath(false);
                string remoteFileTmp = Config.Default.GetFileListPath(true);
                bool   localExits    = File.Exists(localFileTmp);
                bool   remoteExits   = File.Exists(remoteFileTmp);
                try
                {
                    if (localExits && remoteExits)
                    {
                        localFilesTmp  = RemoteFile.Load(localFileTmp, ref localFilesAsocTmp);
                        remoteFilesTmp = RemoteFile.Load(remoteFileTmp, ref remoteFilesAsocTmp);
                    }
                }
                catch (Exception xx) { Utils.OnError(xx); }


                // copy / replace new files
                //Utils.DeleteDir(workingDir);
                //Directory.Move(tempDir, workingDir);
                Utils.CopyReplaceFiles(tempDir, workingDir);
                InitLocalFiles();

                // delete removed files
                try
                {
                    if (localExits && remoteExits)
                    {
                        ArrayList toDelete = RemoteFile.GetRemovedFiles(localFilesTmp, remoteFilesTmp, false);
                        RemoteFile.DeleteFiles(toDelete, false);
                    }
                }
                catch (Exception xx) { Utils.OnError(xx); }
                // set file associations
                if (!FileAssoc.AreEqual(localFilesAsocTmp, localFileAsocs))
                {
                    try
                    {
                        FileAssoc.Register(localFilesAsocTmp, false);
                    }
                    catch (Exception xx) { Utils.OnError(xx); }
                    try
                    {
                        FileAssoc.Register(localFileAsocs, true);
                    }
                    catch (Exception xx) { Utils.OnError(xx); }
                }

                RawLog.Default.Log("rep<");
                Config.Default.NewVersionFileTag = false;
            }
            finally
            {
                replaceLock.Dispose();
            }
            return(true);
        }