Пример #1
0
        private string MoveImages(long shopId, string image, string name, int index = 1)
        {
            if (string.IsNullOrEmpty(image))
            {
                return("");
            }
            string mapPath = IOHelper.GetMapPath(image);
            string str     = ".png";
            string empty   = string.Empty;
            string str1    = string.Concat("/Storage/Shop/", shopId, "/Cert");

            empty = IOHelper.GetMapPath(str1);
            if (!Directory.Exists(empty))
            {
                Directory.CreateDirectory(empty);
            }
            string str2 = string.Concat(name, index, str);

            if (image.Replace("\\", "/").Contains("/temp/"))
            {
                IOHelper.CopyFile(mapPath, empty, true, str2);
            }
            return(string.Concat(str1, "/", str2));
        }
Пример #2
0
        public JsonResult Edit(SiteSettingModel siteSettingModel)
        {
            if (string.IsNullOrWhiteSpace(siteSettingModel.WXLogo))
            {
                Result result = new Result()
                {
                    success = false,
                    msg     = "请上传微信Logo",
                    status  = 1
                };
                return(Json(result));
            }
            string mapPath  = IOHelper.GetMapPath(siteSettingModel.Logo);
            string str      = IOHelper.GetMapPath(siteSettingModel.MemberLogo);
            string mapPath1 = IOHelper.GetMapPath(siteSettingModel.QRCode);
            string str1     = string.Concat("logo", (new FileInfo(mapPath)).Extension);
            string str2     = string.Concat("memberLogo", (new FileInfo(mapPath)).Extension);
            string str3     = string.Concat("qrCode", (new FileInfo(mapPath)).Extension);
            string str4     = "/Storage/Plat/Site/";
            string mapPath2 = IOHelper.GetMapPath(str4);

            if (!Directory.Exists(mapPath2))
            {
                Directory.CreateDirectory(mapPath2);
            }
            if (!siteSettingModel.Logo.Contains("/Storage"))
            {
                IOHelper.CopyFile(mapPath, mapPath2, false, str1);
            }
            if (!siteSettingModel.MemberLogo.Contains("/Storage"))
            {
                IOHelper.CopyFile(str, mapPath2, false, str2);
            }
            if (!siteSettingModel.QRCode.Contains("/Storage"))
            {
                IOHelper.CopyFile(mapPath1, mapPath2, false, str3);
            }
            if (!siteSettingModel.WXLogo.Contains("/Storage"))
            {
                string str5     = string.Concat(str4, "wxlogo.png");
                string mapPath3 = IOHelper.GetMapPath(siteSettingModel.WXLogo);
                string mapPath4 = IOHelper.GetMapPath(str5);
                using (Image image = Image.FromFile(mapPath3))
                {
                    image.Save(string.Concat(mapPath3, ".png"), ImageFormat.Png);
                    if (System.IO.File.Exists(mapPath4))
                    {
                        System.IO.File.Delete(mapPath4);
                    }
                    ImageHelper.CreateThumbnail(string.Concat(mapPath3, ".png"), mapPath4, 100, 100);
                }
                siteSettingModel.WXLogo = str5;
            }
            Result           result1      = new Result();
            SiteSettingsInfo siteSettings = ServiceHelper.Create <ISiteSettingService>().GetSiteSettings();

            siteSettings.SiteName            = siteSettingModel.SiteName;
            siteSettings.SiteIsClose         = siteSettingModel.SiteIsOpen;
            siteSettings.Logo                = string.Concat(str4, str1);
            siteSettings.MemberLogo          = string.Concat(str4, str2);
            siteSettings.QRCode              = string.Concat(str4, str3);
            siteSettings.FlowScript          = siteSettingModel.FlowScript;
            siteSettings.Site_SEOTitle       = siteSettingModel.Site_SEOTitle;
            siteSettings.Site_SEOKeywords    = siteSettingModel.Site_SEOKeywords;
            siteSettings.Site_SEODescription = siteSettingModel.Site_SEODescription;
            siteSettings.MobileVerifOpen     = siteSettingModel.MobileVerifOpen;
            siteSettings.WXLogo              = siteSettingModel.WXLogo;
            ServiceHelper.Create <ISiteSettingService>().SetSiteSettings(siteSettings);
            result1.success = true;
            return(Json(result1));
        }
