Skip to content

Instantly share code, notes, and snippets.

@xyzzy-17-638
Created March 20, 2012 09:45
Show Gist options
  • Save xyzzy-17-638/2133525 to your computer and use it in GitHub Desktop.
Save xyzzy-17-638/2133525 to your computer and use it in GitHub Desktop.
[Windows]簡単アップデートくん
#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