forked from FNNDSC/KWWidgets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkKWFileBrowserUtilities.h
82 lines (69 loc) · 2.44 KB
/
vtkKWFileBrowserUtilities.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*=========================================================================
Module: $RCSfile: vtkKWFileBrowserUtilities.h,v $
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkKWFileBrowserUtilities - some constants
// This work is part of the National Alliance for Medical Image
// Computing (NAMIC), funded by the National Institutes of Health
// through the NIH Roadmap for Medical Research, Grant U54 EB005149.
// Information on the National Centers for Biomedical Computing
// can be obtained from http://nihroadmap.nih.gov/bioinformatics.
#ifndef __vtkKWFileBrowserUtilities_h
#define __vtkKWFileBrowserUtilities_h
#include <vtksys/SystemTools.hxx>
#include <vtksys/stl/string>
#ifdef _WIN32
#define KWFileBrowser_PATH_SEPARATOR "\\"
#else
#define KWFileBrowser_PATH_SEPARATOR "/"
#endif
#define KWFileBrowser_UNIX_ROOT_DIRECTORY "/"
#define KWFileBrowser_ESCAPE_CHARS "{}[]$\"\\"
#define VTK_KW_FAVORITE_TOPLEVEL "KWFileBrowserFavorites"
static char* KWFileBrowser_GetUnixPath(const char* path)
{
if(path && *path)
{
vtksys_stl::string sBuffer = path;
vtksys::SystemTools::ConvertToUnixSlashes(sBuffer);
static char buffer[512];
strcpy(buffer, sBuffer.c_str());
return buffer;
}
return NULL;
};
static int KWFileBrowser_HasTrailingSlash(const char *dir)
{
size_t dir_len = strlen(dir);
int has_slash =
(dir_len && (dir[dir_len - 1] == '/' || dir[dir_len - 1] == '\\'));
return has_slash;
};
static bool KWFileBrowser_ComparePath(const char *dir1, const char* dir2)
{
if(!dir1 || !dir2)
{
return false;
}
vtksys_stl::string path1 = dir1;
vtksys_stl::string path2 = dir2;
int dirslash1 = KWFileBrowser_HasTrailingSlash(dir1);
int dirslash2 = KWFileBrowser_HasTrailingSlash(dir2);
if(!dirslash1 && dirslash2)
{
path1 += "/";
}
else if(dirslash1 && !dirslash2)
{
path2 += "/";
}
vtksys::SystemTools::ConvertToUnixSlashes(path1);
vtksys::SystemTools::ConvertToUnixSlashes(path2);
return vtksys::SystemTools::ComparePath(path1.c_str(), path2.c_str());
};
#endif