Skip to content

Commit

Permalink
17.5.28 Adjusted: Update, Tab
Browse files Browse the repository at this point in the history
  • Loading branch information
tablacus committed May 28, 2017
1 parent 7a6f691 commit 33a0d17
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 34 deletions.
55 changes: 29 additions & 26 deletions Debug/script/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2098,7 +2098,8 @@ GetAddonInfo2 = function (xml, info, Tag, bTrans)
var item = items[0].childNodes;
for (var i = 0; i < item.length; i++) {
var n = item[i].tagName;
info[n] = bTrans && /Name|Description/i.test(n) ? GetText(item[i].text) : item[i].text;
var s = item[i].textContent || item[i].text;
info[n] = (bTrans && /Name|Description/i.test(n) ? GetText(s) : s);
}
}
}
Expand Down Expand Up @@ -2202,29 +2203,31 @@ function GetAddons()

function CheckUpdate()
{
OpenHttpRequest("https://www.eonet.ne.jp/~gakana/tablacus/explorer_en.html", "text/html", CheckUpdate2);
OpenHttpRequest("https://api.github.com/repos/tablacus/TablacusExplorer/releases/latest", "http://www.eonet.ne.jp/~gakana/tablacus/explorer_en.html", CheckUpdate2);
}

function CheckUpdate2(xhr, url)
{
var arg = {};
var res = /<meta http\-equiv="refresh" content="\d+; *URL=([^"]*)/i.exec(xhr.responseText);
var res = /<td id="te">.*?<a href="([^"]+)">.*?\(([\d\.]+)\s*KB.*?<\/td>/i.exec(xhr.responseText);
if (res) {
OpenHttpRequest(res[1], "text/html", CheckUpdate2);
return;
}
res = /<td id="te">(.*?)<\/td>/i.exec(xhr.responseText);
if (!res) {
return;
arg.url = res[1];
arg.size = res[2];
if (!/^https?:/i.test(arg.url)) {
arg.url = url.replace(/[^\/]*$/, '') + arg.url;
}
} else {
var json = !window.JSON ? JSON.parse(xhr.responseText) : (new Function('return ' + xhr.responseText))();
var assets = json.assets;
if (json.assets && json.assets[0]) {
arg.size = json.assets[0]["size"] / 1024;
arg.url = json.assets[0]["browser_download_url"];
}
}
var s = res[1];
res = /<a href="([^"]*)/i.exec(s);
if (!res) {
if (!arg.url) {
return;
}
var uri = res[1];
arg.file = fso.GetFileName(uri.replace(/\//g, "\\"));
s = s.replace(/Download/i, "").replace(/<[^>]*>/ig, "");
arg.file = fso.GetFileName(arg.url.replace(/\//g, "\\"));
var ver = 0;
res = /(\d+)/.exec(arg.file);
if (res) {
Expand All @@ -2236,6 +2239,7 @@ function CheckUpdate2(xhr, url)
return;
}
}
var s = api.sprintf(99, "Version %d.%d.%d (%.1lfKB)", ver / 10000 % 100, ver / 100 % 100, ver % 100, arg.size);
if (!confirmOk([GetText("Update available"), s, GetText("Do you want to install it now?")].join("\n"))) {
return;
}
Expand All @@ -2247,10 +2251,7 @@ function CheckUpdate2(xhr, url)
arg.temp += "\\explorer";
DeleteItem(arg.temp);
CreateFolder2(arg.temp);
if (!/^https?:/i.test(uri)) {
uri = url.replace(/[^\/]*$/, '') + uri;
}
OpenHttpRequest(uri, "application/zip", CheckUpdate3, arg);
OpenHttpRequest(arg.url, "http", CheckUpdate3, arg);
}

function CheckUpdate3(xhr, url, arg)
Expand Down Expand Up @@ -2319,33 +2320,34 @@ MessageBox = function (s, title, uType)
createHttpRequest = function ()
{
try {
return te.CreateObject("Msxml2.XMLHTTP");
return window.XMLHttpRequest ? new XMLHttpRequest() : te.CreateObject("Msxml2.XMLHTTP");
} catch (e) {
return te.CreateObject("Microsoft.XMLHTTP");
}
}

OpenHttpRequest = function (url, ct, fn, arg)
OpenHttpRequest = function (url, alt, fn, arg)
{
var xhr = createHttpRequest();
xhr.onreadystatechange = function()
{
if (xhr.readyState == 4) {
if (xhr.status == 200) {
fn(xhr, url, arg);
return fn(xhr, url, arg);
}
if (/^http/.test(alt)) {
return OpenHttpRequest(/^https/.test(url) && alt == "http" ? url.replace(/^https/, alt) : alt, '', fn, arg);
}
MessageBox([api.sprintf(999, api.LoadString(hShell32, 4227).replace(/^\t/, ""), xhr.status), url].join("\n\n"), TITLE, MB_OK | MB_ICONSTOP);
}
}
xhr.open("GET", url + "?" + Math.floor(new Date().getTime() / 60000), false);
xhr.setRequestHeader('Content-Type', ct);
xhr.setRequestHeader('Pragma', 'no-cache');
xhr.setRequestHeader('Cache-Control', 'no-store');
xhr.setRequestHeader('Expires', '0');
try {
xhr.send(null);
} catch (e) {
MessageBox([api.LoadString(hShell32, 4227).replace(/^\t/, "").replace("%d", api.sprintf(99, "0x%08x", e.number)), url].join("\n\n"), TITLE, MB_OK | MB_ICONSTOP);
}
} catch (e) {}
}

InputDialog = function (text, defaultText)
Expand Down Expand Up @@ -2447,6 +2449,7 @@ AddonOptions = function (Id, fn, Data)
el.style.cssText = 'width: 100%; border: 0; padding: 0; margin: 0';
g_.elAddons[Id] = el;
var o = document.getElementById('panel1_2');
o.style.display = "block";
o.appendChild(el);
o = document.getElementById('tab1_');
o.insertAdjacentHTML("BeforeEnd", '<label id="tab1_' + Id + '" class="button" style="width: 100%" onmousedown="ClickTree(this);">'+ info.Name +'</label><br />');
Expand Down
6 changes: 3 additions & 3 deletions Debug/script/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@
</div>
<!--panel_end-->

<div class="panel" id="panel1_2" style="padding: 0; border: 0; display: block">
<div class="panel" id="panel1_2" style="padding: 0">
</div>
<!--panel_end-->

<div class="panel" id="panel2">
<table style="width: 100%">
<tr>
<td width="12em" valign="top">
<td style="width: 12em; vertical-align: top">
<select name="Menus" style="display: none">
</select>
<div id="Menus_List">
Expand Down Expand Up @@ -256,7 +256,7 @@
</td>
</tr>
</table>
<table width="100%">
<table style="width: 100%">
<tr>
<td>
<input type="button" value="Remove" onclick="RemoveX('Menus')" />
Expand Down
4 changes: 2 additions & 2 deletions Debug/script/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2195,7 +2195,7 @@ function GetTextEx(s)

function GetAddons()
{
OpenHttpRequest(urlAddons + "index.xml", "text/xml", AddonsList);
OpenHttpRequest(urlAddons + "index.xml", "http", AddonsList);
}

function UpdateAddon(Id, o)
Expand Down Expand Up @@ -2361,7 +2361,7 @@ function Install(o, bUpdate)
return;
}
var file = o.title.replace(/\./, "") + '.zip';
OpenHttpRequest(urlAddons + Id + '/' + file, "application/zip", Install2, o);
OpenHttpRequest(urlAddons + Id + '/' + file, "http", Install2, o);
}

