Created
March 20, 2012 09:45
-
-
Save xyzzy-17-638/2133525 to your computer and use it in GitHub Desktop.
[Windows]簡単アップデートくん
This file contains hidden or 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
#define _CRT_SECURE_NO_WARNINGS | |
#include <stdio.h> | |
#include <windows.h> | |
#include <tchar.h> | |
int main(int argc, const char* argv[]) { | |
// 自分の名前 | |
TCHAR filename[MAX_PATH]; | |
GetModuleFileName(0, filename, MAX_PATH); | |
// 退避先の名前 | |
TCHAR backupName[MAX_PATH]; | |
{ | |
TCHAR drive[MAX_PATH], dir[MAX_PATH], fname[MAX_PATH], ext[MAX_PATH]; | |
_tsplitpath(filename, drive, dir, fname, ext); | |
_sntprintf(backupName, _countof(backupName), _T("%s%s%s_old%s"), drive, dir, fname, ext); | |
} | |
// 退避していたファイルがあるなら、削除する | |
if(GetFileAttributes(backupName) != 0xffffffffUL) { | |
DeleteFile(backupName); | |
} | |
// いろいろやってアップデートが必要かチェック | |
bool needUpdateAndExit = true; | |
// 必要ならファイル名を変えて、コピーとかする | |
if(needUpdateAndExit) { | |
MoveFile(filename, backupName); | |
// コピーとか、再起動的な何かとか | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment