Fixed detection of files in kdiff3_part.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
(cherry picked from commit caa6e33141)
r14.0.x
Michele Calgaro 4 years ago
parent 7817ecad88
commit f756c5c1ec
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -46,7 +46,14 @@
ProgressDialog* g_pProgressDialog=0;
FileAccess::FileAccess( const TQString& name, bool bWantToWrite )
FileAccess::FileAccess( const TQString& name, bool bWantToWrite ) :
m_workingDir(TQString::null)
{
setFile( name, bWantToWrite );
}
FileAccess::FileAccess( const TQString& workingDir, const TQString& name, bool bWantToWrite ) :
m_workingDir(workingDir)
{
setFile( name, bWantToWrite );
}
@ -111,7 +118,15 @@ void FileAccess::setFile( const TQString& name, bool bWantToWrite )
// 1. When the local file exists and the remote location is wanted nevertheless. (unlikely)
// 2. When the local file doesn't exist and should be written to.
bool bExistsLocal = TQDir().exists(name);
bool bExistsLocal = false;
if (!m_workingDir.isEmpty())
{
bExistsLocal = TQDir(m_workingDir).exists(name);
}
else
{
bExistsLocal = TQDir().exists(name);
}
if ( m_url.isLocalFile() || !m_url.isValid() || bExistsLocal ) // assuming that invalid means relative
{
TQString localName = name;
@ -119,7 +134,15 @@ void FileAccess::setFile( const TQString& name, bool bWantToWrite )
{
localName = m_url.path(); // I want the path without preceding "file:"
}
TQFileInfo fi( localName );
TQFileInfo fi;
if (!m_workingDir.isEmpty())
{
fi = TQFileInfo( m_workingDir, localName );
}
else
{
fi = TQFileInfo( localName );
}
#if defined(TQ_WS_WIN)
// On some windows machines in a network this takes very long.
// and it's not so important anyway.
@ -158,7 +181,15 @@ void FileAccess::setFile( const TQString& name, bool bWantToWrite )
TQString cmd = "cleartool get -to \"" + m_localCopy + "\" \"" + m_absFilePath + "\"";
::system( cmd.local8Bit() );
TQFileInfo fi( m_localCopy );
TQFileInfo fi;
if (!m_workingDir.isEmpty())
{
fi = TQFileInfo( m_workingDir, m_localCopy );
}
else
{
fi = TQFileInfo( m_localCopy );
}
#if defined(TQ_WS_WIN)
m_bReadable = true;//fi.isReadable();
m_bWritable = true;//fi.isWritable();

@ -31,6 +31,7 @@ public:
FileAccess();
~FileAccess();
FileAccess( const TQString& name, bool bWantToWrite=false ); // name: local file or dirname or url (when supported)
FileAccess( const TQString& workingDir, const TQString& name, bool bWantToWrite=false ); // name: local file or dirname or url (when supported)
void setFile( const TQString& name, bool bWantToWrite=false );
bool isValid() const;
@ -101,6 +102,7 @@ private:
bool m_bHidden;
long m_fileType; // for testing only
TQString m_workingDir;
TQString m_linkTarget;
TQString m_user;
TQString m_group;

@ -98,7 +98,7 @@ void KDiff3Part::setModified(bool /*modified*/)
*/
}
static void getNameAndVersion( const TQString& str, const TQString& lineStart, TQString& fileName, TQString& version )
static void getNameAndVersion( const TQString& workingDir, const TQString& str, const TQString& lineStart, TQString& fileName, TQString& version )
{
if ( str.left( lineStart.length() )==lineStart && fileName.isEmpty() )
{
@ -110,7 +110,12 @@ static void getNameAndVersion( const TQString& str, const TQString& lineStart, T
while (pos2>pos && str[pos2]!=' ' && str[pos2]!='\t') --pos2;
fileName = str.mid( pos, pos2-pos );
std::cerr << "KDiff3: " << fileName.latin1() << std::endl;
if ( FileAccess(fileName).exists() ) break;
FileAccess fa(workingDir, fileName);
if (fa.exists())
{
fileName = fa.absFilePath();
break;
}
--pos2;
}
@ -135,6 +140,8 @@ bool KDiff3Part::openFile()
// our example widget is text-based, so we use TQTextStream instead
// of a raw TQDataStream
TQFileInfo fileinfo(m_file);
TQString workingDir = fileinfo.dirPath(true);
TQTextStream stream(&file);
TQString str;
TQString fileName1;
@ -144,8 +151,8 @@ bool KDiff3Part::openFile()
while (!stream.eof() && (fileName1.isEmpty() || fileName2.isEmpty()) )
{
str = stream.readLine() + "\n";
getNameAndVersion( str, "---", fileName1, version1 );
getNameAndVersion( str, "+++", fileName2, version2 );
getNameAndVersion( workingDir, str, "---", fileName1, version1 );
getNameAndVersion( workingDir, str, "+++", fileName2, version2 );
}
file.close();
@ -156,8 +163,8 @@ bool KDiff3Part::openFile()
return false;
}
FileAccess f1(fileName1);
FileAccess f2(fileName2);
FileAccess f1(workingDir, fileName1);
FileAccess f2(workingDir, fileName2);
if ( f1.exists() && f2.exists() && fileName1!=fileName2 )
{

Loading…
Cancel
Save