Пример #3
0
 public async Task SaveContentToFile(MediaItem item, string filePath)
 {
     await IOHelper.CopyFile(GetMediaPath(item), filePath);
 }
Пример #4
0
        public JsonResult Index(SiteSettingModel siteSettingModel)
        {
            JsonResult jsonResult;

            if (!string.IsNullOrWhiteSpace(siteSettingModel.WXLogo))
            {
                string mapPath  = IOHelper.GetMapPath(siteSettingModel.Logo);
                string str      = IOHelper.GetMapPath(siteSettingModel.MemberLogo);
                string mapPath1 = IOHelper.GetMapPath(siteSettingModel.QRCode);
                string str1     = IOHelper.GetMapPath(siteSettingModel.PCLoginPic);
                string str2     = string.Concat("logo", (new FileInfo(mapPath)).Extension);
                string str3     = string.Concat("memberLogo", (new FileInfo(mapPath)).Extension);
                string str4     = string.Concat("qrCode", (new FileInfo(mapPath)).Extension);
                string str5     = string.Concat("pcloginpic", (new FileInfo(mapPath)).Extension);
                string str6     = "/Storage/Plat/Site/";
                string mapPath2 = IOHelper.GetMapPath(str6);
                if (!Directory.Exists(mapPath2))
                {
                    Directory.CreateDirectory(mapPath2);
                }
                if (!siteSettingModel.Logo.Contains("/Storage"))
                {
                    IOHelper.CopyFile(mapPath, mapPath2, false, str2);
                }
                if (!siteSettingModel.MemberLogo.Contains("/Storage"))
                {
                    IOHelper.CopyFile(str, mapPath2, false, str3);
                }
                if (!siteSettingModel.QRCode.Contains("/Storage"))
                {
                    IOHelper.CopyFile(mapPath1, mapPath2, false, str4);
                }
                if (siteSettingModel.PCLoginPic != null)
                {
                    if (!siteSettingModel.PCLoginPic.Contains("/Storage"))
                    {
                        IOHelper.CopyFile(str1, mapPath2, true, str5);
                        siteSettingModel.PCLoginPic = Path.Combine(str6, str5);
                    }
                }
                if (!siteSettingModel.WXLogo.Contains("/Storage"))
                {
                    string str7     = string.Concat(str6, "wxlogo.png");
                    string mapPath3 = IOHelper.GetMapPath(siteSettingModel.WXLogo);
                    string mapPath4 = IOHelper.GetMapPath(str7);
                    Image  image    = Image.FromFile(mapPath3);
                    try
                    {
                        image.Save(string.Concat(mapPath3, ".png"), ImageFormat.Png);
                        if (System.IO.File.Exists(mapPath4))
                        {
                            System.IO.File.Delete(mapPath4);
                        }
                        ImageHelper.CreateThumbnail(string.Concat(mapPath3, ".png"), mapPath4, 100, 100);
                    }
                    finally
                    {
                        if (image != null)
                        {
                            ((IDisposable)image).Dispose();
                        }
                    }
                    siteSettingModel.WXLogo = str7;
                }
                BaseController.Result result       = new BaseController.Result();
                SiteSettingsInfo      siteSettings = this._iSiteSettingService.GetSiteSettings();
                siteSettings.SiteName            = siteSettingModel.SiteName;
                siteSettings.SiteIsClose         = siteSettingModel.SiteIsOpen;
                siteSettings.Logo                = string.Concat(str6, str2);
                siteSettings.MemberLogo          = string.Concat(str6, str3);
                siteSettings.QRCode              = string.Concat(str6, str4);
                siteSettings.FlowScript          = siteSettingModel.FlowScript;
                siteSettings.Site_SEOTitle       = siteSettingModel.Site_SEOTitle;
                siteSettings.Site_SEOKeywords    = siteSettingModel.Site_SEOKeywords;
                siteSettings.Site_SEODescription = siteSettingModel.Site_SEODescription;
                siteSettings.MobileVerifOpen     = siteSettingModel.MobileVerifOpen;
                siteSettings.WXLogo              = siteSettingModel.WXLogo;
                siteSettings.PCLoginPic          = siteSettingModel.PCLoginPic;
                siteSettings.AndriodDownLoad     = siteSettingModel.AndriodDownLoad;
                siteSettings.IOSDownLoad         = siteSettingModel.IOSDownLoad;
                siteSettings.CanDownload         = siteSettingModel.CanDownload;
                this._iSiteSettingService.SetSiteSettings(siteSettings);
                result.success = true;
                jsonResult     = base.Json(result);
            }
            else
            {
                BaseController.Result result1 = new BaseController.Result()
                {
                    success = false,
                    msg     = "请上传微信Logo",
                    status  = 1
                };
                jsonResult = base.Json(result1);
            }
            return(jsonResult);
        }
        public void Repack(string srcFolder, string patchFolder, string importFolder)
        {
            Logger.Print("正在读取索引数据");
            DDTFileTable table = JsonHelper.Deserialize <DDTFileTable>(File.ReadAllText("./dds3_table.json", Encoding.UTF8));

            this.GetEntry();
            Logger.Print("正在复制package");
            if (File.Exists(Path.Combine(importFolder, Path.GetFileName(this.ImgName))))
            {
                File.Delete(Path.Combine(importFolder, Path.GetFileName(this.ImgName)));
            }
            if (File.Exists(Path.Combine(importFolder, Path.GetFileName(this.DDTName))))
            {
                File.Delete(Path.Combine(importFolder, Path.GetFileName(this.DDTName)));
            }

            IOHelper.CopyFile(this.ImgName, Path.Combine(importFolder, Path.GetFileName(this.ImgName)));
            IOHelper.CopyFile(this.DDTName, Path.Combine(importFolder, Path.GetFileName(this.DDTName)));
            Logger.Print("开始对资源打补丁");
            List <string> pFileList = SearchPatchingFiles(table, patchFolder);

            Logger.Print(string.Format("有 {0} 个资源文件需要打补丁", pFileList.Count));


            FileStream imgStream = File.Open(Path.Combine(importFolder, Path.GetFileName(this.ImgName)),
                                             FileMode.Open, FileAccess.ReadWrite);
            FileStream ddtStream = File.Open(Path.Combine(importFolder, Path.GetFileName(this.DDTName)),
                                             FileMode.Open, FileAccess.ReadWrite);
            BinaryWriter imgWriter = new BinaryWriter(imgStream);
            BinaryWriter ddtWriter = new BinaryWriter(ddtStream);

            Entry   vEntry;
            SubFile vSubFile;

            for (int i = 0; i < pFileList.Count; i++)
            {
                if (fDictionary.ContainsKey(pFileList[i]))
                {
                    byte[] data = null;

                    vEntry   = fDictionary[pFileList[i]];
                    vSubFile = tempSubFileDictionary[pFileList[i]];
                    if (Path.GetExtension(vSubFile.FileName).ToLower().Equals(".lb") &&
                        vSubFile.SubItems.Count > 0)
                    {
                        //lb包有子文件,启动压缩
                        LB     lbContainer = new LB();
                        byte[] packedBytes = lbContainer.Repack(getBaseDir(vSubFile.FileName), vSubFile.FileName, srcFolder, patchFolder, vSubFile.SubItems);
                        //File.WriteAllBytes("temp/" + Path.GetFileName(vSubFile.FileName), packedBytes);
                        data = packedBytes;
                    }
                    else
                    {
                        string tmpPath = "";
                        if (File.Exists(patchFolder + "/" + vSubFile.FileName))
                        {
                            tmpPath = patchFolder + "/" + vSubFile.FileName;
                        }
                        else
                        {
                            tmpPath = srcFolder + "/" + vSubFile.FileName;
                        }

                        data = File.ReadAllBytes(tmpPath);
                    }

                    if (data != null)
                    {
                        var t_length   = data.Length;
                        var chunk_size = 0;
                        if ((t_length % 0x800) == 0)
                        {
                            chunk_size = t_length;
                        }
                        else
                        {
                            chunk_size = t_length + 0x800 - t_length % 0x800;
                        }

                        var o_chunk_sz = 0;
                        if ((vEntry.Size % 0x800) == 0)
                        {
                            o_chunk_sz = vEntry.Size;
                        }
                        else
                        {
                            o_chunk_sz = vEntry.Size + 0x800 - vEntry.Size % 0x800;
                        }

                        if (chunk_size > o_chunk_sz)
                        {
                            //追加补丁
                            imgWriter.Seek(0, SeekOrigin.End);
                            var offset = imgWriter.BaseStream.Position / 0x800;
                            Logger.Print(string.Format("Append res file{0} to offfset {1:x8}", vSubFile.FileName,
                                                       offset * 0x800, t_length));
                            imgWriter.Write(data);
                            imgWriter.AlignPosition(0x800);
                            ddtWriter.Seek(vEntry.Ptr, SeekOrigin.Begin);
                            ddtWriter.Seek(4, SeekOrigin.Current);
                            ddtWriter.Write((int)offset);
                            ddtWriter.Write((int)t_length);
                        }
                        else
                        {
                            //原位替换
                            imgWriter.Seek(vEntry.Offset, SeekOrigin.Begin);
                            imgWriter.Write(Enumerable.Repeat((byte)0, vEntry.Size).ToArray());
                            imgWriter.Seek(vEntry.Offset, SeekOrigin.Begin);
                            var offset = vEntry.Offset / 0x800;
                            Logger.Print(string.Format("overrite res file{0} to offfset {1:x8}", vSubFile.FileName,
                                                       offset * 0x800, t_length));
                            imgWriter.Write(data);
                            ddtWriter.Seek(vEntry.Ptr, SeekOrigin.Begin);
                            ddtWriter.Seek(4, SeekOrigin.Current);
                            ddtWriter.Write((int)offset);
                            ddtWriter.Write((int)t_length);
                        }
                    }
                }
            }
            imgWriter.Close();
            ddtWriter.Close();
            Logger.Print("补丁结束。Have Fun");
        }
