|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonz/screensavermaker.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "texception.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tsystem.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef WIN32
|
|
Toshihiro Shimizu |
890ddd |
#pragma warning(disable : 4996)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <windows.h></windows.h>
|
|
Toshihiro Shimizu |
890ddd |
//#include <iostream.h></iostream.h>
|
|
Toshihiro Shimizu |
890ddd |
#include <sys stat.h=""></sys>
|
|
Toshihiro Shimizu |
890ddd |
#include <stdio.h></stdio.h>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <qurl></qurl>
|
|
Toshihiro Shimizu |
890ddd |
#include <qdesktopservices></qdesktopservices>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void makeScreenSaver(
|
|
Toshihiro Shimizu |
890ddd |
TFilePath scrFn,
|
|
Toshihiro Shimizu |
890ddd |
TFilePath swfFn,
|
|
Toshihiro Shimizu |
890ddd |
string screenSaverName)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
struct _stat results;
|
|
Toshihiro Shimizu |
890ddd |
if (_wstat(swfFn.getWideString().c_str(), &results) != 0)
|
|
Toshihiro Shimizu |
890ddd |
throw TException(L"Can't stat file " + swfFn.getWideString());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int swfSize = results.st_size;
|
|
Toshihiro Shimizu |
890ddd |
std::auto_ptr<char> swf(new char[swfSize]);</char>
|
|
Toshihiro Shimizu |
890ddd |
FILE *chan = _wfopen(swfFn.getWideString().c_str(), L"rb");
|
|
Toshihiro Shimizu |
890ddd |
if (!chan)
|
|
Toshihiro Shimizu |
890ddd |
throw TException(L"fopen failed on " + swfFn.getWideString());
|
|
Toshihiro Shimizu |
890ddd |
fread(swf.get(), swfSize, 1, chan);
|
|
Toshihiro Shimizu |
890ddd |
fclose(chan);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TFilePath svscrn = TSystem::getBinDir() + "screensaver.dat";
|
|
Toshihiro Shimizu |
890ddd |
if (!TFileStatus(svscrn).doesExist()) {
|
|
Toshihiro Shimizu |
890ddd |
throw TException(
|
|
Toshihiro Shimizu |
890ddd |
wstring(L"Screensaver template not found: ") +
|
|
Toshihiro Shimizu |
890ddd |
svscrn.getWideString());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
TSystem::copyFile(scrFn, svscrn);
|
|
Toshihiro Shimizu |
890ddd |
HANDLE hUpdateRes =
|
|
Toshihiro Shimizu |
890ddd |
BeginUpdateResourceW(scrFn.getWideString().c_str(), FALSE);
|
|
Toshihiro Shimizu |
890ddd |
if (hUpdateRes == NULL)
|
|
Toshihiro Shimizu |
890ddd |
throw TException(L"can't write " + scrFn.getWideString());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
BOOL result = UpdateResource(
|
|
Toshihiro Shimizu |
890ddd |
hUpdateRes,
|
|
Toshihiro Shimizu |
890ddd |
"FLASHFILE",
|
|
Toshihiro Shimizu |
890ddd |
MAKEINTRESOURCE(101),
|
|
Toshihiro Shimizu |
890ddd |
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
|
|
Toshihiro Shimizu |
890ddd |
swf.get(),
|
|
Toshihiro Shimizu |
890ddd |
swfSize);
|
|
Toshihiro Shimizu |
890ddd |
if (result == FALSE)
|
|
Toshihiro Shimizu |
890ddd |
throw TException(L"can't add resource to " + scrFn.getWideString());
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
result = UpdateResource(
|
|
Toshihiro Shimizu |
890ddd |
hUpdateRes,
|
|
Toshihiro Shimizu |
890ddd |
RT_STRING,
|
|
Toshihiro Shimizu |
890ddd |
MAKEINTRESOURCE(1),
|
|
Toshihiro Shimizu |
890ddd |
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
|
|
Toshihiro Shimizu |
890ddd |
(void*)screenSaverName.c_str(),
|
|
Toshihiro Shimizu |
890ddd |
screenSaverName.size());
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (result == FALSE)
|
|
Toshihiro Shimizu |
890ddd |
throw TException(L"can't add name to "+scrFn.getWideString());
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!EndUpdateResource(hUpdateRes, FALSE))
|
|
Toshihiro Shimizu |
890ddd |
throw TException(L"Couldn't write " + scrFn.getWideString());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void previewScreenSaver(TFilePath scr)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
try {
|
|
Toshihiro Shimizu |
890ddd |
TSystem::showDocument(scr);
|
|
Toshihiro Shimizu |
890ddd |
} catch (...) {
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void installScreenSaver(TFilePath scr)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
wstring cmd = wstring(L"desk.cpl,InstallScreenSaver ") + scr.getWideString();
|
|
Toshihiro Shimizu |
890ddd |
int ret = (int)
|
|
Toshihiro Shimizu |
890ddd |
ShellExecuteW(0, L"open", L"rundll32.exe", cmd.c_str(), 0, SW_SHOWNORMAL);
|
|
Toshihiro Shimizu |
890ddd |
if (ret <= 32)
|
|
Toshihiro Shimizu |
890ddd |
throw;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void makeScreenSaver(
|
|
Toshihiro Shimizu |
890ddd |
TFilePath scrFn,
|
|
Toshihiro Shimizu |
890ddd |
TFilePath swfFn,
|
|
Toshihiro Shimizu |
890ddd |
string screenSaverName)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
void previewScreenSaver(TFilePath scr)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void installScreenSaver(TFilePath scr)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif
|