Skip to content

Commit

Permalink
Update version ctl
Browse files Browse the repository at this point in the history
  • Loading branch information
cinience committed Jan 6, 2015
1 parent 4f02bf5 commit 20db2cc
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 28 deletions.
12 changes: 6 additions & 6 deletions RedisStudio/Base/Http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Http::Response Http::post(const std::string& path, const std::string& data)
Response res;
res.status = -1;

char buffer[1024];
char buffer[1024] = {0};
struct sockaddr_in serveraddr;
int sock;

Expand All @@ -64,8 +64,7 @@ Http::Response Http::post(const std::string& path, const std::string& data)
//request2 << "" << endl;
request2 << "Host: " << _host << endl;
request2 << "Content-Length: " << data.length() << endl;
request2 << "Content-Type: application/xfo-www-rm-urlencoded" << endl;
request2 << "Accept-Language: en-au" << endl;
request2 << "Content-Type: application/json;charset=utf-8" << endl;
request2 << endl;
request2 << data;
request = request2.str();
Expand Down Expand Up @@ -104,7 +103,7 @@ Http::Response Http::post(const std::string& path, const std::string& data)
//disconnect
closesocket(sock);

String::TSeqStr seq;
String::TSeqStr seq;
String::Split(response, "\n", seq);
if (seq.size() == 0) {
res.status = -1;
Expand All @@ -117,9 +116,10 @@ Http::Response Http::post(const std::string& path, const std::string& data)
res.status = atoi(hdrseq[1].c_str());
}
if (res.status == 200) {
res.data = seq[seq.size()-1];
char *p = strstr(buffer, "\r\n\r\n") + 4;
res.data = p;
}
return res;
}

} // namespace Base
} // namespace Base
47 changes: 45 additions & 2 deletions RedisStudio/Base/Util.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include "StdAfx.h"
#include "Util.h"
#include <winsock2.h>
#include <Iphlpapi.h>
#pragma comment(lib,"Iphlpapi.lib") /// for GetAdaptersInfo

namespace Base {

std::string Util::HumanReadableTimeDuration(long long seconds)
std::string Util::convertHumanTimeDuration(long long seconds)
{
std::stringstream sb;
if (seconds == 0) {
Expand Down Expand Up @@ -40,4 +43,44 @@ std::string Util::HumanReadableTimeDuration(long long seconds)
return sb.str();
}

} // namespace Base
std::string Util::getPCID()
{
BYTE szSystemInfo[4096] = {0};
UINT uSystemInfoLen = 0;
UINT uErrorCode = 0;
IP_ADAPTER_INFO iai;
ULONG uSize = 0;
std::string nicID ;
DWORD dwResult = GetAdaptersInfo( &iai, &uSize );
if( dwResult != ERROR_BUFFER_OVERFLOW )
{
return nicID;
}
IP_ADAPTER_INFO* piai = ( IP_ADAPTER_INFO* )HeapAlloc( GetProcessHeap(), 0, uSize );
if( piai == NULL )
{
return nicID;
}
dwResult = GetAdaptersInfo( piai, &uSize );
if(ERROR_SUCCESS == dwResult)
{
IP_ADAPTER_INFO* piai2 = piai;
while( piai2 != NULL && ( uSystemInfoLen + piai2->AddressLength ) < 4096U )
{
CopyMemory( szSystemInfo + uSystemInfoLen, piai2->Address, piai2->AddressLength );
uSystemInfoLen += piai2->AddressLength;
piai2 = piai2->Next;
}
}
HeapFree( GetProcessHeap(), 0, piai);
char buf[124] = {0};
for (UINT idx = 0; idx < uSystemInfoLen; ++idx)
{
memset(buf, 0 , sizeof(buf));
sprintf(buf, "%02X",szSystemInfo[idx]);
nicID += buf;
}
return nicID;
}

} // namespace Base
6 changes: 4 additions & 2 deletions RedisStudio/Base/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ namespace Base {
class Util {

public:
static std::string HumanReadableTimeDuration(long long seconds);
static std::string convertHumanTimeDuration(long long seconds);

static std::string getPCID();
};

} // namespace Base

#endif
#endif
59 changes: 48 additions & 11 deletions RedisStudio/MainFrameWhd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

#include "Base/Http.h"
#include "Base/CharacterSet.h"
#include "Base/Util.h"

#include "rapidjson/document.h" // rapidjson's DOM-style API
#include "rapidjson/prettywriter.h" // for stringify JSON
#include "rapidjson/stringbuffer.h"
using namespace rapidjson;

DUI_BEGIN_MESSAGE_MAP(CMainFrameWnd, WindowImplBase)
DUI_ON_MSGTYPE(DUI_MSGTYPE_CLICK,OnClick)
Expand Down Expand Up @@ -121,7 +127,7 @@ DuiLib::UILIB_RESOURCETYPE CMainFrameWnd::GetResourceType() const

LPCTSTR CMainFrameWnd::GetResourceID() const
{
return MAKEINTRESOURCE(IDR_ZIP_SKIN);
return MAKEINTRESOURCE(IDR_ZIP_SKIN);
}

CControlUI* CMainFrameWnd::CreateControl(LPCTSTR pstrClassName)
Expand Down Expand Up @@ -320,21 +326,57 @@ LRESULT CMainFrameWnd::OnConnecting( HWND hwnd, WPARAM wParam, LPARAM lParam )