Пример #6
0
        public override void Run()
        {
            //determine all file times to copy
            var itemsToCopy = GetItemsToCopy();

            var transferLocation = Configuration.GetTransferLocation(TransferLocationName);

            if (transferLocation.MaximumSize.HasValue)
            {
                m_Logger.Info("Maximum size for transfer location: {0}", transferLocation.MaximumSize.Value.ToString("GB"));
            }


            var skippedSize = ByteSize.FromBytes(0);
            var copiedSize  = ByteSize.FromBytes(0);

            foreach (var item in itemsToCopy)
            {
                //determine absolute paths for the copy operation
                var absSource = GetSourcePath(item);
                var absTarget = GetTargetPath(item);

                try
                {
                    EnsurePathIsWithinSourceRoot(absSource);
                    EnsurePathIsWithinTargetRoot(absTarget);
                }
                catch (PathTooLongException ex)
                {
                    m_Logger.Error($"Could not copy file '{item.RelativePath}': {ex.GetType().Name}");
                    continue;
                }

                //source file not found => skip file, write error to log
                if (!File.Exists(absSource))
                {
                    m_Logger.Error("File '{0}' could not be found", absSource);
                    continue;
                }

                var size = new FileInfo(absSource).GetByteSize();

                //check if copying the file would exceed the maximum transfer size
                //continue because there might be a file that can be copied without exceeding the max size
                //this way the copy as much as possible
                if (CheckNextFileExceedsMaxTransferSize(size))
                {
                    m_Logger.Debug($"Skipping '{item.RelativePath}' ({size}) because copying it would exceed the maximum transfer size");
                    skippedSize += size;
                    continue;
                }

                m_Logger.Info($"Copying {item.RelativePath} ({size})");

                var success = FileEquals(absSource, absTarget) || IOHelper.CopyFile(absSource, absTarget);

                if (success)
                {
                    UpdateTransferLocationSizeCache(transferLocation, size);
                    OnItemCopied(item);
                    copiedSize += size;
                }
            }

            m_Logger.Info($"Copying complete. {copiedSize} worth of files were copied, {skippedSize} worth of files were skipped");
        }
