/// <summary> /// 新建文件夹 /// </summary> /// <param name="dirname">新文件夹名</param> public static void AddNewDir() { var loc = myFileSystem.AddDir(Data.current, Data.DriveName, Data.Volume); DirectInfo dirinfo = new DirectInfo() { AccessCode = 255, Name = "新建文件夹", Author = "xu",//改系统名 LastEditor = "xu", AccessMode = 255, Type = 0, Location = myFileSystem.transfer(Data.Volume.SectorStart, loc, Data.Volume.Cluster) }; myFileSystem.WriteIn(Data.DriveName, Data.Volume, loc, new byte[Data.Volume.Cluster]); myFileSystem.SetFileInfo(Data.DriveName, dirinfo); }
/// <summary> /// 设置文件信息 不改变文件内容 /// </summary> /// <param name="drivename">驱动器</param> /// <param name="location">文件位置扇区</param> /// <param name="fat">文件表</param> /// <returns></returns> public static ErrorCode SetFileInfo(string drivename, DirectInfo fat) { byte[] buffer = DiskRW.read(drivename, fat.Location); //name for (int i = 0; i < 63; i++) { buffer[i] = 0; } byte[] name = Encoding.Unicode.GetBytes(fat.Name); name.CopyTo(buffer, 0); //文件号 权限号 权限标记 buffer[77] = fat.Type; buffer[78] = fat.AccessCode; buffer[79] = fat.AccessMode; //作者 name = Encoding.Unicode.GetBytes(fat.Author); name.CopyTo(buffer, 80); //最后修改人 name = Encoding.Unicode.GetBytes(fat.LastEditor); name.CopyTo(buffer, 112); //创建日期 buffer[144] = (byte)(fat.CreateTime); buffer[145] = (byte)(fat.CreateTime >> 8); buffer[146] = (byte)(fat.CreateTime >> 16); buffer[147] = (byte)(fat.CreateTime >> 24); //修改日期 buffer[148] = (byte)(fat.LastEditTime); buffer[149] = (byte)(fat.LastEditTime >> 8); buffer[150] = (byte)(fat.LastEditTime >> 16); buffer[151] = (byte)(fat.LastEditTime >> 24); bool res = DiskRW.write(drivename, fat.Location, buffer); if (!res) { return(ErrorCode.Fail); } return(ErrorCode.Success); }
/// <summary> /// 创建Sdk支付链接串(蚂蚁金服) /// </summary> /// <param name="directInfo">支付信息</param> /// <param name="config">config</param> /// <returns>请求连接</returns> public static string CreateDirectSdkPayByUser(DirectInfo directInfo, SdkPay.Config config) { const string url = SdkPay.Config.ServerUrl; string appId = config.GetAppId(); string privateKeyPem = config.GetPrivateKeyPem(); const string format = SdkPay.Config.Format; const string version = SdkPay.Config.Version; const string signType = SdkPay.Config.SignType; string publicKeyPem = config.GetPublicKeyPem(); const string charset = SdkPay.Config.Charset; const string productCode = SdkPay.Config.ProductCode; string pid = config.GetPid(); IAopClient client = new DefaultAopClient(url, appId, privateKeyPem, format, version, signType, publicKeyPem, charset, false); AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest(); if (!string.IsNullOrWhiteSpace(directInfo.Notify)) { request.SetNotifyUrl(directInfo.Notify); } if (!string.IsNullOrWhiteSpace(directInfo.Return)) { request.SetReturnUrl(directInfo.Return); } AlipayTradeAppPayModel model = new AlipayTradeAppPayModel { Body = directInfo.ExtraCommonParam, Subject = directInfo.Subject, TotalAmount = directInfo.TotalFee.ToString("0.00"), ProductCode = productCode, OutTradeNo = directInfo.OutTradeNo, TimeoutExpress = "30m", SellerId = pid }; request.SetBizModel(model); AlipayTradeAppPayResponse response = client.SdkExecute(request); var body = response.Body; return(body); }
/// <summary> /// 创建PC支付链接串(航旅版) /// </summary> /// <param name="directInfo">支付信息</param> /// <param name="config">config</param> /// <returns>请求连接</returns> public static string CreateDirectGetPcPayByUser(DirectInfo directInfo, Config config) { var partner = config.GetPid(); Submit submit = new Submit(config); var sParaTemp = new SortedDictionary <string, string> { { "service", "create_direct_pay_by_user" }, { "partner", partner }, { "_input_charset", Config.InputCharset.ToLower() }, { "payment_type", "1" }, { "notify_url", directInfo.Notify }, { "return_url", directInfo.Return }, { "out_trade_no", directInfo.OutTradeNo }, { "subject", directInfo.Subject }, { "total_fee", directInfo.TotalFee.ToString("0.00") }, { "show_url", directInfo.ShowUrl }, { "seller_email", Config.SellerEmail }, }; string responseResult = submit.BuildRequest(sParaTemp); return(responseResult); }
/// <summary> /// 创建Wap支付链接串(航旅版) /// </summary> /// <param name="directInfo">支付信息</param> /// <param name="config">config</param> /// <returns>请求连接</returns> public static string CreateDirectWapPayByUser(DirectInfo directInfo, Config config) { var partner = config.GetPid(); Submit submit = new Submit(config); var sParaTemp = new SortedDictionary <string, string> { { "partner", partner }, { "seller_id", partner }, { "_input_charset", Config.InputCharset.ToLower() }, { "service", "alipay.wap.create.direct.pay.by.user" }, { "payment_type", "1" }, { "notify_url", directInfo.Notify }, { "return_url", directInfo.Return }, { "out_trade_no", directInfo.OutTradeNo }, { "subject", directInfo.Subject }, { "total_fee", directInfo.TotalFee.ToString("0.00") }, { "show_url", directInfo.ShowUrl }, { "body", directInfo.ExtraCommonParam } }; string responseResult = submit.BuildRequest(sParaTemp, "post", "确认"); return(responseResult); }
/// <summary> /// 删除目录中某项 /// </summary> /// <param name="drivename">驱动器名</param> /// <param name="volumeinfo">卷信息结构体</param> /// <param name="cluster">要删的扇区</param> /// <param name="dirinfo">目录</param> /// <returns></returns> public static ErrorCode DeleteInDir(string drivename, VolumeInfo volumeinfo, UInt32 sector, DirectInfo dirinfo) { var cluster = TransferInverse(volumeinfo.SectorStart, sector, volumeinfo.Cluster); byte[] content = DiskRW.ReadA(drivename, dirinfo.Location, (uint)(volumeinfo.Cluster >> 9)); UInt32 next = mergeByte(content[160], content[161], content[162], content[163]); for (UInt16 i = 164; i < content.Length; i += 4) { UInt32 s1 = mergeByte(content[i], content[i + 1], content[i + 2], content[i + 3]); if (s1 == cluster) { content[i] = 0; content[i + 1] = 0; content[i + 2] = 0; content[i + 3] = 0; DiskRW.write(drivename, dirinfo.Location, content); return(ErrorCode.Success); } } //没有下一个索引块,找不到该目录 if (next == 0) { return(ErrorCode.NoSuchFile); } //读取索引表 content = DiskRW.ReadA(drivename, transfer(volumeinfo.SectorStart, next, volumeinfo.Cluster), (uint)(volumeinfo.Cluster >> 9)); while (true) { for (UInt16 i = 4; i < content.Length; i += 4) { UInt32 s1 = mergeByte(content[i], content[i + 1], content[i + 2], content[i + 3]); if (s1 == cluster) { content[i] = 0; content[i + 1] = 0; content[i + 2] = 0; content[i + 3] = 0; DiskRW.write(drivename, next, content); return(ErrorCode.Success); } } next = mergeByte(content[0], content[1], content[2], content[3]); //下簇号 为零表示没有下一簇 if (next == 0) { return(ErrorCode.NoSuchFile); } content = ReadOut(drivename, volumeinfo, next); } }
/// <summary> /// 添加文件fat,文件为空 /// </summary> /// <param name="current">当前目录信息</param> /// <param name="drivename">驱动器名</param> /// <param name="volumeinfo">当前卷信息</param> /// <returns>新文件簇号</returns> public static UInt32 AddDir(DirectInfo current, string drivename, VolumeInfo volumeinfo) { byte[] buffer = new byte[volumeinfo.Cluster]; var ls = GetFreeBlock(drivename, ref volumeinfo, 1);//获取存放fat的簇 //向现在目录加项 var currentDir = DiskRW.ReadA(drivename, current.Location, (UInt16)(volumeinfo.Cluster >> 9)); //检索当前的fat表 for (int i = 164; i < volumeinfo.Cluster; i += 4) { if (mergeByte(currentDir[i], currentDir[i + 1], currentDir[i + 2], currentDir[i + 3]) == 0) { currentDir[i] = (byte)ls[0]; currentDir[i + 1] = (byte)(ls[0] >> 8); currentDir[i + 2] = (byte)(ls[0] >> 16); currentDir[i + 3] = (byte)(ls[0] >> 24); //写回磁盘 DiskRW.write(drivename, current.Location, currentDir); return(ls[0]); } } //fat满并且没有下个簇存放 if (mergeByte(currentDir[160], currentDir[161], currentDir[162], currentDir[163]) == 0) { //添加下一索引块 byte[] buffer2 = new byte[volumeinfo.Cluster];//写入内容缓存 var l2 = GetFreeBlock(drivename, ref volumeinfo, 1); //写入上个的索引表 currentDir[160] = (byte)l2[0]; currentDir[161] = (byte)(l2[0] >> 8); currentDir[162] = (byte)(l2[0] >> 16); currentDir[163] = (byte)(l2[0] >> 24); //下个 buffer2[4] = (byte)ls[0]; buffer2[5] = (byte)(ls[0] >> 8); buffer2[6] = (byte)(ls[0] >> 16); buffer2[7] = (byte)(ls[0] >> 24); //写入磁盘 WriteIn(drivename, volumeinfo, l2[0], buffer2); DiskRW.write(drivename, current.Location, currentDir); return(ls[0]); } //寻找下一个索引表 currentDir = ReadOut(drivename, volumeinfo, mergeByte(currentDir[160], currentDir[161], currentDir[162], currentDir[163])); while (true) { for (int i = 4; i < volumeinfo.Cluster; i += 4) { if (mergeByte(currentDir[i], currentDir[i + 1], currentDir[i + 2], currentDir[i + 3]) == 0) { currentDir[i] = (byte)ls[0]; currentDir[i + 1] = (byte)(ls[0] >> 8); currentDir[i + 2] = (byte)(ls[0] >> 16); currentDir[i + 3] = (byte)(ls[0] >> 24); //写回磁盘 DiskRW.write(drivename, current.Location, currentDir); return(ls[0]); } continue; } //索引表满并且没有下个簇存放 if (mergeByte(currentDir[0], currentDir[1], currentDir[2], currentDir[3]) == 0) { //添加下一索引块 byte[] buffer2 = new byte[volumeinfo.Cluster];//写入内容缓存 var l2 = GetFreeBlock(drivename, ref volumeinfo, 1); //写入上个的索引表 currentDir[0] = (byte)l2[0]; currentDir[1] = (byte)(l2[0] >> 8); currentDir[2] = (byte)(l2[0] >> 16); currentDir[3] = (byte)(l2[0] >> 24); //下个 buffer2[4] = (byte)ls[0]; buffer2[5] = (byte)(ls[0] >> 8); buffer2[6] = (byte)(ls[0] >> 16); buffer2[7] = (byte)(ls[0] >> 24); //写入磁盘 WriteIn(drivename, volumeinfo, l2[0], buffer2); DiskRW.write(drivename, current.Location, currentDir); return(ls[0]); } currentDir = ReadOut(drivename, volumeinfo, mergeByte(currentDir[0], currentDir[1], currentDir[2], currentDir[3])); } }
/// <summary> /// 从某个FAT节点读取文件信息,返回值要转换方可使用 /// </summary> /// <param name="drivename"></param> /// <param name="location">扇区</param> /// <param name="fileUnit"></param> /// <returns>返回目录信息或者文件信息</returns> public static FATInfo GetFileInfo(string drivename, UInt32 location, UInt16 fileUnit) { byte[] content = DiskRW.ReadA(drivename, location, (uint)(fileUnit >> 9)); if (content[77] == 0) //目录 { var dir = new DirectInfo(); byte[] tmp = new byte[64]; Array.Copy(content, tmp, 64); dir.Name = Encoding.Unicode.GetString(tmp).Replace("\0", ""); //类型 dir.Type = content[77]; //权限号 dir.AccessCode = content[78]; //权限标记 dir.AccessMode = content[79]; //作者 tmp = new byte[32]; Array.Copy(content, 80, tmp, 0, 32); dir.Author = Encoding.Unicode.GetString(tmp); //最后修改人 tmp = new byte[32]; Array.Copy(content, 112, tmp, 0, 32); dir.LastEditor = Encoding.Unicode.GetString(tmp); //创建时间 UInt32 s1 = content[144]; UInt32 s2 = content[145]; UInt32 s3 = content[146]; UInt32 s4 = content[147]; dir.CreateTime = (s4 << 24) + (s3 << 16) + (s2 << 8) + s1; //最后修改时间 s1 = content[148]; s2 = content[149]; s3 = content[150]; s4 = content[151]; dir.LastEditTime = (s4 << 24) + (s3 << 16) + (s2 << 8) + s1; dir.Location = location; return(dir); } else if (content[77] != 0) //实体文件 { var file = new FileInfo(); byte[] tmp = new byte[64]; Array.Copy(content, tmp, 64); file.Name = Encoding.Unicode.GetString(tmp).Replace("\0", ""); //后缀名 tmp = new byte[13]; Array.Copy(content, 64, tmp, 0, 13); file.Extension = Encoding.Unicode.GetString(tmp).Replace("\0", ""); //类型 file.Type = content[77]; //权限号 file.AccessCode = content[78]; //权限标记 file.AccessMode = content[79]; //作者 tmp = new byte[32]; Array.Copy(content, 80, tmp, 0, 32); file.Author = Encoding.Unicode.GetString(tmp); //最后修改人 tmp = new byte[32]; Array.Copy(content, 112, tmp, 0, 32); file.LastEditor = Encoding.Unicode.GetString(tmp); //创建时间 UInt32 s1 = content[144]; UInt32 s2 = content[145]; UInt32 s3 = content[146]; UInt32 s4 = content[147]; file.CreateTime = (s4 << 24) + (s3 << 16) + (s2 << 8) + s1; //最后修改时间 s1 = content[148]; s2 = content[149]; s3 = content[150]; s4 = content[151]; file.LastEditTime = (s4 << 24) + (s3 << 16) + (s2 << 8) + s1; //尾字节 UInt16 s5 = content[152]; UInt16 s6 = content[153]; file.Rest = (UInt16)((s6 << 8) + s5); file.Location = location; return(file); } return(null); }