-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
shandiankulishe
committed
Feb 6, 2022
0 parents
commit f2c4fda
Showing
5 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea/ | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
project(N0vaResourceExtractor) | ||
|
||
set(CMAKE_CXX_STANDARD 14) | ||
set(CMAKE_EXE_LINKER_FLAGS -static) | ||
|
||
add_executable(N0vaResourceExtractor main.cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 shandiankulishe | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# N0vaResourceExtractor | ||
## 这是什么 | ||
提取`人工桌面(米哈游旗下一款动态壁纸软件)`的动态壁纸资源的工具。 | ||
## 如何使用 | ||
### 如果需要批量拆资源文件 | ||
直接把二进制文件复制到人工桌面的安装目录然后运行即可。生成的文件为`源文件_changed.mp4` | ||
### 如果需要单个替换 | ||
+ Linux:输入 `./N0vaResourceExtractor [需要替换的文件] | ||
+ Windows: 直接把ndf文件拖到二进制文件里即可 | ||
## 从源代码构建 | ||
### Linux:(安装cmake和gcc环境) | ||
``` | ||
mkdir build | ||
cd build | ||
cmake .. | ||
make | ||
``` | ||
在`build`目录下寻找产出的二进制文件 | ||
### Windows(安装cmake和MinGW-W64) | ||
``` | ||
mkdir build | ||
cd build | ||
cmake -G "MinGW Makefiles" .. | ||
mingw32-make | ||
``` | ||
在`build`目录下寻找产出的二进制文件 | ||
## 开源 | ||
本项目使用MIT协议开源。模型为米哈游版权所有。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#include <iostream> | ||
#include <fstream> | ||
#include <vector> | ||
#include <cstdio> | ||
#include <io.h> | ||
#ifdef WIN32 | ||
#include <windows.h> | ||
#include <tchar.h> | ||
#endif | ||
#ifdef __linux__ | ||
#include <iostream> | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <dirent.h> | ||
#include <stdlib.h> | ||
#include <sys/stat.h> | ||
#include <string.h> | ||
#endif | ||
void replace(const char* filePath); | ||
void traverse(std::vector<std::string> &vct, char* path); | ||
int endWith(std::string s,std::string sub){ | ||
return s.rfind(sub)==(s.length()-sub.length())?1:0; | ||
} | ||
int main(int argc,char **argv) { | ||
if (argc==2){ | ||
char *filePath=argv[1]; | ||
replace(filePath); | ||
return 0; | ||
} else{ | ||
char filePath[1024]; | ||
getcwd(filePath,1024); | ||
std::vector<std::string> dirs; | ||
traverse(dirs,filePath); | ||
for (auto it = dirs.begin(); it!=dirs.end() ; ++it) { | ||
if (endWith(*it,".ndf")){ | ||
printf("Processing: %s\n",it->c_str()); | ||
replace(it->c_str()); | ||
} | ||
} | ||
return 0; | ||
} | ||
} | ||
void replace(const char* filePath){ | ||
std::ifstream fs(filePath,std::ios::in|std::ios::binary); | ||
//get content length | ||
fs.seekg(0,std::ios::end); | ||
size_t size=fs.tellg(); | ||
size-=2; | ||
fs.seekg(2,std::ios::beg); | ||
char *buffer=(char*) malloc(sizeof(char)*size+1); | ||
fs.read(buffer,size); | ||
char path[1024]={0}; | ||
strcat(path,filePath); | ||
strcat(path,"_changed.mp4"); | ||
std::ofstream os(path,std::ios::out|std::ios::binary); | ||
os.write(buffer,size); | ||
fs.close(); | ||
os.close(); | ||
} | ||
void traverse(std::vector<std::string> &vct, char* path){ | ||
#ifdef WIN32 | ||
long handle; | ||
_finddata_t fi; | ||
char _path[1024]={0}; | ||
memcpy(_path,path, strlen(path)); | ||
strcat(_path,"\\*"); | ||
int ret=handle=_findfirst(_path,&fi); | ||
if (handle==-1) { | ||
MessageBox(nullptr, _T("No files exists in the dirctory"), _T("Error"), MB_OK); | ||
printf("Error: No files exists in the directory %s", path); | ||
} | ||
while (ret!=-1){ | ||
if (strcmp(fi.name,".") != 0&& strcmp(fi.name,"..") !=0){ | ||
std::string s(path); | ||
s.append("\\"); | ||
s.append(fi.name); | ||
if ((fi.attrib&_A_NORMAL)==0){ | ||
vct.push_back(s); | ||
} | ||
} | ||
ret=_findnext(handle,&fi); | ||
} | ||
_findclose(handle); | ||
#endif | ||
#ifdef __linux__ | ||
struct stat s; | ||
lstat(path, &s); | ||
if(! S_ISDIR(s.st_mode)) | ||
{ | ||
printf("Error: No files exists in the directory %s", path); | ||
return; | ||
} | ||
struct dirent *fi; | ||
DIR *dir; | ||
dir = opendir(path); | ||
while((fi = readdir(dir) ) != NULL ) | ||
{ | ||
if(strcmp(fi->d_name , "." ) == 0 || | ||
strcmp(fi->d_name , "..") == 0) | ||
continue; | ||
if (fi->d_type == DT_REG){ | ||
std::string s(path); | ||
s.append("/"); | ||
s.append(fi->d_name); | ||
vct.push_back(s); | ||
} | ||
} | ||
|
||
#endif | ||
} |