Пример #7
0
 public bool CopyFile(string sourceFileName, string destFileName)
 {
     WriteLog("CopyFile", "Start.");
     WriteLog("CopyFile", "End.");
     return(IOHelper.CopyFile(sourceFileName, destFileName));
 }
Пример #8
0
        public ResourceCollection LoadRFFile(string rfFilePath, LSFile lsFile)
        {
            string        region = Utils.GetRegionFromFilename(rfFilePath);
            PatchFileItem currentPackedPatchFile = null;

            //Create new ResourceCollection
            ResourceCollection resCol = new ResourceCollection("data" + region);

            //Use temp folder instead of patch folder
            string tempRF = _TempFolder + Path.GetFileName(rfFilePath);

            IOHelper.CopyFile(rfFilePath, tempRF);

            //Load RF file
            RFFile rfFile = new RFFile(tempRF);

            string[]       pathParts    = new string[20];
            LSEntry[]      offsetParts  = new LSEntry[20];
            ResourceItem[] pathPartsRes = new ResourceItem[20];
            foreach (ResourceEntry rEntry in rfFile.ResourceEntries)
            {
                if (rEntry == null || string.IsNullOrEmpty(rEntry.EntryString))
                {
                    continue;
                }

                if (IsJunkEntry(rEntry))
                {
                    continue;
                }

                //Figuring out the path of the entry
                pathParts[rEntry.FolderDepth - 1] = rEntry.EntryString;
                Array.Clear(pathParts, rEntry.FolderDepth, pathParts.Length - (rEntry.FolderDepth));

                //New ResourceItem object
                ResourceItem rItem = new ResourceItem(resCol, rEntry.EntryString, rEntry.OffInPack, (uint)rEntry.CmpSize, (uint)rEntry.DecSize, rEntry.Packed, string.Join(string.Empty, pathParts));
                rItem.OriginalFlags      = rEntry.Flags;
                rItem.OverridePackedFile = (rItem.OriginalFlags & 0x4000) == 0x4000;

                //For Treeview
                pathPartsRes[rEntry.FolderDepth - 1] = rItem;
                Array.Clear(pathPartsRes, rEntry.FolderDepth, pathPartsRes.Length - (rEntry.FolderDepth));
                if (rEntry.FolderDepth == 1)
                {
                    resCol.Nodes.Add(rItem);
                }
                else
                {
                    pathPartsRes[rEntry.FolderDepth - 2].Nodes.Add(rItem);
                }

                LSEntry       fileEntry = null;
                PatchFileItem patchItem = null;
                if (rEntry.Packed)
                {
                    //Check if part of the patch/mod
                    patchItem = _PatchFileList.GetPatchFileItem(rItem.AbsolutePath);
                    if (patchItem != null)
                    {
                        if (patchItem.Packed)
                        {
                            currentPackedPatchFile = patchItem;
                        }
                    }
                    //Part of LS
                    else
                    {
                        currentPackedPatchFile = null;
                        string crcPath = rItem.AbsolutePath.TrimEnd('/') + (rEntry.Directory ? "/packed" : "");
                        uint   crc     = calc_crc(crcPath);
                        lsFile.Entries.TryGetValue(crc, out fileEntry);
                        if (fileEntry == null)
                        {
                            rItem.Source = FileSource.NotFound;
                        }
                        else
                        {
                            lsFile.Entries.Remove(crc);
                            rItem.Source = FileSource.LS;
                        }
                    }
                }

                //Check if part of the patch/mod
                if (currentPackedPatchFile != null && rItem.AbsolutePath.StartsWith(currentPackedPatchFile.AbsolutePath))
                {
                    rItem.Source    = FileSource.Patch;
                    rItem.PatchItem = currentPackedPatchFile;
                }
                else if (patchItem != null)
                {
                    rItem.Source    = FileSource.Patch;
                    rItem.PatchItem = patchItem;
                }

                //Part of LS
                else
                {
                    currentPackedPatchFile = null;
                    offsetParts[rEntry.FolderDepth - 1] = fileEntry;
                    Array.Clear(offsetParts, rEntry.FolderDepth, offsetParts.Length - (rEntry.FolderDepth));

                    if (!rItem.AbsolutePath.EndsWith("/"))
                    {
                        rItem.LSEntryInfo = offsetParts.LastOrDefault(x => x != null);
                        if (rItem.LSEntryInfo == null)
                        {
                            rItem.Source = FileSource.NotFound;
                        }
                        else
                        {
                            rItem.Source = FileSource.LS;
                        }
                    }
                }

                //Case of patch but not in packed
                if (rItem.OverridePackedFile && rItem.Source != FileSource.NotFound)
                {
                    rItem.Source    = FileSource.Patch;
                    rItem.PatchItem = _PatchFileList.GetPatchFileItem(rItem.AbsolutePath);
                    if (rItem.PatchItem == null)
                    {
                        rItem.PatchItem = _PatchFileList.GetPatchFileItem("data/" + rItem.RelativePath);
                    }
                }

                if (rItem.Source != FileSource.NotFound)
                {
                    for (int i = 0; i < pathParts.Length; i++)
                    {
                        if (pathParts[i] != null)
                        {
                            string folder = string.Join(string.Empty, pathParts, 0, i);
                            if (!resCol.Resources.ContainsKey(folder))
                            {
                                continue;
                            }
                            if (rItem.Source == FileSource.LS && resCol.Resources[folder].Source == FileSource.Patch)
                            {
                                resCol.Resources[folder].Source = rItem.Source;
                            }
                            else if (resCol.Resources[folder].Source == FileSource.NotFound)
                            {
                                resCol.Resources[folder].Source = rItem.Source;
                            }
                        }
                    }
                }

                resCol.Resources.Add(rItem.RelativePath, rItem);
            }

            rfFile.WorkingSource.Close();
            rfFile.CompressedSource.Close();
            IOHelper.DeleteFile(tempRF);
            IOHelper.DeleteFile(tempRF + ".dec");

            LogHelper.Info(string.Format("{0} entries: {1}", resCol.ResourceName, resCol.Resources.Count));
            return(resCol);
        }
