mirror of
https://github.com/eliboa/TegraRcmGUI.git
synced 2024-11-24 19:22:04 +00:00
Use relative paths for favorites
This commit is contained in:
parent
c45f13e083
commit
2516e8192d
4 changed files with 170 additions and 15 deletions
|
@ -107,14 +107,19 @@ BOOL DialogTab01::OnInitDialog()
|
|||
for (int i = 0; i < m_TegraRcm->Favorites.GetCount(); i++)
|
||||
{
|
||||
CListBox*pListBox = (CListBox*)GetDlgItem(IDC_LIST1);
|
||||
|
||||
int nIndex = m_TegraRcm->Favorites[i].ReverseFind(_T('\\'));
|
||||
CString fav = m_TegraRcm->Favorites[i];
|
||||
int nIndex = fav.ReverseFind(_T('\\'));
|
||||
CString csFilename, csPath, Item;
|
||||
if (nIndex > 0)
|
||||
{
|
||||
CString csFilename, csPath, Item;
|
||||
csFilename = m_TegraRcm->Favorites[i].Right(m_TegraRcm->Favorites[i].GetLength() - nIndex - 1);
|
||||
csPath = m_TegraRcm->Favorites[i].Left(nIndex);
|
||||
csFilename = fav.Right(fav.GetLength() - nIndex - 1);
|
||||
csPath = fav.Left(nIndex);
|
||||
Item = csFilename + _T(" (") + csPath + _T(")");
|
||||
}
|
||||
else
|
||||
{
|
||||
Item = fav;
|
||||
}
|
||||
pListBox->AddString(_tcsdup(Item));
|
||||
|
||||
wstring wcsPath(csPath);
|
||||
|
@ -122,7 +127,6 @@ BOOL DialogTab01::OnInitDialog()
|
|||
m_TegraRcm->AppendLog("Add favorites to listbox");
|
||||
m_TegraRcm->AppendLog(scsPath);
|
||||
}
|
||||
}
|
||||
|
||||
CFont* pFont = GetFont();
|
||||
LOGFONT lf;
|
||||
|
|
|
@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||
SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "stdafx.h"
|
||||
#include "TegraRcm.h"
|
||||
|
||||
|
@ -370,6 +370,27 @@ void TegraRcm::GetFavorites()
|
|||
string sfav(wfav.begin(), wfav.end());
|
||||
AppendLog("Append new favorite : ");
|
||||
AppendLog(sfav);
|
||||
|
||||
// For relative path
|
||||
int nIndex = fav.ReverseFind(_T(':'));
|
||||
if (nIndex <= 0)
|
||||
{
|
||||
// Get current directory
|
||||
CString csPath;
|
||||
TCHAR szPath[_MAX_PATH];
|
||||
VERIFY(::GetModuleFileName(AfxGetApp()->m_hInstance, szPath, _MAX_PATH));
|
||||
CString csPathf(szPath);
|
||||
int nIndex = csPathf.ReverseFind(_T('\\'));
|
||||
if (nIndex > 0) csPath = csPathf.Left(nIndex);
|
||||
csPath.Append(_T("\\"));
|
||||
csPath.Append(fav);
|
||||
fav = csPath;
|
||||
// Get absolute path
|
||||
TCHAR buffer[4096] = TEXT("");
|
||||
GetFullPathName(fav, 4096, buffer, NULL);
|
||||
fav = buffer;
|
||||
}
|
||||
|
||||
Favorites.Add(fav);
|
||||
}
|
||||
}
|
||||
|
@ -379,6 +400,28 @@ void TegraRcm::GetFavorites()
|
|||
}
|
||||
void TegraRcm::AddFavorite(CString value)
|
||||
{
|
||||
// Get current directory
|
||||
CString csPath;
|
||||
TCHAR szPath[_MAX_PATH];
|
||||
VERIFY(::GetModuleFileName(AfxGetApp()->m_hInstance, szPath, _MAX_PATH));
|
||||
CString csPathf(szPath);
|
||||
int nIndex = csPathf.ReverseFind(_T('\\'));
|
||||
if (nIndex > 0) csPath = csPathf.Left(nIndex);
|
||||
else csPath.Empty();
|
||||
|
||||
CT2A pPath(csPath.GetBuffer(csPath.GetLength()));
|
||||
CT2A pvalue(value.GetBuffer(value.GetLength()));
|
||||
char* rvalue = GetRelativeFilename(pPath, pvalue);
|
||||
value = rvalue;
|
||||
|
||||
/*
|
||||
if (value.Find(csPath) != -1)
|
||||
{
|
||||
csPath.Append(_T("\\"));
|
||||
value.Replace(csPath, _T(""));
|
||||
}
|
||||
*/
|
||||
|
||||
CString CoutLine(value + _T('\n'));
|
||||
CT2CA pszConvertedAnsiString(CoutLine);
|
||||
std::string outLine = pszConvertedAnsiString;
|
||||
|
@ -792,3 +835,110 @@ TCHAR* TegraRcm::GetAbsolutePath(TCHAR* relative_path, DWORD dwFlags)
|
|||
return _T("");
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
// GetRelativeFilename(), by Rob Fisher.
|
||||
// rfisher@iee.org
|
||||
// http://come.to/robfisher
|
||||
// defines
|
||||
#define MAX_FILENAME_LEN 512
|
||||
// The number of characters at the start of an absolute filename. e.g. in DOS,
|
||||
// absolute filenames start with "X:\" so this value should be 3, in UNIX they start
|
||||
// with "\" so this value should be 1.
|
||||
#define ABSOLUTE_NAME_START 3
|
||||
// set this to '\\' for DOS or '/' for UNIX
|
||||
#define SLASH '\\'
|
||||
// Given the absolute current directory and an absolute file name, returns a relative file name.
|
||||
// For example, if the current directory is C:\foo\bar and the filename C:\foo\whee\text.txt is given,
|
||||
// GetRelativeFilename will return ..\whee\text.txt.
|
||||
char* TegraRcm::GetRelativeFilename(char *currentDirectory, char *absoluteFilename)
|
||||
{
|
||||
// declarations - put here so this should work in a C compiler
|
||||
int afMarker = 0, rfMarker = 0;
|
||||
int cdLen = 0, afLen = 0;
|
||||
int i = 0;
|
||||
int levels = 0;
|
||||
static char relativeFilename[MAX_FILENAME_LEN + 1];
|
||||
cdLen = strlen(currentDirectory);
|
||||
afLen = strlen(absoluteFilename);
|
||||
|
||||
// make sure the names are not too long or too short
|
||||
if (cdLen > MAX_FILENAME_LEN || cdLen < ABSOLUTE_NAME_START + 1 ||
|
||||
afLen > MAX_FILENAME_LEN || afLen < ABSOLUTE_NAME_START + 1)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Handle DOS names that are on different drives:
|
||||
if (currentDirectory[0] != absoluteFilename[0])
|
||||
{
|
||||
// not on the same drive, so only absolute filename will do
|
||||
strcpy(relativeFilename, absoluteFilename);
|
||||
return relativeFilename;
|
||||
}
|
||||
// they are on the same drive, find out how much of the current directory
|
||||
// is in the absolute filename
|
||||
i = ABSOLUTE_NAME_START;
|
||||
while (i < afLen && i < cdLen && currentDirectory[i] == absoluteFilename[i])
|
||||
{
|
||||
i++;
|
||||
}
|
||||
if (i == cdLen && (absoluteFilename[i] == SLASH || absoluteFilename[i - 1] == SLASH))
|
||||
{
|
||||
// the whole current directory name is in the file name,
|
||||
// so we just trim off the current directory name to get the
|
||||
// current file name.
|
||||
if (absoluteFilename[i] == SLASH)
|
||||
{
|
||||
// a directory name might have a trailing slash but a relative
|
||||
// file name should not have a leading one...
|
||||
i++;
|
||||
}
|
||||
strcpy(relativeFilename, &absoluteFilename[i]);
|
||||
return relativeFilename;
|
||||
}
|
||||
// The file is not in a child directory of the current directory, so we
|
||||
// need to step back the appropriate number of parent directories by
|
||||
// using "..\"s. First find out how many levels deeper we are than the
|
||||
// common directory
|
||||
afMarker = i;
|
||||
levels = 1;
|
||||
// count the number of directory levels we have to go up to get to the
|
||||
// common directory
|
||||
while (i < cdLen)
|
||||
{
|
||||
i++;
|
||||
if (currentDirectory[i] == SLASH)
|
||||
{
|
||||
// make sure it's not a trailing slash
|
||||
i++;
|
||||
if (currentDirectory[i] != '\0')
|
||||
{
|
||||
levels++;
|
||||
}
|
||||
}
|
||||
}
|
||||
// move the absolute filename marker back to the start of the directory name
|
||||
// that it has stopped in.
|
||||
while (afMarker > 0 && absoluteFilename[afMarker - 1] != SLASH)
|
||||
{
|
||||
afMarker--;
|
||||
}
|
||||
// check that the result will not be too long
|
||||
if (levels * 3 + afLen - afMarker > MAX_FILENAME_LEN)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// add the appropriate number of "..\"s.
|
||||
rfMarker = 0;
|
||||
for (i = 0; i < levels; i++)
|
||||
{
|
||||
relativeFilename[rfMarker++] = '.';
|
||||
relativeFilename[rfMarker++] = '.';
|
||||
relativeFilename[rfMarker++] = SLASH;
|
||||
}
|
||||
// copy the rest of the filename into the result string
|
||||
strcpy(&relativeFilename[rfMarker], &absoluteFilename[afMarker]);
|
||||
return relativeFilename;
|
||||
}
|
|
@ -40,6 +40,7 @@ public:
|
|||
void BitmapDisplay(int IMG);
|
||||
void LookUp();
|
||||
int Smasher(TCHAR args[]);
|
||||
char* GetRelativeFilename(char *currentDirectory, char *absoluteFilename);
|
||||
|
||||
BOOL CmdShow = TRUE;
|
||||
// Notify Icon
|
||||
|
|
|
@ -90,7 +90,7 @@
|
|||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(LIBUSBK_DIR)\includes\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
|
@ -145,7 +145,7 @@
|
|||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_WINDOWS;_CRT_SECURE_NO_WARNINGS;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(LIBUSBK_DIR)\includes\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
|
|
Loading…
Reference in a new issue