Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 30 additions & 29 deletions src/shares.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-FileCopyrightText: 2023 Open Salamander Authors
// SPDX-License-Identifier: GPL-2.0-or-later
// CommentsTranslationProject: TRANSLATED

#include "precomp.h"
#include <lm.h>
Expand All @@ -17,16 +18,16 @@ CSharesItem::CSharesItem(const char* localPath, const char* remoteName, const ch
{
char buff[MAX_PATH];
lstrcpyn(buff, localPath, MAX_PATH);
SalPathAddBackslash(buff, MAX_PATH); // kdyby nahodou bylo jen "c:", tak aby vznikl root
if (SalGetFullName(buff)) // root "c:\\", ostatni bez '\\' na konci
SalPathAddBackslash(buff, MAX_PATH); // in case it was only "c:", make sure a root is created
if (SalGetFullName(buff)) // root "c\\", others without the trailing '\\' at the end
{
LocalPath = DupStr(buff);
RemoteName = DupStr(remoteName);
Comment = DupStr(comment);
if (LocalPath != NULL && RemoteName != NULL && Comment != NULL)
{
char* s = strrchr(LocalPath, '\\');
if (s == NULL || *(s + 1) == 0) // root cesta; s==NULL je pouze pro jistotu, ale nikdy nemuze vyjit
if (s == NULL || *(s + 1) == 0) // root path; s == NULL is only for safety, but it can never happen
LocalName = LocalPath;
else
LocalName = s + 1;
Expand Down Expand Up @@ -61,7 +62,7 @@ void CSharesItem::Cleanup()
void CSharesItem::Destroy()
{
if (LocalPath != NULL)
free(LocalPath); // LocalName ukazuje do LocalPath, proto jej neuvolnujeme
free(LocalPath); // LocalName points into LocalPath, so we do not free it
if (RemoteName != NULL)
free(RemoteName);
if (Comment != NULL)
Expand All @@ -73,7 +74,7 @@ void CSharesItem::Destroy()
// CShares
//

/* Sekce nacteni sharu */
/* Share loading section */

void CShares::Refresh()
{
Expand All @@ -96,29 +97,29 @@ void CShares::Refresh()
char netname[MAX_PATH];
char path[MAX_PATH];
char remark[MAX_PATH];
// special nechceme, protoze je Explorer neukazuje
// we do not want specials because Explorer does not show them
BOOL include = p->shi502_type == 0;
if (!SubsetOnly && p->shi502_type == 0x80000000) // special
if (!SubsetOnly && p->shi502_type == 0x80000000) // special share
include = TRUE;
if (include &&
WideCharToMultiByte(CP_ACP, 0, p->shi502_netname, -1, netname, MAX_PATH, NULL, NULL) &&
WideCharToMultiByte(CP_ACP, 0, p->shi502_path, -1, path, MAX_PATH, NULL, NULL) &&
WideCharToMultiByte(CP_ACP, 0, p->shi502_remark, -1, remark, MAX_PATH, NULL, NULL))
{
// TRACE_I("Share: " << netname << " = " << path);
// pridani sharovane cesty do pole Data
// add the shared path to the Data array
CSharesItem* item = new CSharesItem(path, netname, remark);
if (item != NULL && item->IsGood())
{
Data.Add(item);
if (Data.IsGood())
item = NULL; // uspesne pridani
item = NULL; // added successfully
else
{
delete item;
Data.ResetState();
Data.DestroyMembers();
break; // chyba, nema smysl pokracovat v enumu
break; // error, no point in continuing the enumeration
}
}
if (item != NULL)
Expand Down Expand Up @@ -160,7 +161,7 @@ BOOL CShares::GetWantedIndex(const char* name, int& index)
m = (l + r) / 2;
char* hw = Wanted[m]->LocalName;
int res = StrICmp(hw, name);
if (res == 0) // nalezeno
if (res == 0) // found
{
index = m;
return TRUE;
Expand All @@ -169,18 +170,18 @@ BOOL CShares::GetWantedIndex(const char* name, int& index)
{
if (res > 0)
{
if (l == r || l > m - 1) // nenalezeno
if (l == r || l > m - 1) // not found
{
index = m; // mel by byt na teto pozici
index = m; // should be at this position
return FALSE;
}
r = m - 1;
}
else
{
if (l == r) // nenalezeno
if (l == r) // not found
{
index = m + 1; // mel by byt az za touto pozici
index = m + 1; // should be after this position
return FALSE;
}
l = m + 1;
Expand All @@ -192,14 +193,14 @@ BOOL CShares::GetWantedIndex(const char* name, int& index)
void CShares::PrepareSearch(const char* path)
{
HANDLES(EnterCriticalSection(&CS));
// vyprazdnime pole Wanted
// empty the Wanted array
Wanted.DestroyMembers();

// zaradime do nej pouze ty shary, ktere lezi na pozadovane ceste
// put in only the shares that lie on the requested path
char buff[MAX_PATH];
lstrcpyn(buff, path, MAX_PATH);
if (buff[0] != 0) // pokud hledame shary z this_computer nesmime pripojit backslash
SalPathAddBackslash(buff, MAX_PATH); // na konci chceme backslash
if (buff[0] != 0) // when we search for shares from this_computer, we must not append a backslash
SalPathAddBackslash(buff, MAX_PATH); // we want a backslash at the end
int pathLen = (int)strlen(buff);

int i;
Expand All @@ -210,7 +211,7 @@ void CShares::PrepareSearch(const char* path)
if (pathLen == itemNameLen && StrNICmp(item->LocalPath, buff, itemNameLen) == 0)
{
int index;
if (!GetWantedIndex(item->LocalName, index)) // odpovidajici share zaradime do pole Wanted jen pokud jiz tam neni
if (!GetWantedIndex(item->LocalName, index)) // add the matching share to Wanted array only if it is not already there
{
Wanted.Insert(index, item);
}
Expand All @@ -233,9 +234,9 @@ BOOL CShares::GetUNCPath(const char* path, char* uncPath, int uncPathMax)
HANDLES(EnterCriticalSection(&CS));
char buff[MAX_PATH];
lstrcpyn(buff, path, MAX_PATH);
SalPathAddBackslash(buff, MAX_PATH); // na konci chceme backslash
SalPathAddBackslash(buff, MAX_PATH); // we want a backslash at the end

int longestIndex = -1; // index do pole Data, kde lezi nejdelsi vyhovujici share
int longestIndex = -1; // index into Data array holding the longest matching share

int i;
for (i = 0; i < Data.Count; i++)
Expand All @@ -244,32 +245,32 @@ BOOL CShares::GetUNCPath(const char* path, char* uncPath, int uncPathMax)
int itemNameLen = (int)strlen(item->LocalPath);
if (StrNICmp(buff, item->LocalPath, itemNameLen) == 0)
{
// hledame nejdelsi mozny share, ktery jeste odpovida pozadovane 'path'
// look for the longest possible share that still matches the requested 'path'
if (longestIndex == -1 || (int)strlen(Data[longestIndex]->LocalPath) < itemNameLen)
longestIndex = i;
}
}
if (longestIndex != -1)
{
CSharesItem* item = Data[longestIndex];
// vlozime nazev naseho pocitace
// insert the name of our computer
char unc[2 * MAX_PATH];
strcpy(unc, "\\\\");
DWORD len = MAX_PATH;
GetComputerName(unc + 2, &len);
strcat(unc, "\\");
// pripojime nazev sharu
// append the share name
strcat(unc, item->RemoteName);
SalPathAddBackslash(unc, 2 * MAX_PATH); // na konci chceme backslash
// z puvodni cesty pripojime adresare od sdileni dale
SalPathAddBackslash(unc, 2 * MAX_PATH); // we want a backslash at the end
// from the original path, append the directories starting from the share
if (strlen(item->LocalPath) < strlen(path))
{
const char* s = path + strlen(item->LocalPath);
if (*s == '\\')
s++; // preskocime pripadny backslash
s++; // skip an optional backslash
strcat(unc, s);
}
if (!SalGetFullName(unc)) // root "c:\\", ostatni bez '\\' na konci
if (!SalGetFullName(unc)) // root "c\\", others without the trailing '\\' at the end
{
TRACE_E("Unexpected path in CSharesItem::GetUNCPath()");
HANDLES(LeaveCriticalSection(&CS));
Expand Down