| | |
| | | /// 执行上传自动备份数据(0:没有可上传的自动备份数据 1:成功 -1:失败)
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | public async static Task<int> DoUpLoadAutoBackupData()
|
| | | public static int DoUpLoadAutoBackupData()
|
| | | {
|
| | | //获取app的自动备份
|
| | | var data = await HdlBackupLogic.Current.GetBackupListNameFromDB(1);
|
| | | var data = HdlBackupLogic.Current.GetBackupListNameFromDB(1);
|
| | | if (data == null)
|
| | | {
|
| | | return -1;
|
| | |
| | | //删除全部的自动备份的本地文件
|
| | | DeleteAllAutoBackupFile();
|
| | | //如果没有自动备份数据,则把本地全部东西上传
|
| | | var pathTemp = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupDirectory);
|
| | | var pathTemp = DirNameResourse.AutoBackupDirectory;
|
| | | //复制本地所有文件过去
|
| | | List<string> listAllFile = Global.FileListByHomeId();
|
| | | List<string> listAllFile = HdlFileLogic.Current.GetRootPathListFile();
|
| | | foreach (string fileName in listAllFile)
|
| | | {
|
| | | string oldFile = UserCenterLogic.CombinePath(fileName);
|
| | | string oldFile = System.IO.Path.Combine(Config.Instance.FullPath, fileName);
|
| | | string newFile = System.IO.Path.Combine(pathTemp, fileName);
|
| | | //复制文件
|
| | | System.IO.File.Copy(oldFile, newFile, true);
|
| | | HdlFileLogic.Current.CopyFile(oldFile, newFile);
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uBackupFileUploading));
|
| | |
|
| | | //上传文件到云端
|
| | | bool result = await UpLoadBackupFileToDB(listEditor);
|
| | | bool result = UpLoadBackupFileToDB(listEditor);
|
| | | if (result == false)
|
| | | {
|
| | | ProgressFormBar.Current.Close();
|
| | |
| | | }
|
| | |
|
| | | //删除文件
|
| | | result = await DoDeleteFileFromDB(listDelete);
|
| | | result = DoDeleteFileFromDB(listDelete);
|
| | | if (result == false)
|
| | | {
|
| | | ProgressFormBar.Current.Close();
|
| | |
| | | /// </summary>
|
| | | /// <param name="listFile"></param>
|
| | | /// <returns></returns>
|
| | | private async static Task<bool> UpLoadBackupFileToDB(List<string> listFile)
|
| | | private static bool UpLoadBackupFileToDB(List<string> listFile)
|
| | | {
|
| | | int listFileCount = listFile.Count;
|
| | | string backUpDir = System.IO.Path.Combine(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupDirectory);
|
| | | string backUpDir = DirNameResourse.AutoBackupDirectory;
|
| | | for (int i = 0; i < listFile.Count; i++)
|
| | | {
|
| | | string file = listFile[i];
|
| | | var datainfo = new FileInfoData();
|
| | | datainfo.BackupFileName = file;
|
| | | datainfo.BackupFileContent = ReadDirctoryFileByName(backUpDir, file);
|
| | | datainfo.BackupFileContent = HdlFileLogic.Current.ReadFileByteContent(System.IO.Path.Combine(backUpDir, file));
|
| | | if (datainfo.BackupFileContent == null)
|
| | | {
|
| | | continue;
|
| | |
| | | list.Add(datainfo);
|
| | |
|
| | | //执行是上传
|
| | | bool falge = await DoUpLoadInfoToDB(list);
|
| | | bool falge = DoUpLoadInfoToDB(list);
|
| | | if (falge == false)
|
| | | {
|
| | | return false;
|
| | |
| | | /// </summary>
|
| | | /// <param name="listData">删除的文件</param>
|
| | | /// <returns></returns>
|
| | | private async static Task<bool> DoDeleteFileFromDB(List<string> listData)
|
| | | private static bool DoDeleteFileFromDB(List<string> listData)
|
| | | {
|
| | | if (listData.Count == 0)
|
| | | {
|
| | |
| | | }
|
| | |
|
| | | //获取app的自动备份
|
| | | var data = await HdlBackupLogic.Current.GetBackupListNameFromDB(1);
|
| | | var data = HdlBackupLogic.Current.GetBackupListNameFromDB(1);
|
| | | if (data == null || data.Count == 0)
|
| | | {
|
| | | return true;
|
| | |
| | | //获取控制主人账号的Token
|
| | | upData.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
|
| | |
|
| | | bool falge = await UserCenterLogic.GetResultStatuByRequestHttps("App/DeleteAppBackupFile", true, upData);
|
| | | bool falge = UserCenterLogic.GetResultStatuByRequestHttps("App/DeleteAppBackupFile", true, upData);
|
| | | if (falge == false)
|
| | | {
|
| | | return false;
|
| | | }
|
| | |
|
| | | //删除文件
|
| | | string strroot = Common.Config.Instance.FullPath;
|
| | | var backPath = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupdeleteDirectory);
|
| | | var backPath = DirNameResourse.AutoBackupdeleteDirectory;
|
| | | foreach (var file in listData)
|
| | | {
|
| | | string fullName = System.IO.Path.Combine(backPath, file);
|
| | | System.IO.File.Delete(fullName);
|
| | | HdlFileLogic.Current.DeleteFile(fullName);
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
| | | /// </summary>
|
| | | /// <param name="listData">上传的数据</param>
|
| | | /// <returns></returns>
|
| | | private async static Task<bool> DoUpLoadInfoToDB(List<FileInfoData> listData)
|
| | | private static bool DoUpLoadInfoToDB(List<FileInfoData> listData)
|
| | | {
|
| | | var nowZigbeeNumHomeId = Shared.Common.Config.Instance.Home.Id;
|
| | |
|
| | |
| | | //获取控制主人账号的Token
|
| | | upData.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
|
| | |
|
| | | bool falge = await UserCenterLogic.GetResultStatuByRequestHttps("App/HomeAppAutoDataBackup", true, upData);
|
| | | bool falge = UserCenterLogic.GetResultStatuByRequestHttps("App/HomeAppAutoDataBackup", true, upData, null, true);
|
| | | if (falge == false)
|
| | | {
|
| | | return false;
|
| | | }
|
| | |
|
| | | //删除文件
|
| | | string strroot = Common.Config.Instance.FullPath;
|
| | | var backPath = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupDirectory);
|
| | | var backPath = DirNameResourse.AutoBackupDirectory;
|
| | | foreach (var file in listData)
|
| | | {
|
| | | string fullName = System.IO.Path.Combine(backPath, file.BackupFileName);
|
| | | System.IO.File.Delete(fullName);
|
| | | HdlFileLogic.Current.DeleteFile(fullName);
|
| | | }
|
| | |
|
| | | return true;
|
| | |
| | |
|
| | | #region ■ 获取文件___________________________
|
| | |
|
| | | /// <summary> |
| | | /// 获取指定文件夹下面的文件内容 |
| | | /// </summary> |
| | | /// <param name="dirctory">指定文件夹的名字(不是全路径)</param> |
| | | /// <param name="fileName">File name.</param> |
| | | private static byte[] ReadDirctoryFileByName(string dirctory, string fileName) |
| | | { |
| | | var path = UserCenterLogic.CombinePath(dirctory, fileName); |
| | | if (System.IO.File.Exists(path) == false)
|
| | | {
|
| | | return null;
|
| | | } |
| | | return Shared.IO.FileUtils.ReadFile(path); |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取自动备份目录下的添加或者编辑的文件
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | public static List<string> GetAutoBackupEditorFile()
|
| | | {
|
| | | string strroot = Common.Config.Instance.FullPath; |
| | | var path = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupDirectory);
|
| | |
|
| | | return GetFileFromDirectory(path);
|
| | | return HdlFileLogic.Current.GetFileFromDirectory(DirNameResourse.AutoBackupDirectory);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | /// <returns></returns>
|
| | | public static List<string> GetAutoBackupDeleteFile()
|
| | | {
|
| | | string strroot = Common.Config.Instance.FullPath; |
| | | var path = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupdeleteDirectory);
|
| | |
|
| | | return GetFileFromDirectory(path);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取指定文件夹里面的全部文件 |
| | | /// </summary>
|
| | | /// <param name="directory">文件路径(全名)</param>
|
| | | /// <returns></returns>
|
| | | public static List<string> GetFileFromDirectory(string directory) |
| | | { |
| | | if (System.IO.Directory.Exists(directory) == false)
|
| | | {
|
| | | return new List<string>();
|
| | | } |
| | | |
| | | List<string> list = new List<string>(); |
| | | var files = System.IO.Directory.GetFiles(directory); |
| | | foreach (var file in files) |
| | | { |
| | | var f = file.Substring(directory.Length + 1); |
| | | list.Add(f); |
| | | } |
| | | return list; |
| | | return HdlFileLogic.Current.GetFileFromDirectory(DirNameResourse.AutoBackupdeleteDirectory);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | /// <param name="fileName">文件的名字,不含路径</param>
|
| | | public static void AddOrEditorFile(string fileName)
|
| | | {
|
| | | //根目录
|
| | | string strroot = Common.Config.Instance.FullPath;
|
| | | if (strroot == string.Empty)
|
| | | {
|
| | | return;
|
| | | }
|
| | | fileName = System.IO.Path.GetFileName(fileName);
|
| | | //自动备份目录
|
| | | string strBackPath = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupDirectory);
|
| | |
|
| | |
|
| | | //自动删除备份目录
|
| | | string strdelBackPath = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupdeleteDirectory);
|
| | | //如果删除列表里面有这个东西的话,移除掉
|
| | | string delFile = System.IO.Path.Combine(strdelBackPath, fileName);
|
| | | if (System.IO.File.Exists(delFile) == true)
|
| | | {
|
| | | System.IO.File.Delete(delFile);
|
| | | }
|
| | |
|
| | | string soureFile = System.IO.Path.Combine(strroot, fileName);
|
| | | string newFile = System.IO.Path.Combine(strBackPath, fileName);
|
| | | string strBackPath = DirNameResourse.AutoBackupDirectory;
|
| | | if (System.IO.Directory.Exists(strBackPath) == false)
|
| | | {
|
| | | //预创建个人中心全部的文件夹
|
| | | UserCenterLogic.CreatAllUserCenterDirectory();
|
| | | HdlFileLogic.Current.CreatAllUserCenterDirectory();
|
| | | }
|
| | |
|
| | | //自动删除备份目录
|
| | | string strdelBackPath = DirNameResourse.AutoBackupdeleteDirectory;
|
| | | //如果删除列表里面有这个东西的话,移除掉
|
| | | string delFile = System.IO.Path.Combine(strdelBackPath, fileName);
|
| | | HdlFileLogic.Current.DeleteFile(delFile);
|
| | |
|
| | | string soureFile = System.IO.Path.Combine(Common.Config.Instance.FullPath, fileName);
|
| | | string newFile = System.IO.Path.Combine(strBackPath, fileName);
|
| | |
|
| | | //原原本本的复制文件到指定文件夹
|
| | | CopyFile(soureFile, newFile);
|
| | | HdlFileLogic.Current.CopyFile(soureFile, newFile);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | /// <param name="fileName">文件的名字,不含路径</param>
|
| | | public static void DeleteFile(string fileName)
|
| | | {
|
| | | //根目录
|
| | | string strroot = Common.Config.Instance.FullPath;
|
| | | if (strroot == string.Empty)
|
| | | {
|
| | | return;
|
| | | }
|
| | | fileName = System.IO.Path.GetFileName(fileName);
|
| | | //自动删除备份目录
|
| | | string strBackPath = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupdeleteDirectory);
|
| | |
|
| | | string strBackPath = DirNameResourse.AutoBackupdeleteDirectory;
|
| | | string newFile = System.IO.Path.Combine(strBackPath, fileName);
|
| | |
|
| | | //创建一个空文件
|
| | |
| | | file.Close();
|
| | |
|
| | | //自动备份目录
|
| | | strBackPath = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupDirectory);
|
| | | strBackPath = DirNameResourse.AutoBackupDirectory;
|
| | | //如果备份列表里面有这个东西的话,移除掉
|
| | | string delFile = System.IO.Path.Combine(strBackPath, fileName);
|
| | | if (System.IO.File.Exists(delFile) == true)
|
| | | {
|
| | | System.IO.File.Delete(delFile);
|
| | | }
|
| | |
|
| | | HdlFileLogic.Current.DeleteFile(delFile);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | /// 同步云端数据(仅限APP启动之后) -1:异常 0:已经同步过,不需要同步 1:正常同步 2:没有自动备份数据
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | public static async Task<int> SynchronizeDbAutoBackupData()
|
| | | public static int SynchronizeDbAutoBackupData()
|
| | | {
|
| | | //判断是否能够同步数据
|
| | | string checkFile = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoDownLoadBackupCheckFile);
|
| | | string checkFile = DirNameResourse.AutoDownLoadBackupCheckFile;
|
| | | //如果本地已经拥有了这个文件,则说明不是新手机,不再自动还原
|
| | | if (System.IO.File.Exists(checkFile) == true)
|
| | | {
|
| | | //同步服务器的分享内容
|
| | | await HdlShardLogic.Current.SynchronizeDbSharedContent();
|
| | | HdlShardLogic.Current.SynchronizeDbSharedContent();
|
| | | return 0;
|
| | | }
|
| | |
|
| | |
| | | if (UserCenterResourse.UserInfo.AuthorityNo == 3)
|
| | | {
|
| | | //同步服务器的分享内容
|
| | | await HdlShardLogic.Current.SynchronizeDbSharedContent();
|
| | | HdlShardLogic.Current.SynchronizeDbSharedContent();
|
| | | //创建一个空文件(标识已经完成同步)
|
| | | var file = System.IO.File.Create(checkFile);
|
| | | file.Close();
|
| | |
| | | }
|
| | |
|
| | | //获取app的自动备份
|
| | | var data = await HdlBackupLogic.Current.GetBackupListNameFromDB(1);
|
| | | var data = HdlBackupLogic.Current.GetBackupListNameFromDB(1);
|
| | | if (data == null)
|
| | | {
|
| | | return -1;
|
| | |
| | | if (data.Count == 0)
|
| | | {
|
| | | //同步服务器的分享内容
|
| | | await HdlShardLogic.Current.SynchronizeDbSharedContent();
|
| | | HdlShardLogic.Current.SynchronizeDbSharedContent();
|
| | | //创建一个空文件(标识已经完成同步)
|
| | | var file = System.IO.File.Create(checkFile);
|
| | | file.Close();
|
| | |
| | | ProgressFormBar.Current.SetMsg(Language.StringByID(R.MyInternationalizationString.uAccountDataIsSynchronizing));
|
| | |
|
| | | //从云端获取备份的文件,然后存入本地指定的临时文件夹
|
| | | string tempDir = await HdlBackupLogic.Current.GetBackFileFromDBAndSetToLocation(backId);
|
| | | string tempDir = HdlBackupLogic.Current.GetBackFileFromDBAndSetToLocation(backId);
|
| | | if (tempDir == null)
|
| | | {
|
| | | //删除检测文件
|
| | |
| | | return -1;
|
| | | }
|
| | | //如果读取到的文件完全没有问题,则清理本地的文件
|
| | | UserCenterLogic.DeleteAllLocationFile(false);
|
| | | HdlFileLogic.Current.DeleteAllLocationFile(false);
|
| | |
|
| | | //没有错误的话,则移动到当前住宅文件夹下面
|
| | | Global.MoveDirectoryFileToHomeDirectory(tempDir, true);
|
| | | HdlFileLogic.Current.MoveDirectoryFileToHomeDirectory(tempDir, true);
|
| | |
|
| | | //创建一个空文件(标识已经完成同步)
|
| | | var file2 = System.IO.File.Create(checkFile);
|
| | |
| | | #region ■ 一般方法___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 复制文件
|
| | | /// </summary>
|
| | | /// <param name="sourseFile">指定文件(全名)</param>
|
| | | /// <param name="newFile">新文件(全名)</param>
|
| | | private static void CopyFile(string sourseFile, string newFile)
|
| | | {
|
| | | try
|
| | | {
|
| | | if (System.IO.File.Exists(sourseFile) == false)
|
| | | {
|
| | | return;
|
| | | }
|
| | | System.IO.File.Copy(sourseFile, newFile, true);
|
| | | }
|
| | | catch { }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 删除全部的自动备份的本地文件(此函数用于读取自动备份的时候使用)
|
| | | /// </summary>
|
| | | public static void DeleteAllAutoBackupFile()
|
| | | {
|
| | | //清空自动备份【文件夹】(编辑,追加)
|
| | | string dirPath = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupDirectory);
|
| | | System.IO.Directory.Delete(dirPath, true);
|
| | | System.IO.Directory.CreateDirectory(dirPath);
|
| | | string dirPath = DirNameResourse.AutoBackupDirectory;
|
| | | HdlFileLogic.Current.DeleteDirectory(dirPath);
|
| | | HdlFileLogic.Current.CreateDirectory(dirPath, true);
|
| | |
|
| | | //清空自动备份【文件夹】(删除)
|
| | | dirPath = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupdeleteDirectory);
|
| | | System.IO.Directory.Delete(dirPath, true);
|
| | | System.IO.Directory.CreateDirectory(dirPath);
|
| | | dirPath = DirNameResourse.AutoBackupdeleteDirectory;
|
| | | HdlFileLogic.Current.DeleteDirectory(dirPath);
|
| | | HdlFileLogic.Current.CreateDirectory(dirPath, true);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | public static void SaveBackupNotPrompted(bool notPrompted, int day = -1)
|
| | | {
|
| | | //文件全路径
|
| | | string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupNotPromptedFile);
|
| | | string fullName = DirNameResourse.AutoBackupNotPromptedFile;
|
| | | BackupNotPrompted info = null;
|
| | | if (System.IO.File.Exists(fullName) == true)
|
| | | {
|
| | | var data = Global.ReadFileByDirectory(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupNotPromptedFile);
|
| | | var data = HdlFileLogic.Current.ReadFileByteContent(fullName);
|
| | | info = JsonConvert.DeserializeObject<BackupNotPrompted>(System.Text.Encoding.UTF8.GetString(data));
|
| | | }
|
| | | if (info == null)
|
| | |
| | | info.Day = day;
|
| | | }
|
| | | //保存
|
| | | var saveData = JsonConvert.SerializeObject(info);
|
| | | var byteData = System.Text.Encoding.UTF8.GetBytes(saveData);
|
| | | Global.WriteFileToDirectoryByBytes(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupNotPromptedFile, byteData);
|
| | | HdlFileLogic.Current.SaveFileContent(fullName, info);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | //暂不支持成员
|
| | | return;
|
| | | }
|
| | | string strroot = Common.Config.Instance.FullPath; |
| | | var path = System.IO.Path.Combine(strroot, DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupDirectory);
|
| | |
|
| | | List<string> listFile1 = GetFileFromDirectory(path);
|
| | | List<string> listFile1 = HdlFileLogic.Current.GetFileFromDirectory(DirNameResourse.AutoBackupDirectory);
|
| | | List<string> listFile2 = GetAutoBackupDeleteFile();
|
| | |
|
| | | if (listFile1.Count == 0 && listFile2.Count == 0)
|
| | |
| | | }
|
| | |
|
| | | //文件全路径
|
| | | string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupNotPromptedFile);
|
| | | string fullName = DirNameResourse.AutoBackupNotPromptedFile;
|
| | | if (System.IO.File.Exists(fullName) == false)
|
| | | {
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | |
| | | return;
|
| | | }
|
| | | BackupNotPrompted info = null;
|
| | | var data = Global.ReadFileByDirectory(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoBackupNotPromptedFile);
|
| | | var data = HdlFileLogic.Current.ReadFileByteContent(fullName);
|
| | | info = JsonConvert.DeserializeObject<BackupNotPrompted>(System.Text.Encoding.UTF8.GetString(data));
|
| | | if (info.NotPrompted == true)
|
| | | {
|