public override ICommandResult Execute(IDictionary <string, string> vars, params string[] args)
        {
            if (args.Length != 2)
            {
                return(ArgsCountError(2, args));
            }

            SubstituteVariables(vars, args);

            string from = args[0];
            string to   = args[1];

            if (string.IsNullOrWhiteSpace(from))
            {
                return(Error("the source path was empty or white space"));
            }
            if (string.IsNullOrWhiteSpace(to))
            {
                return(Error("the destination path was empty or white space"));
            }

            SafeFile.Move(from, to);

            return(Success());
        }
Esempio n. 2
0
        private void SaveDFUAndTetherFiles()
        {
            LogUtil.LogEvent(string.Format("Saving {0} and {1} files", MiscUtils.KERNEL_CACHE_FILE_NAME, MiscUtils.IBSS_FILE_NAME));

            MiscUtils.RecreateDirectory(firmwareVersionModel.AppDataFolder);

            LogUtil.LogEvent(string.Format("Directory {0} recreated successfully", firmwareVersionModel.AppDataFolder));

            string kernelcache = Path.Combine(MiscUtils.WORKING_FOLDER, MiscUtils.OUTPUT_FOLDER_NAME, MiscUtils.KERNEL_CACHE_FILE_NAME);

            if (SafeFile.Exists(kernelcache))
            {
                SafeFile.Copy(kernelcache, Path.Combine(firmwareVersionModel.AppDataFolder, MiscUtils.KERNEL_CACHE_FILE_NAME), true);
                LogUtil.LogEvent(string.Format("{0} file copied successfully", MiscUtils.KERNEL_CACHE_FILE_NAME));
            }

            string iBSS = Path.Combine(MiscUtils.WORKING_FOLDER, MiscUtils.OUTPUT_FOLDER_NAME, MiscUtils.FIRMWARE_FOLDER_NAME, MiscUtils.DFU_FOLDER_NAME, MiscUtils.IBSS_FILE_NAME);

            if (SafeFile.Exists(iBSS))
            {
                SafeFile.Copy(iBSS, Path.Combine(firmwareVersionModel.AppDataFolder, MiscUtils.IBSS_FILE_NAME), true);
                LogUtil.LogEvent(string.Format("{0} file copied successfully", MiscUtils.IBSS_FILE_NAME));
            }

            string iBEC = Path.Combine(MiscUtils.WORKING_FOLDER, MiscUtils.OUTPUT_FOLDER_NAME, MiscUtils.FIRMWARE_FOLDER_NAME, MiscUtils.DFU_FOLDER_NAME, MiscUtils.IBEC_FILE_NAME);

            if (firmwareVersionModel.SelectedVersion.Save_iBEC && SafeFile.Exists(iBEC))
            {
                SafeFile.Copy(iBEC, Path.Combine(firmwareVersionModel.AppDataFolder, MiscUtils.IBEC_FILE_NAME), true);
                LogUtil.LogEvent(string.Format("{0} file copied successfully", MiscUtils.IBEC_FILE_NAME));
            }
        }
Esempio n. 3
0
        public void ForceDeleteFile_WithNormalFile_DeletesIt()
        {
            var path = BaseDir.CreateFile("normal.txt");

            Should.NotThrow(() => SafeFile.ForceDeleteFile(path));
            path.FileExists().ShouldBeFalse();
        }
        private void SaveDfuAndTetherFiles()
        {
            LogUtil.LogEvent($"Saving {MiscUtils.KERNEL_CACHE_FILE_NAME} and {MiscUtils.IBSS_FILE_NAME} files");

            MiscUtils.RecreateDirectory(_firmwareVersionModel.AppDataFolder);

            LogUtil.LogEvent($"Directory {_firmwareVersionModel.AppDataFolder} recreated successfully");

            string kernelcache = Path.Combine(MiscUtils.WORKING_FOLDER, MiscUtils.OUTPUT_FOLDER_NAME, MiscUtils.KERNEL_CACHE_FILE_NAME);

            if (SafeFile.Exists(kernelcache))
            {
                SafeFile.Copy(kernelcache, Path.Combine(_firmwareVersionModel.AppDataFolder, MiscUtils.KERNEL_CACHE_FILE_NAME), true);
                LogUtil.LogEvent($"{MiscUtils.KERNEL_CACHE_FILE_NAME} file copied successfully");
            }

            string iBss = Path.Combine(MiscUtils.WORKING_FOLDER, MiscUtils.OUTPUT_FOLDER_NAME, MiscUtils.FIRMWARE_FOLDER_NAME, MiscUtils.DFU_FOLDER_NAME, MiscUtils.IBSS_FILE_NAME);

            if (SafeFile.Exists(iBss))
            {
                SafeFile.Copy(iBss, Path.Combine(_firmwareVersionModel.AppDataFolder, MiscUtils.IBSS_FILE_NAME), true);
                LogUtil.LogEvent($"{MiscUtils.IBSS_FILE_NAME} file copied successfully");
            }

            string iBec = Path.Combine(MiscUtils.WORKING_FOLDER, MiscUtils.OUTPUT_FOLDER_NAME, MiscUtils.FIRMWARE_FOLDER_NAME, MiscUtils.DFU_FOLDER_NAME, MiscUtils.IBEC_FILE_NAME);

            if (_firmwareVersionModel.SelectedVersion.SaveIBec && SafeFile.Exists(iBec))
            {
                SafeFile.Copy(iBec, Path.Combine(_firmwareVersionModel.AppDataFolder, MiscUtils.IBEC_FILE_NAME), true);
                LogUtil.LogEvent($"{MiscUtils.IBEC_FILE_NAME} file copied successfully");
            }
        }
