📄 node_win32.c
字号:
/*****************************************************************************
*
* This program is free software ; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: node_win32.c 202 2005-01-25 01:27:33Z picard $
*
* BetaPlayer Core
* Copyright (c) 2004 Gabor Kovacs
*
****************************************************************************/
#include "../stdafx.h"
#if defined(_WIN32)
#ifndef STRICT
#define STRICT
#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "../zlib/zlib.h"
#if defined(_WIN32_WCE)
#define TWIN(a) L ## a
#else
#define TWIN(a) a
#endif
static tchar_t RegBase[64];
static const tchar_t* CmdLine = NULL;
static const tchar_t* ProgramId = NULL;
static const tchar_t* Version = NULL;
#define NULL_ID FOURCC('N','U','L','L')
#if defined(_WIN32_WCE)
#define ACCESS_LOAD 0
#define ACCESS_SAVE 0
#else
#define ACCESS_LOAD KEY_READ
#define ACCESS_SAVE KEY_READ | KEY_WRITE | KEY_SET_VALUE
#endif
bool_t NodeBase( node* p, tchar_t* Base )
{
char Id[4];
if (p->Get(p,NODE_ID,Id,sizeof(Id)) != ERR_NONE)
return 0;
stprintf(Base,T("%s\\%c%c%c%c"),RegBase,Id[0],Id[1],Id[2],Id[3]);
return 1;
}
bool_t NodeLoadValue( int Id, void* Data, int Size, int* Type )
{
bool_t Result = 0;
HKEY Key;
tchar_t Name[32];
stprintf(Name,T("%d"),Id);
if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, RegBase, 0, ACCESS_LOAD, &Key ) == ERROR_SUCCESS)
{
DWORD RegSize = Size;
DWORD RegType;
if (RegQueryValueEx(Key, Name, 0, &RegType, (PBYTE)Data, &RegSize) == ERROR_SUCCESS)
Result = 1;
if (Type)
switch (RegType)
{
case REG_SZ: *Type = TYPE_STRING; break;
case REG_DWORD: *Type = TYPE_INT; break;
default: *Type = 0; break;
}
RegCloseKey( Key );
}
return Result;
}
void NodeSaveValue( int Id, const void* Data, int Size, int Type )
{
DWORD Disp;
HKEY Key;
tchar_t Name[32];
stprintf(Name,T("%d"),Id);
if (RegCreateKeyEx( HKEY_LOCAL_MACHINE, RegBase, 0, NULL, 0, ACCESS_SAVE, NULL, &Key, &Disp ) == ERROR_SUCCESS)
{
if (Size)
{
DWORD RegType;
switch (Type)
{
case TYPE_STRING: RegType = REG_SZ; break;
case TYPE_INT: RegType = REG_DWORD; break;
default: RegType = REG_BINARY; break;
}
RegSetValueEx( Key, Name, 0, RegType, (PBYTE)Data, Size );
}
else
RegDeleteValue(Key,Name);
RegCloseKey( Key );
}
}
void NodeLoadSetup( node* p )
{
HKEY Key;
tchar_t Base[256];
tchar_t Name[64];
if (!p || !NodeBase(p,Base))
return;
if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, Base, 0, ACCESS_LOAD, &Key ) == ERROR_SUCCESS)
{
uint8_t Buffer[512];
DWORD RegSize;
DWORD RegType;
node* Ptr;
int No;
datadef Type;
for (No=0;p->Enum(p,No,&Type)==ERR_NONE;++No)
if ((Type.Flags & DF_SETUP) && !(Type.Flags & (DF_OWNREG|DF_RDONLY)))
{
RegSize = sizeof(Buffer);
stprintf(Name,T("%d"),Type.No);
if (RegQueryValueEx(Key, Name, 0, &RegType, Buffer, &RegSize) == ERROR_SUCCESS)
{
switch (Type.Type)
{
case TYPE_BOOL:
case TYPE_INT:
case TYPE_HOTKEY:
case TYPE_FRACTION:
case TYPE_STRING:
case TYPE_RECT:
case TYPE_POINT:
case TYPE_RGB:
case TYPE_EQUALIZER:
case TYPE_TICK:
p->Set(p,Type.No,Buffer,RegSize);
break;
case TYPE_NODE:
if (RegType == REG_DWORD)
{
if (*(int*)Buffer == NULL_ID)
{
Ptr = NULL;
p->Set(p,Type.No,&Ptr,sizeof(Ptr));
}
else
{
Ptr = NodeFind(*(int*)Buffer);
if (Ptr)
p->Set(p,Type.No,&Ptr,sizeof(Ptr));
}
}
break;
}
}
}
RegCloseKey( Key );
}
}
void NodeSaveSetup( node* p )
{
DWORD Disp;
HKEY Key;
tchar_t Base[256];
tchar_t Name[64];
if (!p || !NodeBase(p,Base))
return;
if (RegCreateKeyEx( HKEY_LOCAL_MACHINE, Base, 0, NULL, 0, ACCESS_SAVE, NULL, &Key, &Disp ) == ERROR_SUCCESS)
{
uint8_t Buffer[512];
DWORD RegSize;
DWORD RegType;
node* Ptr;
int Size;
int No;
datadef Type;
struct list
{
tchar_t Name[64];
struct list *Next;
} *Chain = NULL,*List;
RegSize = sizeof(Name)/sizeof(tchar_t);
for (No=0;RegEnumValue(Key,No,Name,&RegSize,NULL,&RegType,NULL,NULL)==ERROR_SUCCESS;++No)
{
List = (struct list*)Alloc(sizeof(struct list));
if (!List) break;
tcscpy(List->Name,Name);
List->Next = Chain;
Chain = List;
RegSize = sizeof(Name)/sizeof(tchar_t);;
}
while (Chain)
{
List = Chain;
Chain = List->Next;
RegDeleteValue(Key,List->Name);
Free(List);
}
for (No=0;p->Enum(p,No,&Type)==ERR_NONE;++No)
if ((Type.Flags & DF_SETUP) && !(Type.Flags & (DF_OWNREG|DF_RDONLY)))
{
RegType = RegSize = Size = 0;
switch (Type.Type)
{
case TYPE_BOOL:
RegType = REG_DWORD;
RegSize = sizeof(DWORD);
Size = sizeof(bool_t);
break;
case TYPE_TICK:
case TYPE_INT:
case TYPE_HOTKEY:
RegType = REG_DWORD;
RegSize = Size = sizeof(int);
break;
case TYPE_FRACTION:
RegType = REG_BINARY;
RegSize = Size = sizeof(fraction);
break;
case TYPE_STRING:
RegType = REG_SZ;
RegSize = Size = sizeof(Buffer);
break;
case TYPE_RECT:
RegType = REG_BINARY;
RegSize = Size = sizeof(rect);
break;
case TYPE_POINT:
RegType = REG_BINARY;
RegSize = Size = sizeof(point);
break;
case TYPE_RGB:
RegType = REG_DWORD;
RegSize = sizeof(DWORD);
Size = sizeof(rgb);
break;
case TYPE_EQUALIZER:
RegType = REG_BINARY;
RegSize = Size = sizeof(equalizer);
break;
case TYPE_NODE:
if (p->Get(p,Type.No,&Ptr,sizeof(Ptr)) == ERR_NONE)
{
RegType = REG_DWORD;
RegSize = sizeof(DWORD);
if (Ptr)
{
if (Ptr->Get(Ptr,NODE_ID,Buffer,sizeof(int)) != ERR_NONE)
RegSize = 0;
}
else
*(int*)Buffer = NULL_ID;
}
break;
}
if (Size)
{
int Result;
memset(Buffer,0,RegSize);
Result = p->Get(p,Type.No,Buffer,Size);
if (Result != ERR_NONE && Result != ERR_NOT_SUPPORTED) // not supported settings should be still saved
continue;
}
if (RegSize)
{
stprintf(Name,T("%d"),Type.No);
RegSetValueEx( Key, Name, 0, RegType, Buffer, RegSize );
}
}
RegCloseKey( Key );
}
}
typedef struct lib
{
HMODULE Dll;
FARPROC Func;
uint8_t* Min;
uint8_t* Max;
} lib;
static int NodeLibCount = 0;
static lib NodeLib[256];
const tchar_t* NodeProgramId() { return ProgramId; }
const tchar_t* NodeVersion() { return Version; }
const tchar_t* NodeCmdLine() { return CmdLine; }
void Node_Init( const tchar_t* NewProgramId, const tchar_t* NewVersion, funcany Any, const tchar_t* NewCmdLine )
{
lib* Lib;
ProgramId = NewProgramId;
Version = NewVersion;
CmdLine = NewCmdLine ? NewCmdLine : T("");
tcscpy(RegBase,T("SOFTWARE\\"));
tcscat(RegBase,NewProgramId);
// add self (common.plg)
Lib = &NodeLib[0];
Lib->Dll = NULL;
Lib->Func = (FARPROC)Any;
Lib->Min = Lib->Max = NULL;
NodeLibCount = 1;
}
static void FilterString(tchar_t* i)
{
tchar_t* j=i;
for (;*i;++i,++j)
{
if (i[0]=='\\' && i[1]=='n')
{
*j=10;
++i;
}
else
*j=*i;
}
*j=0;
}
static void StringLoad(const tchar_t* FileName, gzFile gf, int Size)
{
int Lang;
tchar_t s[512];
tchar_t* p;
tchar_t* q;
uint16_t s16[512];
char* s8 = (char*)s16;
bool_t Unicode = 0;
int No = 0;
int CodePage = CP_OEMCP;
bool_t CodePageFound = 0;
// filter by file name if possible
tcscpy(s,FileName);
TcsUpr(s);
p = tcsstr(s,T("LANG_"));
if (p)
{
q = tcschr(p,'.');
if (q && tcsncmp(q,T(".TXT"),4)==0)
{
*q = 0;
Lang = StringToFourCC(p+5,1);
if (Lang != LANG_DEFAULT && Lang != StringLang && Lang != FOURCC('S','T','D','_'))
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -