From f66314859fc7451c05f6bd22c64b5d892cd6f37e Mon Sep 17 00:00:00 2001 From: zhaochengyu Date: Fri, 27 Sep 2019 15:59:21 +0800 Subject: [PATCH] first commit --- .gitignore | 263 +++++++++++++++++++++++++++++++++++++ main.cc | 113 ++++++++++++++++ readme.md | 35 +++++ run.sh | 1 + splitmerge.sln | 31 +++++ splitmerge.vcxproj | 131 ++++++++++++++++++ splitmerge.vcxproj.filters | 22 ++++ 7 files changed, 596 insertions(+) create mode 100644 .gitignore create mode 100644 main.cc create mode 100644 readme.md create mode 100644 run.sh create mode 100644 splitmerge.sln create mode 100644 splitmerge.vcxproj create mode 100644 splitmerge.vcxproj.filters diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e6af416 --- /dev/null +++ b/.gitignore @@ -0,0 +1,263 @@ +*.DS_Store + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +#*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc diff --git a/main.cc b/main.cc new file mode 100644 index 0000000..186530f --- /dev/null +++ b/main.cc @@ -0,0 +1,113 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include +int splitFile(const char* path, int count, const char* savename) +{ + FILE* F = fopen(path, "rb"); + if (F == NULL) + { + return -1; + } + else + { + fseek(F, 0, SEEK_END);//将文件指针移动到文件末尾 + int length = ftell(F);//计算文件指针到文件开头的字节数,即就是文件大小 + int yushu = length % count;//余数 + int size = length / count; //前面count-1份每一分大小为size,最后一份为size + yushu + for (int i = 1; i <= count; i++) + { + char savefile[100]; + sprintf(savefile, "%s%d", savename,i); + printf("%s\n", savefile); + FILE* P = fopen(savefile, "wb"); + if (P == NULL) + { + fclose(F); + return -1; + } + else + { + fseek(F, (i - 1) * size, SEEK_SET); + if (i == count) + { + for (int j = 0; j <= size + yushu; j++) + { + int c = fgetc(F); + fputc(c, P); + } + } + else + { + for (int j = 0; j < size; j++) + { + int c = fgetc(F); + fputc(c, P); + } + } + + + } + fclose(P); + } + fclose(F); + return 0; + } +} +/*合并文件,合并为一个大文件bigfile返回-1表示分割失败,0表示成功*/ +int mergeFile(const char* savename, int count, const char* bigfile) +{ + + FILE* BF = fopen(bigfile, "wb"); + if (BF == NULL) + { + printf("open file failed"); + return -1; + } + else + { + for (int i = 0; i < count; i++) + { + char savefile[100]; + sprintf(savefile, "%s%d",savename,i+1); + + FILE* P = fopen(savefile, "rb"); + if (P == NULL) + { + printf("open %s failed", savefile); + fclose(BF); + return -1; + } + else + { + int c = fgetc(P); + while (c != EOF) + { + fputc(c, BF); + c = fgetc(P); + } + } + fclose(P); + } + } + fclose(BF); + return 0; +} +int main(int argc, char* argv[]) +{ + if (argc < 4) { + printf("splitmerge.exe split bigfile 10\nsplitmerge.exe merge bigfile 10\n"); + return 0; + } + if (strcmp(argv[1], "split") == 0) { + + splitFile(argv[2], atoi(argv[3]), "funnywolf.split"); + printf("split file finish"); + return 0; + } + else if (strcmp(argv[1], "merge") == 0) { + mergeFile("funnywolf.split", atoi(argv[3]), argv[2]); + printf("merge file finish"); + return 0; + } +} \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..fe21ee6 --- /dev/null +++ b/readme.md @@ -0,0 +1,35 @@ +# 鏂囦欢鍒嗗壊/鍚堝苟宸ュ叿(splitmerge) +splitmerge鐢ㄤ簬鍒嗗壊/鍚堝苟鏂囦欢,褰搘eb鏈嶅姟闄愬埗涓婁紶鏂囦欢澶у皬鏃,鍙氳繃姝ゅ伐鍏峰湪鏈満灏嗘枃浠跺垎鍓叉垚澶氫釜灏忔枃浠,涓婁紶鏈嶅姟鍣ㄥ悗鍐嶆浣跨敤璇ュ伐鍏峰皢澶氫釜灏忔枃浠跺悎骞舵垚涓涓ぇ鏂囦欢. +# 浣跨敤鏂规硶 +* 濡傚皢cthun.exe鍒嗗壊鎴3涓皬鏂囦欢 +``` +splitmerge.exe split cthun.exe 3 +位 splitmerge.exe split cthun.exe 3 +funnywolf.split1 +funnywolf.split2 +funnywolf.split3 +split file finish +F:\splitmerge +位 dir +聽椹卞姩鍣 F 涓殑鍗锋病鏈夋爣绛俱 +聽鍗风殑搴忓垪鍙锋槸 7825-4014 +聽F:\splitmerge 鐨勭洰褰 +2019/09/27聽 15:50聽 聽 聽 聽 聽 聽 聽 . +2019/09/27聽 15:50聽 聽 聽 聽 聽 聽 聽 .. +2019/09/11聽 10:07聽 聽 聽 聽 23,419,604 cthun.exe +2019/09/27聽 15:50聽 聽 聽 聽 聽7,806,534 funnywolf.split1 +2019/09/27聽 15:50聽 聽 聽 聽 聽7,806,534 funnywolf.split2 +2019/09/27聽 15:50聽 聽 聽 聽 聽7,806,537 funnywolf.split3 +2019/09/27聽 15:18聽 聽 聽 聽 聽 聽 17,184 splitmerge +2019/09/27聽 15:13聽 聽 聽 聽 聽 聽 10,240 splitmerge.exe +聽 聽 聽 聽 聽 聽 聽 聽6 涓枃浠堵 聽 聽46,866,633 瀛楄妭 +聽 聽 聽 聽 聽 聽 聽 聽2 涓洰褰 981,248,131,072 鍙敤瀛楄妭 +F:\splitmerge +``` + +* 灏唂unnywolf.split1,funnywolf.split2,funnywolf.split2涓婁紶鍒皐eb鏈嶅姟鍣ㄥ悗,鎵ц +``` +splitmerge.exe merge cthun_new.exe 3 +``` +灏嗕笁涓枃浠堕噸鏂板悎骞舵垚cthun_new.exe + diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..1a297bc --- /dev/null +++ b/run.sh @@ -0,0 +1 @@ +g++ -std=c++11 main.cc -o main \ No newline at end of file diff --git a/splitmerge.sln b/splitmerge.sln new file mode 100644 index 0000000..2be7417 --- /dev/null +++ b/splitmerge.sln @@ -0,0 +1,31 @@ +锘 +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29215.179 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "splitmerge", "splitmerge.vcxproj", "{9597A486-2FDD-4881-9A88-1731EFB90E53}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9597A486-2FDD-4881-9A88-1731EFB90E53}.Debug|x64.ActiveCfg = Debug|x64 + {9597A486-2FDD-4881-9A88-1731EFB90E53}.Debug|x64.Build.0 = Debug|x64 + {9597A486-2FDD-4881-9A88-1731EFB90E53}.Debug|x86.ActiveCfg = Debug|Win32 + {9597A486-2FDD-4881-9A88-1731EFB90E53}.Debug|x86.Build.0 = Debug|Win32 + {9597A486-2FDD-4881-9A88-1731EFB90E53}.Release|x64.ActiveCfg = Release|x64 + {9597A486-2FDD-4881-9A88-1731EFB90E53}.Release|x64.Build.0 = Release|x64 + {9597A486-2FDD-4881-9A88-1731EFB90E53}.Release|x86.ActiveCfg = Release|Win32 + {9597A486-2FDD-4881-9A88-1731EFB90E53}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {77A3D510-FCF9-4623-99BE-6A7FD3D58EDC} + EndGlobalSection +EndGlobal diff --git a/splitmerge.vcxproj b/splitmerge.vcxproj new file mode 100644 index 0000000..bc774cf --- /dev/null +++ b/splitmerge.vcxproj @@ -0,0 +1,131 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {9597A486-2FDD-4881-9A88-1731EFB90E53} + splitmerge + 10.0 + + + + Application + true + v142 + MultiByte + + + Application + false + v142 + true + MultiByte + + + Application + true + v142 + MultiByte + + + Application + false + v142 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + true + true + + + Console + + + + + Level3 + Disabled + true + true + + + Console + + + + + Level3 + MaxSpeed + true + true + true + true + + + Console + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + Console + true + true + + + + + + + + + \ No newline at end of file diff --git a/splitmerge.vcxproj.filters b/splitmerge.vcxproj.filters new file mode 100644 index 0000000..79b4bd4 --- /dev/null +++ b/splitmerge.vcxproj.filters @@ -0,0 +1,22 @@ +锘 + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 婧愭枃浠 + + + \ No newline at end of file