Esempio n. 5
0
        private void RestoreDfuAndTetherFiles()
        {
            LogUtil.LogEvent("Restoring DFU and Tether file");

            string kernelCache = Path.Combine(_firmwareVersionModel.AppDataFolder, MiscUtils.KERNEL_CACHE_FILE_NAME);

            if (SafeFile.Exists(kernelCache))
            {
                SafeFile.Copy(kernelCache, Path.Combine(MiscUtils.BIN_DIRECTORY, MiscUtils.KERNEL_CACHE_FILE_NAME), true);
            }

            string iBss = Path.Combine(_firmwareVersionModel.AppDataFolder, MiscUtils.IBSS_FILE_NAME);

            if (SafeFile.Exists(iBss))
            {
                SafeFile.Copy(iBss, Path.Combine(MiscUtils.BIN_DIRECTORY, MiscUtils.IBSS_FILE_NAME), true);
            }

            string iBec = Path.Combine(_firmwareVersionModel.AppDataFolder, MiscUtils.IBEC_FILE_NAME);

            if (SafeFile.Exists(iBec))
            {
                SafeFile.Copy(iBec, Path.Combine(MiscUtils.BIN_DIRECTORY, MiscUtils.IBEC_FILE_NAME), true);
            }
        }
Esempio n. 6
0
        public void ForceDeleteFile_WithMissingFile_DoesNotThrow()
        {
            var path = BaseDir.Combine("missing.txt");

            path.FileExists().ShouldBeFalse();
            Should.NotThrow(() => SafeFile.ForceDeleteFile(path));
            path.FileExists().ShouldBeFalse();
        }
Esempio n. 7
0
        public void ForceDeleteFile_WithReadOnlyFile_DeletesIt()
        {
            var path = BaseDir.CreateFile("readonly.txt");

            SafeFile.SetReadOnly(path);

            Should.NotThrow(() => SafeFile.ForceDeleteFile(path));
            path.FileExists().ShouldBeFalse();
        }
Esempio n. 8
0
        public void AtomicWrite_ReplacingExistingReadOnlyFile_Throws()
        {
            var path = BaseDir.CreateFile("test.txt");

            SafeFile.SetReadOnly(path);

            Should.Throw <UnauthorizedAccessException>(() =>
                                                       SafeFile.AtomicWrite(path, tmpPath => tmpPath.ToNPath().CreateFile()));
        }
Esempio n. 9
0
        public void AtomicWrite_WithEmptyAction_ShouldDoNothing()
        {
            var path = BaseDir.CreateFile("test.txt");

            SafeFile.AtomicWrite(path, tmpPath => { });

            path.FileExists().ShouldBeTrue();
            (path + SafeFile.TmpExtension).ToNPath().FileExists().ShouldBeFalse();
            (path + SafeFile.BakExtension).ToNPath().FileExists().ShouldBeFalse();
        }
Esempio n. 10
0
        public void SetReadOnly_AppliesProperFileAttributes()
        {
            var path = BaseDir.CreateFile("normal.txt");

            ((File.GetAttributes(path) & FileAttributes.ReadOnly) == 0).ShouldBeTrue();

            SafeFile.SetReadOnly(path);
            ((File.GetAttributes(path) & FileAttributes.ReadOnly) != 0).ShouldBeTrue();
            SafeFile.SetReadOnly(path, false);
            ((File.GetAttributes(path) & FileAttributes.ReadOnly) == 0).ShouldBeTrue();
        }
