Пример #1
0
        public int ReloadFileList(string projectPath)
        {
            IsMd5Checked = false;
            if (md5Thread != null && md5Thread.IsAlive)
            {
                StopMd5Thread();
            }
            LocalFiles.Clear();
            localFileMap.Clear();

            string filePath = $"{projectPath}\\Saved\\AssetMan\\assetlist.txt";

            if (File.Exists(filePath) == false)
            {
                return(0);
            }

            progress.Status = "loading file";
            string content = "";

            try
            {
                StreamReader sr = new StreamReader(filePath);
                content = sr.ReadToEnd();
                sr.Close();
            }catch
            {
                return(0);
            }

            progress.Status = "deserialize file";
            FAssetListData data = null;

            try
            {
                data = Newtonsoft.Json.JsonConvert.DeserializeObject <FAssetListData>(content);
            }catch
            {
            }
            if (data == null)
            {
                return(0);
            }

            progress.Status = "recoding file";
            recordLocalFile(data.DataMap);
            recordLocalFile(data.Dependencies);

            MergeFiles();
            IsCheckedForUpload = false;
            progress.Reset();
            progress.Status  = "start calc md5";
            progress.Total   = data.DataMap.Count + data.Dependencies.Count;
            md5ThreadRunning = true;
            md5Thread        = new Thread(new ThreadStart(CalcFileMd5Thread));
            md5Thread.Start();

            return(LocalFiles.Count);
        }
Пример #2
0
        public async Task <bool> CheckChanges()
        {
            if (IsProjDirValid == false)
            {
                return(false);
            }

            if (checkThreadWorking)
            {
                return(false);
            }

            Changes.Clear();
            progress.Reset();
            progress.Total = GetDirFiles(CurServer.ProjDir);

            checkThreadWorking = true;
            Action checkaction = CheckThread;
            await Task.Run(checkaction);

            return(true);
        }
Пример #3
0
        private VersionDistance CheckUpdates(VersionsModel svrVer, VersionsModel localVer)
        {
            progress.Reset();

            VersionDistance dst = new VersionDistance();

            dst.HasUpdate        = false;
            dst.MustUpdate       = false;
            dst.HasSkinUpdate    = false;
            dst.DownloadSize     = 0;
            dst.DownloadVersions = 0;

            //server versions is empty.
            if (svrVer == null || svrVer.FileVers == null || svrVer.FileVers.Count == 0)
            {
                progress.Status = "请求服务器数据失败";
                return(dst);
            }

            //local versions is empty
            if (localVer == null || localVer.FileVers == null || localVer.FileVers.Count == 0)
            {
                dst.HasUpdate        = true;
                dst.MustUpdate       = true;
                dst.HasSkinUpdate    = true;
                dst.DownloadVersions = 0;
                dst.DownloadSize     = 0;
                foreach (var item in svrVer.FileVers)
                {
                    dst.DownloadSize += item.DownloadSize;
                    dst.DownloadVersions++;
                    if (item.ForceUpdate)
                    {
                        dst.MustUpdate = true;
                    }
                }
                progress.Status = Util.GetDistanceReportString(dst);
                return(dst);
            }

            //check skin update
            dst.HasSkinUpdate = svrVer.SkinVer > localVer.SkinVer;

            //local is newer than server, this is not possible, maybe changed by user.
            VerInfoModel svrLatest   = svrVer.FileVers[0];
            VerInfoModel localLatest = localVer.FileVers[0];

            if (localLatest.SerialNo >= svrLatest.SerialNo)
            {
                return(dst);
            }

            dst.DownloadVersions = 0;
            dst.HasUpdate        = true;
            for (int i = svrVer.FileVers.Count - 1; i >= 0; i--)
            {
                VerInfoModel ver = svrVer.FileVers[i];
                if (ver.SerialNo <= localLatest.SerialNo)
                {
                    continue;
                }
                dst.DownloadSize += ver.DownloadSize;
                dst.DownloadVersions++;
                if (ver.ForceUpdate)
                {
                    dst.MustUpdate = true;
                }
            }

            progress.Status = Util.GetDistanceReportString(dst);
            return(dst);
        }
Пример #4
0
        private void BtnTransferFiles_Click(object sender, RoutedEventArgs e)
        {
            if ((man.cache?.Parsed?.FileMap?.Values?.Count > 0) == false)
            {
                MessageBox.Show("还没有加载数据", "", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            string svrDir   = txtServerFileDir.Text;
            string localDir = txtLocalFileDir.Text;

            if (Directory.Exists(svrDir) == false)
            {
                MessageBox.Show("服务器文件夹不存在", "", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            if (Directory.Exists(localDir) == false)
            {
                MessageBox.Show("接收文件夹不存在", "", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            if (svrDir.EndsWith("/") == false)
            {
                svrDir = svrDir + "/";
            }

            if (localDir.EndsWith("/") == false)
            {
                localDir = localDir + "/";
            }

            Dictionary <string, CopyItem> copyqueue = new Dictionary <string, CopyItem>();

            ProgressModel prog = new ProgressModel();

            BindProgressObj(prog);
            prog.Total = man.cache.Parsed.FileMap.Values.Count;
            long totalSize = 0;

            foreach (var item in man.cache.Parsed.FileMap.Values)
            {
                prog.Status = item.localPath;
                prog.CurPos++;
                if (string.IsNullOrEmpty(item.localPath) || string.IsNullOrEmpty(item.url) || item.url.StartsWith("/upload/", StringComparison.CurrentCultureIgnoreCase) == false)
                {
                    continue;//数据不合法
                }
                if (item.localPath.IndexOf("/Saved/") >= 0)
                {
                    continue;//saved文件夹的一律跳过
                }
                //只复制 content和 uploadIcons文件夹的

                int idindex = item.localPath.IndexOf("/Content/");
                if (idindex < 0)
                {
                    idindex = item.localPath.IndexOf("/UploadIcons/");
                }

                if (idindex < 0)
                {
                    continue;//只复制 content和 uploadIcons文件夹的
                }
                CopyItem cpitem = new CopyItem();
                cpitem.srcpath  = svrDir + item.url.Substring(7);// /upload/abc.txt >> abc.txt
                cpitem.dstpath  = localDir + item.localPath.Substring(idindex);
                cpitem.updatetm = item.modifiedTime;
                if (copyqueue.ContainsKey(cpitem.dstpath))
                {
                    var oldone = copyqueue[cpitem.dstpath];
                    if (cpitem.updatetm > oldone.updatetm)
                    {
                        copyqueue[cpitem.dstpath] = cpitem;
                    }
                }
                else
                {
                    copyqueue[cpitem.dstpath] = cpitem;
                    totalSize += item.size;
                }
            }

            MessageBox.Show($"总共 {copyqueue.Count} 文件拷贝, 尺寸约 {new FileSize((ulong)totalSize)}");

            prog.Reset();
            prog.Total = copyqueue.Values.Count;
            foreach (var item in copyqueue.Values)
            {
                Task.Run(() => {
                    string dstdir = System.IO.Path.GetDirectoryName(item.dstpath);
                    try
                    {
                        if (Directory.Exists(dstdir) == false)
                        {
                            Directory.CreateDirectory(dstdir);
                        }
                        File.Copy(item.srcpath, item.dstpath, true);
                        prog.Status = item.dstpath;
                        prog.CurPos++;
                    }
                    catch (Exception ex)
                    {
                        prog.Status = item.dstpath + " " + ex.Message;
                        prog.CurPos++;
                    }
                });
            }
        }