Пример #9
0
        public bool ExtractFileFromPatch(ResourceItem rItem, string outputFile)
        {
            try
            {
                //Simple file
                string gameFile = PathHelper.GetGameFolder(PathHelperEnum.FOLDER_PATCH) + rItem.PatchItem.AbsolutePath.Replace('/', Path.DirectorySeparatorChar);
                if (File.Exists(gameFile))
                {
                    //If the file is an externally-patched file, we want to decompress it
                    if (rItem.OverridePackedFile)
                    {
                        byte[] fileBinary = File.ReadAllBytes(gameFile);
                        if (Utils.IsCompressed(fileBinary))
                        {
                            fileBinary = Utils.DeCompress(fileBinary);
                        }

                        Directory.CreateDirectory(Path.GetDirectoryName(outputFile));
                        File.WriteAllBytes(outputFile, fileBinary);
                        return(true);
                    }
                    else
                    {
                        IOHelper.CopyFile(gameFile, outputFile);
                        return(true);
                    }
                }

                string mainfolder     = "";
                string gamePackedFile = PathHelper.GetGameFolder(PathHelperEnum.FOLDER_PATCH) + rItem.AbsolutePath.Replace('/', Path.DirectorySeparatorChar);
                if (!rItem.AbsolutePath.EndsWith("/"))
                {
                    DataSource packedSource;

                    //If packed file not datasourced yet
                    string packed = rItem.PatchItem.AbsolutePath;
                    if (!_CachedDataSources.TryGetValue(packed, out packedSource))
                    {
                        string path = gamePackedFile.Substring(0, gamePackedFile.LastIndexOf("\\data")) + Path.DirectorySeparatorChar + packed.Replace("/", "\\") + "packed";
                        if (File.Exists(path))
                        {
                            packedSource = new DataSource(FileMap.FromFile(path));
                            _CachedDataSources.Add(packed, packedSource);
                            mainfolder = path.Remove(path.Length - 6);
                        }
                    }

                    var fileData = new byte[0];

                    byte[] checkCmp = packedSource.Slice((int)rItem.OffInPack, 4);
                    if (checkCmp[0] == 0x78 && checkCmp[1] == 0x9c)
                    {
                        fileData = Utils.DeCompress(packedSource.Slice((int)rItem.OffInPack, (int)rItem.CmpSize));
                    }
                    else
                    {
                        fileData = packedSource.Slice((int)rItem.OffInPack, (int)rItem.DecSize);
                    }
                    Directory.CreateDirectory(Path.GetDirectoryName(outputFile));
                    File.WriteAllBytes(outputFile, fileData);
                }
                else
                {
                    LogHelper.Error(string.Format("Error extracting '{0}', the file could not be found in '{1}'", rItem.AbsolutePath, outputFile));
                }
                return(true);
            }
            catch (Exception e)
            {
                LogHelper.Error(string.Format("Error extracting '{0}', error: {1}", rItem.AbsolutePath, e.Message));
                return(false);
            }
        }