LRESULT CMainFrameWnd::OnUpdate(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
UserMessageBox(GetHWND(), 20000, NULL, MB_ICONINFORMATION);
::ShellExecute(NULL, NULL, _T("https://github.com/cinience/RedisStudio/releases"), NULL, NULL, NULL);
std::string *data = (std::string*) (wParam);
StringStream ss(data->c_str());
Document document;
if (document.ParseStream<0>(ss).HasParseError())
{
delete data;
return TRUE;
}
bool needNotice = false;
if (document.HasMember("Notice"))
{
needNotice = document["Notice"].GetBool();
}
if (needNotice)
{
std::string version;
if (document.HasMember("Version"))
{
version = document["Version"].GetString();
}
if (version > VERSION) {
UserMessageBox(GetHWND(), 20000, Base::CharacterSet::ANSIToUnicode(version).c_str(), MB_ICONINFORMATION);
//::ShellExecute(NULL, NULL, _T("https://github.com/cinience/RedisStudio/releases"), NULL, NULL, NULL);
}
}
delete data;
return TRUE;
}

DWORD WINAPI CMainFrameWnd::BackgroundWork( LPVOID lpParameter )
{
std::string code = Base::Util::getPCID();
StringBuffer buffer;
PrettyWriter<StringBuffer> writer(buffer);
writer.StartObject();
writer.String("Version");
writer.String(VERSION);

writer.String("MCode");
writer.String(code.c_str());

writer.EndObject();
Base::Http http("hiredis.com", 80);
Base::Http::Response rep = {0, ""};
if (http.ping()) {
rep = http.post("/redisstudio/version", "");
rep = http.post("/redisstudio/version", buffer.GetString());
}

if (rep.status == 200 && rep.data.size() > 2 && rep.data != VERSION) {
::PostMessage(m_hwnd, WM_USER_UPDATE, (WPARAM)NULL, NULL);
if (rep.status == 200 && rep.data.size() > 0) {
std::string *data = new std::string(rep.data);
::PostMessage(m_hwnd, WM_USER_UPDATE, (WPARAM)data, NULL);
}
return 0;
}
Expand Down Expand Up @@ -376,8 +418,3 @@ LRESULT CMainFrameWnd::HandleCustomMessage( UINT uMsg, WPARAM wParam, LPARAM lPa
}
return lRes;
}





17 changes: 11 additions & 6 deletions RedisStudio/RedisDataUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ RedisDataUI::RedisDataUI( const CDuiString& strXML, CPaintManagerUI* pm ):Abstra
{
CDialogBuilder builder;
CControlUI* pContainer = builder.Create(strXML.GetData(), NULL, NULL, GetPaintMgr(), NULL);
if( pContainer ) {
if( pContainer )
{
this->Add(pContainer);
}
else
Expand Down Expand Up @@ -162,7 +163,8 @@ void RedisDataUI::RefreshWnd()

bool RedisDataUI::CanChange()
{
if (m_Thread.isRunning()) {
if (m_Thread.isRunning())
{
return false;
}
return true;
Expand Down Expand Up @@ -230,8 +232,10 @@ void RedisDataUI::OnItemDBClick(TNotifyUI &msg)
if (m_bIsKeyRender) return;

/// 非叶子节点并未加载子节点,则加载子节点
if (pActiveNode->GetTag() != 0 && !pActiveNode->IsHasChild()) {
if (m_Thread.isRunning()) {
if (pActiveNode->GetTag() != 0 && !pActiveNode->IsHasChild())
{
if (m_Thread.isRunning())
{
UserMessageBox(GetHWND(), 10012, NULL, MB_ICONINFORMATION);
return;
}
Expand Down Expand Up @@ -681,7 +685,7 @@ void RedisDataUI::BackgroundWorkForRefreshValues(void)
{
m_RedisData.ttl.Append(_T(" "));
m_RedisData.ttl.Append(_T("("));
m_RedisData.ttl.Append(Base::CharacterSet::ANSIToUnicode(Base::Util::HumanReadableTimeDuration(ttl)).c_str());
m_RedisData.ttl.Append(Base::CharacterSet::ANSIToUnicode(Base::Util::convertHumanTimeDuration(ttl)).c_str());
m_RedisData.ttl.Append(_T(")"));
}
/// 预先显示数据类型等信息
Expand Down Expand Up @@ -981,4 +985,5 @@ CTreeNodeUI* RedisDataUI::NewNode(const string& text, bool isLeaf)
{
pNode->RemoveAt((CTreeNodeUI*)myArray[i]);
}
}
}

2 changes: 1 addition & 1 deletion Skin/skin-en/MessageBox.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<Label name="lbl_msg_10030" visible="false" inset="8,2,2,0" text="The key doesn't exist, Please reload." height="32"/>
<Label name="lbl_msg_10031" visible="false" inset="8,2,2,0" text="Failed to update the data." height="32"/>

<Label name="lbl_msg_20000" visible="false" inset="8,2,2,0" text="A new version of RedisStudio is available." height="32"/>
<Label name="lbl_msg_20000" visible="false" inset="8,2,2,0" text="A new version $ of RedisStudio is available." height="32"/>
<Label name="lbl_msg_20001" visible="false" inset="8,2,2,0" text="In development!" height="32"/>
<Label name="lbl_msg_20002" visible="false" inset="8,2,2,0" text="Please click to select the item." height="32"/>
<Label name="lbl_msg_20003" visible="false" inset="8,2,2,0" text="save conf failed.(Insufficient permissions?)" height="32"/>
Expand Down

0 comments on commit 20db2cc

Please sign in to comment.