Esempio n. 11
0
    private void SavedGame(SafeFile toSave)
    {
        //NotificationManager.instance.NewNotification("is saving");
        var serializer = new XmlSerializer(typeof(SafeFile));

        using (var stream = new System.IO.FileStream(Application.persistentDataPath + "/SavedGame_" + PhotonNetwork.NickName + ".xml", FileMode.Create))
        {
            serializer.Serialize(stream, toSave);
        }
        SafeFile();
    }
Esempio n. 12
0
        public void AtomicWrite_WithExistingReadOnlyTempAndBakFiles_OverwritesFilesAndOperatesNormally()
        {
            var path   = BaseDir.Combine("test.txt").WriteAllText("test");
            var temp   = (path + SafeFile.TmpExtension).ToNPath().CreateFile();
            var backup = (path + SafeFile.BakExtension).ToNPath().CreateFile();

            SafeFile.SetReadOnly(temp);
            SafeFile.SetReadOnly(backup);

            SafeFile.AtomicWrite(path, tmpPath => tmpPath.ToNPath().WriteAllText("new"));

            temp.FileExists().ShouldBeFalse();
            backup.FileExists().ShouldBeFalse();
            path.ReadAllText().ShouldBe("new");
        }
Esempio n. 13
0
        private void RestoreDFUFile()
        {
            LogUtil.LogEvent("Restoring DFU file");

            string iBSS = Path.Combine(firmwareVersionModel.AppDataFolder, MiscUtils.IBSS_FILE_NAME);

            if (SafeFile.Exists(iBSS))
            {
                SafeFile.Copy(iBSS, Path.Combine(MiscUtils.BIN_DIRECTORY, MiscUtils.IBSS_FILE_NAME), true);
            }

            string iBEC = Path.Combine(firmwareVersionModel.AppDataFolder, MiscUtils.IBEC_FILE_NAME);

            if (SafeFile.Exists(iBEC))
            {
                SafeFile.Copy(iBEC, Path.Combine(MiscUtils.BIN_DIRECTORY, MiscUtils.IBEC_FILE_NAME), true);
            }
        }
Esempio n. 14
0
        public void CancelDownload()
        {
            if (!_webClient.IsBusy) // already canceled or used ExistingFirmwarePath
            {
                return;
            }

            LogUtil.LogEvent("Cancelling download");
            _webClient.CancelAsync();
            while (_webClient.IsBusy)
            {
                Thread.Sleep(50);
            }
            if (SafeFile.Exists(_fileName))
            {
                SafeFile.Delete(_fileName);
            }
        }
Esempio n. 15
0
 public void LoadGame()
 {
     if (File.Exists(Application.persistentDataPath + "/SavedGame_" + PhotonNetwork.NickName + ".xml"))
     {
         lastSafeFile = Load();
         print(lastSafeFile + "test");
         byte[] test = lastSafeFile.test;
         if (lastSafeFile.test != null)
         {
             safe = (Safe)ByteArrayToObject(test);
         }
     }
     else
     {
         lastSafeFile = new SafeFile();
         safe         = new Safe();
     }
     LoadFile();
 }
Esempio n. 16
0
        private void PerformStart()
        {
            if (SafeFile.Exists(_firmwareVersionModel.ExistingFirmwarePath) &&
                MiscUtils.ComputeMd5(_firmwareVersionModel.ExistingFirmwarePath) == _firmwareVersionModel.CorrectFirmwareMd5)
            {
                LogUtil.LogEvent("Original firmware found on disk");

                SafeFile.Copy(_firmwareVersionModel.ExistingFirmwarePath, Path.Combine(MiscUtils.WORKING_FOLDER, MiscUtils.DOWNLOADED_FILE_PATH), true);
                if (DownloadCompleted != null)
                {
                    DownloadCompleted(this, EventArgs.Empty);
                }
                return;
            }

            LogUtil.LogEvent("Starting download");

            _webClient.DownloadFileAsync(new Uri(_firmwareVersionModel.DownloadUri), _fileName);
        }
