Example #1
0
void TRegistry::CloseKey()
{
  if (GetCurrentKey() != 0)
  {
    // if LazyWrite then
    RegCloseKey(GetCurrentKey()); //else RegFlushKey(CurrentKey);
    FCurrentKey = 0;
    FCurrentPath = L"";
  }
}
Example #2
0
/* 取当前KEY对应的数据(包)
 *   注意,当数据有修改时,可能需是更新包的内容,所以
 *   不返回const类型;
 */
Conf *Page::GetCurrentPack()
{
    // 空,则先加载其值;
    if(NULL == m_pack)
    {
        const string &key = GetCurrentKey();
        const string &username = m_request->GetCurrentUser();
        UserData data( username );
        Conf *pack = new Conf;
        if(NULL != pack)
        {
            Ini ini;
            // 填充一个空Conf,以便插入key对应的所有值;
            ini.Set(key, *pack);
            data.Get( ini );
            pack->Set( *(ini.Get(key)) );
            m_pack = pack;
            LOG_DEBUG("Pack[key:%s] loading... ok", key.c_str());
        }
    }
    if(NULL == m_pack)
    {
        // 返回一空值,避免外部做过多的NULL检测;
        static Conf pack;
        return &pack;
    }
    return m_pack;
}
Example #3
0
bool TRegistry::OpenKey(const UnicodeString & Key, bool CanCreate)
{
  bool Result = false;
  UnicodeString S = Key;
  bool Relative = Classes::IsRelative(S);

  // if (!Relative) S.erase(0, 1); // Delete(S, 1, 1);
  HKEY TempKey = 0;
  if (!CanCreate || S.IsEmpty())
  {
    Result = RegOpenKeyEx(GetBaseKey(Relative), S.c_str(), 0,
                          FAccess, &TempKey) == ERROR_SUCCESS;
  }
  else
  {
    Result = RegCreateKeyEx(GetBaseKey(Relative), S.c_str(), 0, nullptr,
                            REG_OPTION_NON_VOLATILE, FAccess, nullptr, &TempKey, nullptr) == ERROR_SUCCESS;
  }
  if (Result)
  {
    if ((GetCurrentKey() != 0) && Relative)
    {
      S = FCurrentPath + L'\\' + S;
    }
    ChangeKey(TempKey, S);
  }
  return Result;
}
Example #4
0
bool TRegistry::GetKeyInfo(TRegKeyInfo & Value) const
{
  ClearStruct(Value);
  bool Result = RegQueryInfoKey(GetCurrentKey(), nullptr, nullptr, nullptr, &Value.NumSubKeys,
    &Value.MaxSubKeyLen, nullptr, &Value.NumValues, &Value.MaxValueLen,
    &Value.MaxDataLen, nullptr, &Value.FileTime) == ERROR_SUCCESS;
  return Result;
}
Example #5
0
bool TRegistry::GetDataInfo(const UnicodeString & ValueName, TRegDataInfo & Value) const
{
  DWORD DataType;
  ClearStruct(Value);
  bool Result = (RegQueryValueEx(GetCurrentKey(), ValueName.c_str(), nullptr, &DataType, nullptr,
                                 &Value.DataSize) == ERROR_SUCCESS);
  Value.RegData = DataTypeToRegData(DataType);
  return Result;
}
Example #6
0
// 输出http协议头部
int Page_Image::OutHead()
{
    FUNCTION_TRACK(); // 函数轨迹跟综

    Connect * const connect = m_request->GetConnect();
    string filename = m_request->GetField("file");
    string fullpath = "";

    if("" == filename)
    {
        /*
         * 是直接请求图片,如:
         * http://192.168.1.100:17890/logo.gif
         */
        filename = m_request->GetPageName();
        fullpath = GlobalConfig::instance()->HtmlDir() + filename;
    }
    else
    {
        /*
         * 打开用户图片,如:
         *  http://192.168.1.100:17890/image?file=logo.gif
         */
        const string &username = m_request->GetCurrentUser();
        const string &key = GetCurrentKey();
        User *user = User::Get( username );
        fullpath = user->AttachDir() + key + "." + filename; // 图片存于附件目录中
    }

    LOG_DEBUG("file=[%s]", fullpath.c_str());


    if( "" == filename || !m_file.Open(fullpath) )
    {
        Page::OutHead();

        const string str = "没有图片: <font color='red'>" + filename + "</font>";
        LOG_ERROR("Can't open file: [%s]", fullpath.c_str());
        // 发送到浏览器
        connect->Send(str);
        return ERR;
    }

    const string &size = IntToString(m_file.Size());
    // 图像显示
    const string html = ""
                        "HTTP/1.1 200 OK\n"
                        "Accept-Ranges: bytes\n"
                        "Content-Length: " + size + "\n"
                        "Connection: Keep-Alive\n"
                        "Content-Type: image/png jpg jpeg gif bmp\n"
                        "\n";

    // 发送
    return connect->Send(html) == html.length() ? OK : ERR;
}
Example #7
0
void TRegistry::PutData(const UnicodeString & Name, const void * Buffer,
  intptr_t BufSize, TRegDataType RegData)
{
  int DataType = Classes::RegDataToDataType(RegData);
  if (RegSetValueEx(GetCurrentKey(), Name.c_str(), 0, DataType,
                    reinterpret_cast<const BYTE *>(Buffer), static_cast<DWORD>(BufSize)) != ERROR_SUCCESS)
  {
    throw Exception("RegSetValueEx failed");    // ERegistryException(); // FIXME .CreateResFmt(SRegSetDataFailed, Name.c_str());
  }
}
Example #8
0
int TRegistry::GetData(const UnicodeString & Name, void * Buffer,
  intptr_t BufSize, TRegDataType & RegData) const
{
  DWORD DataType = REG_NONE;
  DWORD bufSize = static_cast<DWORD>(BufSize);
  if (RegQueryValueEx(GetCurrentKey(), Name.c_str(), nullptr, &DataType,
    reinterpret_cast<BYTE *>(Buffer), &bufSize) != ERROR_SUCCESS)
  {
    throw Exception("RegQueryValueEx failed"); // FIXME ERegistryException.CreateResFmt(@SRegGetDataFailed, [Name]);
  }
  RegData = DataTypeToRegData(DataType);
  int Result = static_cast<int>(BufSize);
  return Result;
}
Example #9
0
void TRegistry::GetKeyNames(TStrings * Strings) const
{
  Strings->Clear();
  TRegKeyInfo Info;
  UnicodeString S;
  if (GetKeyInfo(Info))
  {
    S.SetLength(static_cast<intptr_t>(Info.MaxSubKeyLen) + 1);
    for (DWORD I = 0; I < Info.NumSubKeys; I++)
    {
      DWORD Len = Info.MaxSubKeyLen + 1;
      RegEnumKeyEx(GetCurrentKey(), static_cast<DWORD>(I), &S[1], &Len, nullptr, nullptr, nullptr, nullptr);
      Strings->Add(S.c_str());
    }
  }
}
Example #10
0
void TRegistry::GetValueNames(TStrings * Strings) const
{
  Strings->Clear();
  TRegKeyInfo Info;
  UnicodeString S;
  if (GetKeyInfo(Info))
  {
    S.SetLength(Info.MaxValueLen + 1);
    for (DWORD I = 0; I < Info.NumValues; I++)
    {
      DWORD Len = Info.MaxValueLen + 1;
      RegEnumValue(GetCurrentKey(), I, &S[1], &Len, nullptr, nullptr, nullptr, nullptr);
      Strings->Add(S.c_str());
    }
  }
}
Example #11
0
// 统一处理保存(出便于同步处理缓存更新)
int Page::Save(const Ini &pack)
{
    const string &username = m_request->GetCurrentUser();
    UserData save( username );

    // 保存
    if(save.Set( pack ) < 0)
    {
        return ERR;
    }
    // 更新缓存
    const string &key = GetCurrentKey();
    Conf *syn = GetCurrentPack();
    syn->Set( *(pack.Get(key)) );

    return OK;
}
Example #12
0
// 输出http协议头部
int Page_Download::OutHead()
{
    FUNCTION_TRACK(); // 函数轨迹跟综

    Connect * const connect = m_request->GetConnect();
    string filename = m_request->GetField("file");
    string fullpath = "";


    /*
     * 打开用户文件,如:
     *  http://192.168.1.100:17890/download?file=logo.gif
     */
    const string &username = m_request->GetCurrentUser();
    const string &key = GetCurrentKey();
    User *user = User::Get( username );
    fullpath = user->AttachDir() + key + "." + filename;

    LOG_DEBUG("file=[%s]", fullpath.c_str());

    if( "" == filename || !m_file.Open(fullpath) )
    {
        Page::OutHead();

        const string str = HtmlAlert("没有文件: " + filename + ",可能文件已被删除。");
        LOG_ERROR("Can't open file: [%s]", fullpath.c_str());
        // 发送到浏览器
        connect->Send(str);
        return ERR;
    }

    const string &size = IntToString(m_file.Size());

    // 文件下载头部格式
    const string html = ""
                        "HTTP/1.1 200 OK\n"
                        "Accept-Ranges: bytes\n"
                        "Content-Disposition: attachment; filename=\"" + FilenameDecode(filename) + "\"\n"
                        "Content-length: " + size + "\n"
                        "Connection: Keep-Alive\n"
                        "Content-Type: application/ms-excel\n"
                        "\n";

    // 发送
    return connect->Send(html) == html.length() ? OK : ERR;
}
Example #13
0
char* CNWNXHashSet::OnRequest(char* gameObject, char* Request, char* Parameters)
{
    char* presult = NULL;

    Log(2, "Request: \"%s\"\n", Request);
    Log(3, "Params:  \"%s\"\n", Parameters);

    if (strcmp(Request, "LOOKUP") == 0)
        presult = Lookup(gameObject, Parameters);
    else if (strcmp(Request, "INSERT") == 0)
        presult = Insert(gameObject, Parameters);
    else if (strcmp(Request, "DELETE") == 0)
        presult = Delete(gameObject, Parameters);
    else if (strcmp(Request, "STATUS") == 0)
        presult = (char *)(iLastOperation ? "1" : "0");
    else if (strcmp(Request, "VALID") == 0)
        presult = Valid(gameObject, Parameters);
    else if (strcmp(Request, "EXISTS") == 0)
        presult = Exists(gameObject, Parameters);
    else if (strcmp(Request, "GETFIRSTKEY") == 0)
        presult = GetFirstKey(gameObject, Parameters);
    else if (strcmp(Request, "GETNEXTKEY") == 0)
        presult = GetNextKey(gameObject, Parameters);
    else if (strcmp(Request, "GETCURRENTKEY") == 0)
        presult = GetCurrentKey(gameObject, Parameters);
    else if (strcmp(Request, "GETNTHKEY") == 0)
        presult = GetNthKey(gameObject, Parameters);
    else if (strcmp(Request, "HASNEXT") == 0)
        presult = HasNext(gameObject, Parameters);
    else if (strcmp(Request, "GETSIZE") == 0)
        presult = GetSize(gameObject, Parameters);
    else if (strcmp(Request, "DESTROY") == 0)
        presult = Destroy(gameObject, Parameters);
    else if (strcmp(Request, "CREATE") == 0)
        presult = Create(gameObject, Parameters);

    Log(4, "hashset returns[%s]\n", presult);

    // a return value of NULL tells NWNX that it shouldn't copy
    // any values, a non zero pointer tells NWNX that it should copy
    // the null terminated string pointed to by that pointer back into NWN.
    return presult;
}
Example #14
0
/**
 *  \brief Delete the currently active key to action mapping
 *
 *   TODO FIXME This code needs work to support deleteKey
 *              in any mode exc. Context/Action
 */