function Install2(xhr, url, o)
Expand Down
2 changes: 1 addition & 1 deletion TE/Resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
#define STRING2(str) #str
#define VER_Y 17
#define VER_M 5
#define VER_D 24
#define VER_D 28
31 changes: 29 additions & 2 deletions TE/TE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8538,7 +8538,8 @@ VOID teApiURLDownloadToFile(int nArg, teParam *param, DISPPARAMS *pDispParams, V
if (GetDispatch(&pDispParams->rgvarg[nArg - 1], &pdisp)) {
HRESULT hr = E_FAIL;
VARIANT v;
if SUCCEEDED(teGetProperty(pdisp, L"responseStream", &v)) {
//XMLHTTPRequest does not support responseStream.
/* if SUCCEEDED(teGetProperty(pdisp, L"responseStream", &v)) {
if (FindUnknown(&v, &punk)) {
IStream *pDst, *pSrc;
hr = punk->QueryInterface(IID_PPV_ARGS(&pSrc));
Expand All @@ -8552,6 +8553,23 @@ VOID teApiURLDownloadToFile(int nArg, teParam *param, DISPPARAMS *pDispParams, V
}
}
VariantClear(&v);
} else
*/
if SUCCEEDED(teGetProperty(pdisp, L"responseBody", &v)) {
UCHAR *pc;
int nLen = 0;
GetpDataFromVariant(&pc, &nLen, &v);
if (pc) {
HANDLE hFile = CreateFile(param[2].bstrVal, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE) {
DWORD dwWriteByte;
if (WriteFile(hFile, pc, nLen, &dwWriteByte, NULL)) {
hr = S_OK;
}
CloseHandle(hFile);
}
}
VariantClear(&v);
}
pdisp->Release();
teSetLong(pVarResult, hr);
Expand Down Expand Up @@ -16750,7 +16768,16 @@ STDMETHODIMP CteTabCtrl::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WOR
return S_OK;
//Count
case DISPID_TE_COUNT:
teSetLong(pVarResult, TabCtrl_GetItemCount(m_hwnd));
if (pVarResult) {
int nCount = TabCtrl_GetItemCount(m_hwnd);
if (nCount == 1) {
CteShellBrowser *pSB = GetShellBrowser(0);
if (!pSB || pSB->m_bEmpty) {
nCount = 0;
}
}
teSetLong(pVarResult, nCount);
}
return S_OK;
//_NewEnum
case DISPID_NEWENUM:
Expand Down

0 comments on commit 33a0d17

Please sign in to comment.