Esempio n. 17
0
        private void webClient_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                LogUtil.LogEvent(string.Format("Download failed:\n{0}", e.Error));

                Percentage = 0;
                if (ProgressChanged != null)
                {
                    ProgressChanged(sender, e);
                }

                if (!e.Cancelled)
                {
                    if (DownloadFailed != null)
                    {
                        DownloadFailed(sender, e);
                    }
                    return;
                }
                else
                {
                    LogUtil.LogEvent("Download was cancelled by the user");
                    if (DownloadCanceled != null)
                    {
                        DownloadCanceled(sender, e);
                    }
                    return;
                }
            }

            LogUtil.LogEvent("Download completed");

            SafeFile.Copy(Path.Combine(MiscUtils.WORKING_FOLDER, MiscUtils.DOWNLOADED_FILE_PATH), _firmwareVersionModel.ExistingFirmwarePath, true);

            LogUtil.LogEvent("Downloaded file copied to Documents folder");

            if (DownloadCompleted != null)
            {
                DownloadCompleted(sender, e);
            }
        }
Esempio n. 18
0
        static bool OverwriteFileIfChanged(FormatItem formatItem, IEnumerable <string> lines, EndOfLine eol)
        {
            // write to a buffer so we can do an exact comparison vs the file already on disk. let's avoid generating io writes if
            // there is no actual change. but we need to have the raw bytes so that differences in encoding and EOL's are not masked.

            var newFileBuffer = new MemoryStream();

            WriteLines(newFileBuffer, lines, formatItem.EditorConfig.Charset, eol);
            var newFileBytes  = newFileBuffer.GetBuffer();
            var newFileLength = (int)newFileBuffer.Length;                     // not newFileBytes.Length!

            var match = new FileInfo(formatItem.Path).Length == newFileLength; // do cheap length check first

            if (match)
            {
                var oldFileBytes = File.ReadAllBytes(formatItem.Path);

                // must do the byte compare vs disk
                for (var i = 0; i < newFileLength; ++i)
                {
                    if (newFileBytes[i] != oldFileBytes[i])
                    {
                        match = false;
                        break;
                    }
                }
            }

            // ok we have to write it
            if (!match)
            {
                // TODO: copy the permission bits over ($mode & 0777) to the new file
                // TODO: backup under ./Temp/Format (subfolders? replace folder names with _?) configurable via a new FormatContext.BackupRoot
                SafeFile.AtomicWrite(formatItem.Path, writePath =>
                {
                    using (var writeFile = File.OpenWrite(writePath))
                        writeFile.Write(newFileBytes, 0, newFileLength);
                });
            }

            return(!match);
        }
Esempio n. 19
0
        public override ICommandResult Execute(IDictionary <string, string> vars, params string[] args)
        {
            if (args.Length != 1)
            {
                return(ArgsCountError(1, args));
            }

            SubstituteVariables(vars, args);

            string filePath = args[0];

            if (string.IsNullOrWhiteSpace(filePath))
            {
                return(Error("the file path was empty or white space"));
            }

            SafeFile.Delete(filePath);

            return(Success());
        }
Esempio n. 20
0
        private void RunDFU()
        {
            RestoreDFUFile();

            SafeDirectory.SetCurrentDirectory(MiscUtils.BIN_DIRECTORY);

            var files = new List <string>();

            if (SafeFile.Exists(MiscUtils.IBSS_FILE_NAME))
            {
                files.Add(MiscUtils.IBSS_FILE_NAME);
            }
            if (SafeFile.Exists(MiscUtils.IBEC_FILE_NAME))
            {
                files.Add(MiscUtils.IBEC_FILE_NAME);
            }
            string arguments = string.Join(" ", files);

            LogUtil.LogEvent(string.Format("DFU process starting for {0}", arguments));
            RunDFUProcess(arguments);
        }
        private void PerformPatch()
        {
            _patch = GetPatch();

            _patch.CurrentMessageChanged  += patch_CurrentMessageChanged;
            _patch.CurrentProgressChanged += patch_CurrentProgressChanged;

            string resultFile = _patch.PerformPatch();

            _patch.CurrentMessageChanged  -= patch_CurrentMessageChanged;
            _patch.CurrentProgressChanged -= patch_CurrentProgressChanged;
            _patch = null;

            SaveDfuAndTetherFiles();

            SafeFile.Copy(resultFile, _firmwareVersionModel.PatchedFirmwarePath, true);

            if (Finished != null)
            {
                Finished(this, EventArgs.Empty);
            }
        }
Esempio n. 22
0
 public bool IsTetherPossible()
 {
     return(SafeFile.Exists(Path.Combine(firmwareVersionModel.AppDataFolder, MiscUtils.KERNEL_CACHE_FILE_NAME)) &&
            SafeFile.Exists(Path.Combine(firmwareVersionModel.AppDataFolder, MiscUtils.IBSS_FILE_NAME)));
 }