void MythControls::DeleteKey(void)
{
    QString context = GetCurrentContext();
    QString key     = GetCurrentKey();
    QString action  = GetCurrentAction();

    if (context.isEmpty() || key.isEmpty() || action.isEmpty())
    {
        LOG(VB_GENERAL, LOG_ERR,
            "Unable to delete binding, missing information");
        return;
    }

    if (m_bindings->RemoveActionKey(context, action, key))
    {
        RefreshKeyInformation();
        return;
    }

    QString label = tr("This action is mandatory and needs at least one key "
                       "bound to it. Instead, try rebinding with another key.");

    MythScreenStack *popupStack =
                            GetMythMainWindow()->GetStack("popup stack");

    MythConfirmationDialog *confirmPopup =
            new MythConfirmationDialog(popupStack, label, false);

    if (confirmPopup->Create())
    {
        confirmPopup->SetReturnEvent(this, "mandatorydelete");
        popupStack->AddScreen(confirmPopup);
    }
    else
        delete confirmPopup;
}
Example #15
0
/**
 *  \brief Slot handling a button being pressed in the left list
 */
void MythControls::ActionButtonPressed()
{
    QString key = GetCurrentKey();
    if (!key.isEmpty())
    {
        QString label = tr("Modify Action");

        MythScreenStack *popupStack =
                                GetMythMainWindow()->GetStack("popup stack");

        m_menuPopup =
                new MythDialogBox(label, popupStack, "actionmenu");

        if (m_menuPopup->Create())
            popupStack->AddScreen(m_menuPopup);

        m_menuPopup->SetReturnEvent(this, "action");

        m_menuPopup->AddButton(tr("Set Binding"));
        m_menuPopup->AddButton(tr("Remove Binding"));
    }
    else // for blank keys, no reason to ask what to do
        GrabKey();
}
Example #16
0
bool TRegistry::DeleteKey(const UnicodeString & Key)
{
  bool Result = false;
  UnicodeString S = Key;
  bool Relative = Classes::IsRelative(S);
  HKEY OldKey = GetCurrentKey();
  HKEY DeleteKey = GetKey(Key);
  if (DeleteKey != 0)
  {
    auto cleanup = finally([&]()
    {
      SetCurrentKey(OldKey);
      RegCloseKey(DeleteKey);
    });
    {
      SetCurrentKey(DeleteKey);
      TRegKeyInfo Info;
      if (GetKeyInfo(Info))
      {
        UnicodeString KeyName;
        KeyName.SetLength(Info.MaxSubKeyLen + 1);
        for (intptr_t I = static_cast<intptr_t>(Info.NumSubKeys) - 1; I >= 0; I--)
        {
          DWORD Len = Info.MaxSubKeyLen + 1;
          if (RegEnumKeyEx(DeleteKey, static_cast<DWORD>(I), &KeyName[1], &Len,
                           nullptr, nullptr, nullptr, nullptr) == ERROR_SUCCESS)
          {
            this->DeleteKey(KeyName);
          }
        }
      }
    }
  }
  Result = RegDeleteKey(GetBaseKey(Relative), S.c_str()) == ERROR_SUCCESS;
  return Result;
}
Example #17
0
bool TRegistry::DeleteValue(const UnicodeString & Name) const
{
  bool Result = RegDeleteValue(GetCurrentKey(), Name.c_str()) == ERROR_SUCCESS;
  return Result;
}
Example #18
0
// 输出http协议头部
int Page_DataExport::OutHead()
{
    FUNCTION_TRACK(); // 函数轨迹跟综

    Connect * const connect = m_request->GetConnect();
    const string &username = m_request->GetCurrentUser();
    const string &backup_range = m_request->GetField("backup_range"); // 导出范围
    const string &include_attach = m_request->GetField("include_attach");
    DataPack pack(username);
    string fullpath;
    string filename; // 传到客户端的文件名

    // 是否需是导出附件
    if("yes" != include_attach)
    {
        // 排除附件
        pack.SetAttrib(DataPack::A_EXCLUDE_ATTACH);
    }

    if("all" == backup_range)
    {
        /*
         * 导出所有数据
         */
        if( pack.MakePack() == ERR
            || pack.AddAll() == ERR
          )
        {
            LOG_ERROR("Export data error");
            return ERR;
        }
    }
    else if("select" == backup_range)
    {
        /*
         * 导出选定的数据
         */
        int i;
        vector<string> keys;
        vector<string>::iterator it;
        UserData data( username );
        Split(m_request->GetField("select_key"), " ", keys); // 分割串为数组

        LOG_DEBUG("keys.size=[%d]", keys.size());
        LOG_DEBUG("keys=[%s]", m_request->GetField("select_key").c_str());

        if( pack.MakePack() == ERR )
        {
            LOG_ERROR("Export data error");
            return ERR;
        }

        it = keys.begin();
        while(1)
        {
            if(keys.end() == it)
            {
                break;
            }

            Ini group;

            // 以50个为一组
            for(i=0; i<50 && keys.end() != it; it++)
            {
                const string &key = *it;
                if("" == key)
                {
                    continue;
                }
                group.Set(key, Conf()); // 先填充一空的Conf()
                LOG_DEBUG("key=[%s]", key.c_str());
            }

            // 取key组对应数据
            if( data.Get( group ) < 0 )
            {
                LOG_ERROR("Get data error, username=[%s]", username.c_str());
                return ERR;
            }

            if( pack.Add( group ) == ERR )
            {
                LOG_ERROR("Pack Add error");
                return ERR;
            }
        }// end of while(1...
    }// end of else if("select" ==...
    else
    {
        LOG_ERROR("Range error: [%s]", backup_range.c_str());
        return OK;
    }

    filename = username + "." + GetCurrentKey() + ".pkg";   // 发送到客户端的文件名
    fullpath = pack.PackFinish(); // 打包完成,取包名;
    LOG_DEBUG("fullpath=[%s] filename=[%s]", fullpath.c_str(), filename.c_str());

    // 再次打开打包文件
    if( !m_file.Open(fullpath) )
    {
        Page::OutHead();
        LOG_ERROR("Export error, Can't open file: [%s]", fullpath.c_str());
        return OK;
    }

    const string &size = IntToString(m_file.Size());

    // 文件下载头部格式
    const string html = ""
                        "HTTP/1.1 200 OK\n"
                        "Accept-Ranges: bytes\n"
                        "Content-Disposition: attachment; filename=\"" + filename + "\"\n"
                        "Content-length: " + size + "\n"
                        "Connection: Keep-Alive\n"
                        "Content-Type: application/ms-excel\n"
                        "\n";

    // 发送
    return connect->Send(html) == html.length() ? OK : ERR;
}