Skip to content

TagSpaces is an offline, open source, document manager with tagging support

fix: refactoring for the directory separator

Ilian Sapundshievd3b1ce8b8490
diff --git a/app/components/EntryContainer.tsx b/app/components/EntryContainer.tsx
index 9fe18cd69..7e2554d87 100644
--- a/app/components/EntryContainer.tsx
+++ b/app/components/EntryContainer.tsx
@@ -39,13 +39,13 @@ import SplitPane from 'react-split-pane';
import DeleteIcon from '@material-ui/icons/Delete';
import { withStyles } from '@material-ui/core/styles';
import RefreshIcon from '@material-ui/icons/Refresh';
-import EntryProperties from './EntryProperties';
-import ConfirmDialog from './dialogs/ConfirmDialog';
-import AppConfig from '../config';
-import PlatformIO from '../services/platform-io';
-import AddRemoveTagsDialog from './dialogs/AddRemoveTagsDialog';
-import { FileSystemEntry } from '../services/utils-io';
-import i18n from '../services/i18n';
+import EntryProperties from '-/components/EntryProperties';
+import ConfirmDialog from '-/components/dialogs/ConfirmDialog';
+import AppConfig from '-/config';
+import PlatformIO from '-/services/platform-io';
+import AddRemoveTagsDialog from '-/components/dialogs/AddRemoveTagsDialog';
+import { FileSystemEntry } from '-/services/utils-io';
+import i18n from '-/services/i18n';
import {
extractContainingDirectoryPath,
extractTitle,
@@ -54,13 +54,13 @@ import {
baseName,
extractFileName,
extractDirectoryName
-} from '../utils/paths';
-import { buffer } from '../utils/misc';
+} from '-/utils/paths';
+import { buffer } from '-/utils/misc';
import {
actions as SettingsActions,
getKeyBindingObject
-} from '../reducers/settings';
-import TaggingActions from '../reducers/tagging-actions';
+} from '-/reducers/settings';
+import TaggingActions from '-/reducers/tagging-actions';
import {
OpenedEntry,
NotificationTypes,
@@ -68,7 +68,7 @@ import {
isReadOnlyMode,
getDirectoryContent,
actions as AppActions
-} from '../reducers/app';
+} from '-/reducers/app';
const defaultSplitSize = 103;
const openedSplitSize = 360;
@@ -300,7 +300,8 @@ class EntryContainer extends React.Component<Props, State> {
const currentEntry = nextProps.openedFiles[0];
const tags = extractTagsAsObjects(
currentEntry.path,
- settings.tagDelimiter
+ settings.tagDelimiter,
+ PlatformIO.getDirSeparator()
);
this.setState({
selectedItem: {
@@ -411,10 +412,16 @@ class EntryContainer extends React.Component<Props, State> {
data.preview ? data.preview : false
)
.then(content => {
- let fileDirectory = extractContainingDirectoryPath(textFilePath);
+ let fileDirectory = extractContainingDirectoryPath(
+ textFilePath,
+ PlatformIO.getDirSeparator()
+ );
if (AppConfig.isWeb) {
fileDirectory =
- extractContainingDirectoryPath(location.href) +
+ extractContainingDirectoryPath(
+ location.href,
+ PlatformIO.getDirSeparator()
+ ) +
'/' +
fileDirectory;
}
@@ -736,8 +743,14 @@ class EntryContainer extends React.Component<Props, State> {
onClick={() => {
const { currentEntry } = this.state;
const downloadLink = document.getElementById('downloadFile');
- const entryName = `${baseName(currentEntry.path)}`;
- const fileName = extractFileName(entryName);
+ const entryName = `${baseName(
+ currentEntry.path,
+ PlatformIO.getDirSeparator()
+ )}`;
+ const fileName = extractFileName(
+ entryName,
+ PlatformIO.getDirSeparator()
+ );
if (downloadLink) {
if (AppConfig.isWeb) {
@@ -1102,7 +1115,11 @@ class EntryContainer extends React.Component<Props, State> {
className={classes.fileBadge}
style={{ backgroundColor: currentEntry.color }}
>
- {'.' + extractFileExtension(currentEntry.path)}
+ {'.' +
+ extractFileExtension(
+ currentEntry.path,
+ PlatformIO.getDirSeparator()
+ )}
</div>
{currentEntry.changed
? String.fromCharCode(0x25cf) + ' '
diff --git a/app/components/FolderContainer.tsx b/app/components/FolderContainer.tsx
index 88ef162de..2756564ed 100644
--- a/app/components/FolderContainer.tsx
+++ b/app/components/FolderContainer.tsx
@@ -432,7 +432,10 @@ class FolderContainer extends React.Component<Props, State> {
minWidth: 10
}}
>
- {extractShortDirectoryName(pathPart, '/')}
+ {extractShortDirectoryName(
+ pathPart,
+ PlatformIO.getDirSeparator()
+ )}
<FolderSeparatorIcon />
</Button>
))}
@@ -463,7 +466,7 @@ class FolderContainer extends React.Component<Props, State> {
>
{extractShortDirectoryName(
normalizePath(normalizedCurrentDirPath),
- '/'
+ PlatformIO.getDirSeparator()
)}
<MoreVertIcon />
</Button>
diff --git a/app/components/dialogs/AddRemoveTagsDialog.tsx b/app/components/dialogs/AddRemoveTagsDialog.tsx
index 32e07575f..fb04b57a6 100644
--- a/app/components/dialogs/AddRemoveTagsDialog.tsx
+++ b/app/components/dialogs/AddRemoveTagsDialog.tsx
@@ -33,6 +33,7 @@ import { Tag } from '-/reducers/taglibrary';
import TagsSelect from '../TagsSelect';
import i18n from '-/services/i18n';
import { extractFileName } from '-/utils/paths';
+import PlatformIO from '-/services/platform-io';
interface Props {
open: boolean;
@@ -116,7 +117,10 @@ class AddRemoveTagsDialog extends React.Component<Props, State> {
<FileIcon />
</ListItemIcon>
<Typography variant="inherit" noWrap>
- {extractFileName(entry.path || '')}
+ {extractFileName(
+ entry.path || '',
+ PlatformIO.getDirSeparator()
+ )}
</Typography>
</ListItem>
))}
diff --git a/app/components/dialogs/EditLocationDialog.tsx b/app/components/dialogs/EditLocationDialog.tsx
index 7ba5a561e..0934e5a9d 100644
--- a/app/components/dialogs/EditLocationDialog.tsx
+++ b/app/components/dialogs/EditLocationDialog.tsx
@@ -37,6 +37,7 @@ import { Location, locationType } from '-/reducers/locations';
import ObjectStoreForm from './ObjectStoreForm';
import LocalForm from './LocalForm';
import { Pro } from '-/pro';
+import PlatformIO from '-/services/platform-io';
interface Props {
open: boolean;
@@ -111,13 +112,17 @@ class EditLocationDialog extends React.Component<Props, State> {
let properties;
if (nextProps.location.type === locationType.TYPE_CLOUD) {
properties = {
- storeName: dir ? extractDirectoryName(dir) : nextProps.location.name,
+ storeName: dir
+ ? extractDirectoryName(dir, PlatformIO.getDirSeparator())
+ : nextProps.location.name,
storePath: dir || nextProps.location.paths[0]
};
} else {
properties = {
// TODO maybe its better to separate name/path keys for different locationTypes ??
- name: dir ? extractDirectoryName(dir) : nextProps.location.name,
+ name: dir
+ ? extractDirectoryName(dir, PlatformIO.getDirSeparator())
+ : nextProps.location.name,
path: dir || nextProps.location.paths[0]
};
}
diff --git a/app/components/dialogs/LocalForm.tsx b/app/components/dialogs/LocalForm.tsx
index 9a63d955a..7c06c7db3 100644
--- a/app/components/dialogs/LocalForm.tsx
+++ b/app/components/dialogs/LocalForm.tsx
@@ -47,7 +47,10 @@ class LocalForm extends React.Component<Props> {
if (this.props.state.name.length < 1) {
this.props.handleChange(
'name',
- extractDirectoryName(selectedPaths[0])
+ extractDirectoryName(
+ selectedPaths[0],
+ PlatformIO.getDirSeparator()
+ )
);
}
return true;
diff --git a/app/components/dialogs/MoveCopyFilesDialog.tsx b/app/components/dialogs/MoveCopyFilesDialog.tsx
index 491ab25f4..7292f5962 100644
--- a/app/components/dialogs/MoveCopyFilesDialog.tsx
+++ b/app/components/dialogs/MoveCopyFilesDialog.tsx
@@ -37,7 +37,6 @@ import FormHelperText from '@material-ui/core/FormHelperText';
import Typography from '@material-ui/core/Typography';
import Dialog from '@material-ui/core/Dialog';
import i18n from '-/services/i18n';
-// import { extractContainingDirectoryPath } from '-/utils/paths';
import PlatformIO from '-/services/platform-io';
import AppConfig from '-/config';
import IOActions from '-/reducers/io-actions';
@@ -128,7 +127,7 @@ const MoveCopyFilesDialog = (props: Props) => {
<FileIcon />
</ListItemIcon>
<Typography variant="inherit" noWrap>
- {extractFileName(path)}
+ {extractFileName(path, PlatformIO.getDirSeparator())}
</Typography>
</ListItem>
))}
diff --git a/app/components/dialogs/RenameDirectoryDialog.tsx b/app/components/dialogs/RenameDirectoryDialog.tsx
index cd3614343..b45ccab09 100644
--- a/app/components/dialogs/RenameDirectoryDialog.tsx
+++ b/app/components/dialogs/RenameDirectoryDialog.tsx
@@ -30,6 +30,7 @@ import Dialog from '@material-ui/core/Dialog';
import i18n from '-/services/i18n';
import { extractDirectoryName } from '-/utils/paths';
import { actions as AppActions } from '-/reducers/app';
+import PlatformIO from '-/services/platform-io';
interface Props {
open: boolean;
@@ -49,7 +50,10 @@ class RenameDirectoryDialog extends React.Component<Props, State> {
inputError: false,
disableConfirmButton: true,
name: this.props.selectedDirectoryPath
- ? extractDirectoryName(this.props.selectedDirectoryPath)
+ ? extractDirectoryName(
+ this.props.selectedDirectoryPath,
+ PlatformIO.getDirSeparator()
+ )
: ''
};
diff --git a/app/components/dialogs/RenameFileDialog.tsx b/app/components/dialogs/RenameFileDialog.tsx
index 310d1a06a..253dd7d65 100644
--- a/app/components/dialogs/RenameFileDialog.tsx
+++ b/app/components/dialogs/RenameFileDialog.tsx
@@ -66,7 +66,10 @@ class RenameFileDialog extends React.Component<Props, State> {
componentWillReceiveProps = (nextProps: any) => {
if (nextProps.open) {
- const fileName = extractFileName(nextProps.selectedFilePath);
+ const fileName = extractFileName(
+ nextProps.selectedFilePath,
+ PlatformIO.getDirSeparator()
+ );
this.setState({ fileName }, () => {
this.fileName.focus();
if (fileName) {
@@ -109,7 +112,8 @@ class RenameFileDialog extends React.Component<Props, State> {
onConfirm = () => {
if (!this.state.disableConfirmButton) {
const fileDirectory = extractContainingDirectoryPath(
- this.props.selectedFilePath
+ this.props.selectedFilePath,
+ PlatformIO.getDirSeparator()
);
const newFilePath =
fileDirectory + PlatformIO.getDirSeparator + this.state.fileName;
diff --git a/app/components/menus/DirectoryMenu.tsx b/app/components/menus/DirectoryMenu.tsx
index 645efa780..305d1b284 100644
--- a/app/components/menus/DirectoryMenu.tsx
+++ b/app/components/menus/DirectoryMenu.tsx
@@ -48,7 +48,7 @@ import {
extractFileName,
normalizePath,
cleanTrailingDirSeparator
-} from '-/utils/paths'; // extractFileExtension
+} from '-/utils/paths';
import PlatformIO from '-/services/platform-io';
import { formatDateTime4Tag } from '-/utils/misc';
import { actions as AppActions } from '-/reducers/app';
diff --git a/app/components/menus/FileMenu.tsx b/app/components/menus/FileMenu.tsx
index d122e237b..bc3b5bb08 100644
--- a/app/components/menus/FileMenu.tsx
+++ b/app/components/menus/FileMenu.tsx
@@ -31,6 +31,7 @@ import RenameFile from '@material-ui/icons/FormatTextdirectionLToR';
import DeleteForever from '@material-ui/icons/DeleteForever';
import i18n from '-/services/i18n';
import AppConfig from '-/config';
+import PlatformIO from '-/services/platform-io';
interface Props {
anchorEl: Element;
@@ -98,7 +99,7 @@ const FileMenu = (props: Props) => {
</ListItemIcon>
<ListItemText primary={i18n.t('core:openFile')} />
</MenuItem>
- {!AppConfig.isWeb && (
+ {!(PlatformIO.haveObjectStoreSupport() || AppConfig.isWeb) && (
<div>
<MenuItem
data-tid="fileMenuOpenFileNatively"
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index 5e1163ea0..166dba736 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -415,12 +415,19 @@ export default (state: any = initialState, action: any) => {
return {
...entry,
path: action.newPath,
- // thumbPath: getThumbFileLocationForFile(action.newPath), // not needed due timing issue
+ // thumbPath: getThumbFileLocationForFile(action.newPath, PlatformIO.getDirSeparator()), // not needed due timing issue
name: extractFileName(action.newPath, PlatformIO.getDirSeparator()),
- extension: extractFileExtension(action.newPath),
+ extension: extractFileExtension(
+ action.newPath,
+ PlatformIO.getDirSeparator()
+ ),
tags: [
...entry.tags.filter(tag => tag.type === 'sidecar'), // add only sidecar tags
- ...extractTagsAsObjects(action.newPath) // , getTagDelimiter(state)) TODO https://itnext.io/passing-state-between-reducers-in-redux-318de6db06cd
+ ...extractTagsAsObjects(
+ action.newPath,
+ AppConfig.tagDelimiter,
+ PlatformIO.getDirSeparator()
+ )
]
};
}),
@@ -808,7 +815,8 @@ export const actions = {
dispatch(
actions.showNotification(
`Renaming directory ${extractDirectoryName(
- directoryPath
+ directoryPath,
+ PlatformIO.getDirSeparator()
)} successful.`,
'default',
true
@@ -820,7 +828,10 @@ export const actions = {
console.warn('Error while renaming directory: ' + error);
dispatch(
actions.showNotification(
- `Error renaming directory '${extractDirectoryName(directoryPath)}'`,
+ `Error renaming directory '${extractDirectoryName(
+ directoryPath,
+ PlatformIO.getDirSeparator()
+ )}'`,
'error',
true
)
@@ -841,7 +852,8 @@ export const actions = {
dispatch(
actions.showNotification(
`Creating directory ${extractDirectoryName(
- directoryPath
+ directoryPath,
+ PlatformIO.getDirSeparator()
)} successful.`,
'default',
true
@@ -853,7 +865,10 @@ export const actions = {
console.warn('Error creating directory: ' + error);
dispatch(
actions.showNotification(
- `Error creating directory '${extractDirectoryName(directoryPath)}'`,
+ `Error creating directory '${extractDirectoryName(
+ directoryPath,
+ PlatformIO.getDirSeparator()
+ )}'`,
'error',
true
)
@@ -1222,7 +1237,7 @@ export const actions = {
? extractFileName(path, PlatformIO.getDirSeparator())
: extractDirectoryName(path, PlatformIO.getDirSeparator()),
isFile,
- extension: extractFileExtension(path),
+ extension: extractFileExtension(path, PlatformIO.getDirSeparator()),
description: '',
tags: [],
size: 0,
@@ -1287,8 +1302,8 @@ export const actions = {
);
// Delete sidecar file and thumb
deleteFilesPromise([
- getMetaFileLocationForFile(filePath),
- getThumbFileLocationForFile(filePath)
+ getMetaFileLocationForFile(filePath, PlatformIO.getDirSeparator()),
+ getThumbFileLocationForFile(filePath, PlatformIO.getDirSeparator())
])
.then(() => {
console.log(
@@ -1493,7 +1508,10 @@ function findExtensionsForEntry(
entryPath: string,
isFile: boolean = true
): OpenedEntry {
- const fileExtension = extractFileExtension(entryPath).toLowerCase();
+ const fileExtension = extractFileExtension(
+ entryPath,
+ PlatformIO.getDirSeparator()
+ ).toLowerCase();
const viewingExtensionPath = isFile
? findExtensionPathForId('@tagspaces/text-viewer')
: 'about:blank';
diff --git a/app/reducers/io-actions.ts b/app/reducers/io-actions.ts
index f7b16bf63..30caa206b 100644
--- a/app/reducers/io-actions.ts
+++ b/app/reducers/io-actions.ts
@@ -24,7 +24,6 @@ import {
normalizePath
} from '../utils/paths';
import { copyFilesPromise, renameFilesPromise } from '../services/utils-io';
-import AppConfig from '../config';
import i18n from '../services/i18n';
import { Pro } from '../pro';
import TaggingActions from './tagging-actions';
@@ -86,12 +85,12 @@ const actions = {
moveJobs.map(job => {
dispatch(AppActions.reflectDeleteEntry(job[0])); // TODO moved files should be added to the index, if the target dir in index
moveMetaJobs.push([
- getMetaFileLocationForFile(job[0]),
- getMetaFileLocationForFile(job[1])
+ getMetaFileLocationForFile(job[0], PlatformIO.getDirSeparator()),
+ getMetaFileLocationForFile(job[1], PlatformIO.getDirSeparator())
]);
moveMetaJobs.push([
- getThumbFileLocationForFile(job[0]),
- getThumbFileLocationForFile(job[1])
+ getThumbFileLocationForFile(job[0], PlatformIO.getDirSeparator()),
+ getThumbFileLocationForFile(job[1], PlatformIO.getDirSeparator())
]);
renameFilesPromise(moveMetaJobs)
.then(() => {
@@ -134,12 +133,12 @@ const actions = {
copyJobs.map(job => {
// dispatch(AppActions.reflectCopyEntry(job[0])); // TODO need only for the index if the target dir is indexed
copyMetaJobs.push([
- getMetaFileLocationForFile(job[0]),
- getMetaFileLocationForFile(job[1])
+ getMetaFileLocationForFile(job[0], PlatformIO.getDirSeparator()),
+ getMetaFileLocationForFile(job[1], PlatformIO.getDirSeparator())
]);
copyMetaJobs.push([
- getThumbFileLocationForFile(job[0]),
- getThumbFileLocationForFile(job[1])
+ getThumbFileLocationForFile(job[0], PlatformIO.getDirSeparator()),
+ getThumbFileLocationForFile(job[1], PlatformIO.getDirSeparator())
]);
copyFilesPromise(copyMetaJobs)
.then(() => {
diff --git a/app/reducers/location-index.ts b/app/reducers/location-index.ts
index 7265cc944..a591fb5e2 100644
--- a/app/reducers/location-index.ts
+++ b/app/reducers/location-index.ts
@@ -23,15 +23,14 @@ import {
extractFileExtension,
extractFileName,
extractTagsAsObjects
- // getThumbFileLocationForFile
} from '../utils/paths';
import Search, { SearchQuery } from '../services/search';
import { actions as AppActions } from './app';
-import AppConfig from '../config';
import i18n from '../services/i18n';
import PlatformIO from '../services/platform-io';
import { Tag } from './taglibrary';
import GlobalSearch from '../services/search-index';
+import AppConfig from '-/config';
export const types = {
SET_SEARCH_QUERY: 'SET_SEARCH_QUERY',
@@ -117,17 +116,21 @@ export default (state: any = initialState, action: any) => {
for (let i = 0; i < GlobalSearch.index.length; i += 1) {
if (GlobalSearch.index[i].path === action.path) {
GlobalSearch.index[i].path = action.newPath;
- // thumbPath: getThumbFileLocationForFile(action.newPath), // disabled due performance concerns
GlobalSearch.index[i].name = extractFileName(
action.newPath,
PlatformIO.getDirSeparator()
);
GlobalSearch.index[i].extension = extractFileExtension(
- action.newPath
+ action.newPath,
+ PlatformIO.getDirSeparator()
);
GlobalSearch.index[i].tags = [
...GlobalSearch.index[i].tags.filter(tag => tag.type === 'sidecar'), // add only sidecar tags
- ...extractTagsAsObjects(action.newPath) // , getTagDelimiter(state))
+ ...extractTagsAsObjects(
+ action.newPath,
+ AppConfig.tagDelimiter,
+ PlatformIO.getDirSeparator()
+ )
];
}
}
diff --git a/app/reducers/tagging-actions.ts b/app/reducers/tagging-actions.ts
index 31690189f..463450844 100644
--- a/app/reducers/tagging-actions.ts
+++ b/app/reducers/tagging-actions.ts
@@ -33,7 +33,6 @@ import {
generateFileName
} from '../services/utils-io';
import { formatDateTime4Tag, isPlusCode } from '../utils/misc';
-import AppConfig from '../config';
import PlatformIO from '../services/platform-io';
import { Pro } from '../pro';
import GlobalSearch from '../services/search-index';
@@ -151,7 +150,11 @@ const actions = {
if (fsEntryMeta) {
const uniqueTags = getNonExistingTags(
tags,
- extractTags(path, settings.tagDelimiter),
+ extractTags(
+ path,
+ settings.tagDelimiter,
+ PlatformIO.getDirSeparator()
+ ),
fsEntryMeta.tags
);
if (uniqueTags.length > 0) {
@@ -200,15 +203,22 @@ const actions = {
}
} else if (fsEntryMeta) {
// Handling tags in filename by existing sidecar
- const extractedTags = extractTags(path, settings.tagDelimiter);
+ const extractedTags = extractTags(
+ path,
+ settings.tagDelimiter,
+ PlatformIO.getDirSeparator()
+ );
const uniqueTags = getNonExistingTags(
tags,
extractedTags,
fsEntryMeta.tags
);
if (uniqueTags.length > 0) {
- const fileName = extractFileName(path);
- const containingDirectoryPath = extractContainingDirectoryPath(path);
+ const fileName = extractFileName(path, PlatformIO.getDirSeparator());
+ const containingDirectoryPath = extractContainingDirectoryPath(
+ path,
+ PlatformIO.getDirSeparator()
+ );
for (let i = 0; i < uniqueTags.length; i += 1) {
extractedTags.push(uniqueTags[i].title);
@@ -221,9 +231,16 @@ const actions = {
}
} else {
// Handling tags in filename by no sidecar
- const fileName = extractFileName(path);
- const containingDirectoryPath = extractContainingDirectoryPath(path);
- const extractedTags = extractTags(path);
+ const fileName = extractFileName(path, PlatformIO.getDirSeparator());
+ const containingDirectoryPath = extractContainingDirectoryPath(
+ path,
+ PlatformIO.getDirSeparator()
+ );
+ const extractedTags = extractTags(
+ path,
+ settings.tagDelimiter,
+ PlatformIO.getDirSeparator()
+ );
for (let i = 0; i < tags.length; i += 1) {
// check if tag is already in the tag array
if (extractedTags.indexOf(tags[i].title) < 0) {
@@ -291,9 +308,16 @@ const actions = {
delete tag.id;
// TODO: Handle adding already added tags
if (tag.type === 'plain') {
- const fileName = extractFileName(path);
- const containingDirectoryPath = extractContainingDirectoryPath(path);
- const extractedTags = extractTags(path, settings.tagDelimiter);
+ const fileName = extractFileName(path, PlatformIO.getDirSeparator());
+ const containingDirectoryPath = extractContainingDirectoryPath(
+ path,
+ PlatformIO.getDirSeparator()
+ );
+ const extractedTags = extractTags(
+ path,
+ settings.tagDelimiter,
+ PlatformIO.getDirSeparator()
+ );
let tagFound = false;
for (let i = 0; i < extractedTags.length; i += 1) {
// check if tag is already in the tag array
@@ -481,10 +505,17 @@ const actions = {
});
function removeTagsFromFilename() {
- const extractedTags = extractTags(path, settings.tagDelimiter);
+ const extractedTags = extractTags(
+ path,
+ settings.tagDelimiter,
+ PlatformIO.getDirSeparator()
+ );
if (extractedTags.length > 0) {
- const fileName = extractFileName(path);
- const containingDirectoryPath = extractContainingDirectoryPath(path);
+ const fileName = extractFileName(path, PlatformIO.getDirSeparator());
+ const containingDirectoryPath = extractContainingDirectoryPath(
+ path,
+ PlatformIO.getDirSeparator()
+ );
for (let i = 0; i < tagTitlesForRemoving.length; i += 1) {
const tagLoc = extractedTags.indexOf(tagTitlesForRemoving[i]);
if (tagLoc < 0) {
@@ -553,15 +584,22 @@ const actions = {
function removeAllTagsFromFilename() {
// Tags in file name case, check is file
- const extractedTags = extractTags(path, settings.tagDelimiter);
+ const extractedTags = extractTags(
+ path,
+ settings.tagDelimiter,
+ PlatformIO.getDirSeparator()
+ );
if (extractedTags.length > 0) {
const fileTitle = extractTitle(
path,
false,
PlatformIO.getDirSeparator()
);
- let fileExt = extractFileExtension(path);
- const containingDirectoryPath = extractContainingDirectoryPath(path);
+ let fileExt = extractFileExtension(path, PlatformIO.getDirSeparator());
+ const containingDirectoryPath = extractContainingDirectoryPath(
+ path,
+ PlatformIO.getDirSeparator()
+ );
if (fileExt.length > 0) {
fileExt = '.' + fileExt;
}
@@ -583,9 +621,9 @@ const actions = {
{
/*
console.log('Moves the location of tag in the file name: ' + filePath);
- var fileName = extractFileName(filePath);
- var containingDirectoryPath = extractContainingDirectoryPath(filePath);
- var extractedTags = extractTags(filePath);
+ var fileName = extractFileName(filePath, PlatformIO.getDirSeparator());
+ var containingDirectoryPath = extractContainingDirectoryPath(filePath, PlatformIO.getDirSeparator());
+ var extractedTags = extractTags(filePath, settings.tagDelimiter, PlatformIO.getDirSeparator());
if (extractedTags.indexOf(tagName) < 0) {
showAlertDialog("The tag you are trying to move is not part of the file name and that's why it cannot be moved.", $.i18n.t("ns.common:warning"));
return;
diff --git a/app/services/cordova-io.ts b/app/services/cordova-io.ts
index 4e9e59269..eb0d6f8a6 100644
--- a/app/services/cordova-io.ts
+++ b/app/services/cordova-io.ts
@@ -1022,7 +1022,7 @@ export default class CordovaIO {
): Promise<any> =>
new Promise((resolve, reject) => {
let newDirPath =
- extractParentDirectoryPath(dirPath) +
+ extractParentDirectoryPath(dirPath, '/') +
AppConfig.dirSeparator +
newDirName;
// eslint-disable-next-line no-param-reassign
diff --git a/app/services/electron-io.ts b/app/services/electron-io.ts
index b54aaaea5..b9c6c05f5 100644
--- a/app/services/electron-io.ts
+++ b/app/services/electron-io.ts
@@ -21,7 +21,6 @@ import winattr from 'winattr';
import {
extractParentDirectoryPath,
getMetaDirectoryPath
- // extractFileExtension
} from '../utils/paths';
import { arrayBufferToBuffer } from '../utils/misc';
import AppConfig from '../config';
@@ -382,7 +381,7 @@ export default class ElectronIO {
// Read the .ts meta content
if (!lite && containsMetaFolder) {
- metaFolderPath = getMetaDirectoryPath(path);
+ metaFolderPath = getMetaDirectoryPath(path, AppConfig.dirSeparator);
this.fs.readdir(metaFolderPath, (err, metaEntries) => {
if (err) {
console.log(
@@ -593,7 +592,9 @@ export default class ElectronIO {
newDirName: string
): Promise<any> => {
const newDirPath =
- extractParentDirectoryPath(dirPath) + AppConfig.dirSeparator + newDirName;
+ extractParentDirectoryPath(dirPath, AppConfig.dirSeparator) +
+ AppConfig.dirSeparator +
+ newDirName;
console.log('Renaming dir: ' + dirPath + ' to ' + newDirPath);
// stopWatchingDirectories();
return new Promise((resolve, reject) => {
diff --git a/app/services/thumbsgenerator.ts b/app/services/thumbsgenerator.ts
index 8671b0047..7739df971 100644
--- a/app/services/thumbsgenerator.ts
+++ b/app/services/thumbsgenerator.ts
@@ -106,12 +106,18 @@ function saveThumbnailPromise(filePath, dataURL) {
}
function getThumbFileLocation(filePath: string) {
- const containingFolder = extractContainingDirectoryPath(filePath);
- const metaFolder = getMetaDirectoryPath(containingFolder);
+ const containingFolder = extractContainingDirectoryPath(
+ filePath,
+ PlatformIO.getDirSeparator()
+ );
+ const metaFolder = getMetaDirectoryPath(
+ containingFolder,
+ PlatformIO.getDirSeparator()
+ );
return (
metaFolder +
PlatformIO.getDirSeparator() +
- extractFileName(filePath) +
+ extractFileName(filePath, PlatformIO.getDirSeparator()) +
AppConfig.thumbFileExt
);
}
@@ -191,8 +197,14 @@ export function createThumbnailPromise(
thumbFilePath: string
): Promise<any> {
return new Promise(async resolve => {
- const metaDirectory = extractContainingDirectoryPath(thumbFilePath);
- const fileDirectory = extractContainingDirectoryPath(filePath);
+ const metaDirectory = extractContainingDirectoryPath(
+ thumbFilePath,
+ PlatformIO.getDirSeparator()
+ );
+ const fileDirectory = extractContainingDirectoryPath(
+ filePath,
+ PlatformIO.getDirSeparator()
+ );
const normalizedFileDirectory = normalizePath(fileDirectory);
if (normalizedFileDirectory.endsWith(AppConfig.metaFolder)) {
resolve(); // prevent creating thumbs in meta/.ts folder
@@ -226,7 +238,10 @@ export function createThumbnailPromise(
}
export function generateThumbnailPromise(fileURL: string, fileSize: number) {
- const ext = extractFileExtension(fileURL).toLowerCase();
+ const ext = extractFileExtension(
+ fileURL,
+ PlatformIO.getDirSeparator()
+ ).toLowerCase();
if (supportedImgs.indexOf(ext) >= 0) {
if (fileSize && fileSize < maxFileSize) {
diff --git a/app/services/utils-io.ts b/app/services/utils-io.ts
index 59936f40b..5cb403e3b 100644
--- a/app/services/utils-io.ts
+++ b/app/services/utils-io.ts
@@ -61,7 +61,11 @@ export interface FileSystemEntryMeta {
export function enhanceEntry(entry: any): FileSystemEntry {
let fileNameTags = [];
if (entry.isFile) {
- fileNameTags = extractTagsAsObjects(entry.name);
+ fileNameTags = extractTagsAsObjects(
+ entry.name,
+ AppConfig.tagDelimiter,
+ PlatformIO.getDirSeparator()
+ );
}
let sidecarDescription = '';
let sidecarColor = '';
@@ -81,7 +85,9 @@ export function enhanceEntry(entry: any): FileSystemEntry {
const enhancedEntry: FileSystemEntry = {
name: entry.name,
isFile: entry.isFile,
- extension: entry.isFile ? extractFileExtension(entry.name) : '',
+ extension: entry.isFile
+ ? extractFileExtension(entry.name, PlatformIO.getDirSeparator())
+ : '',
tags: [...sidecarTags, ...fileNameTags],
size: entry.size,
lmdt: entry.lmdt,
@@ -368,7 +374,7 @@ export function generateFileName(
tagsString = tagsString.trim() + AppConfig.endTagContainer;
}
// console.log('The tags string: ' + tagsString);
- const fileExt = extractFileExtension(fileName);
+ const fileExt = extractFileExtension(fileName, PlatformIO.getDirSeparator());
// console.log('Filename: ' + fileName + ' file extension: ' + fileExt);
// Assembling the new filename with the tags
let newFileName = '';
@@ -417,7 +423,10 @@ export async function loadMetaDataPromise(
const entryProperties = await PlatformIO.getPropertiesPromise(path);
let metaDataObject;
if (entryProperties.isFile) {
- const metaFilePath = getMetaFileLocationForFile(path);
+ const metaFilePath = getMetaFileLocationForFile(
+ path,
+ PlatformIO.getDirSeparator()
+ );
const metaData = await loadJSONFile(metaFilePath);
metaDataObject = {
description: metaData.description || '',
@@ -429,7 +438,10 @@ export async function loadMetaDataPromise(
lastUpdated: metaData.lastUpdated || ''
};
} else {
- const metaFilePath = getMetaFileLocationForDir(path);
+ const metaFilePath = getMetaFileLocationForDir(
+ path,
+ PlatformIO.getDirSeparator()
+ );
const metaData = await loadJSONFile(metaFilePath);
metaDataObject = {
description: metaData.description || '',
@@ -453,10 +465,13 @@ export async function saveMetaDataPromise(
let newFsEntryMeta;
if (entryProperties.isFile) {
- metaFilePath = getMetaFileLocationForFile(path);
+ metaFilePath = getMetaFileLocationForFile(
+ path,
+ PlatformIO.getDirSeparator()
+ );
// check and create meta folder if not exist
await PlatformIO.createDirectoryPromise(
- extractContainingDirectoryPath(metaFilePath)
+ extractContainingDirectoryPath(metaFilePath, PlatformIO.getDirSeparator())
);
newFsEntryMeta = {
@@ -468,7 +483,10 @@ export async function saveMetaDataPromise(
} else {
// check and create meta folder if not exist
// todo not need to check if folder exist first createDirectoryPromise() recursively will skip creation of existing folders https://nodejs.org/api/fs.html#fs_fs_mkdir_path_options_callback
- const metaDirectoryPath = getMetaDirectoryPath(path);
+ const metaDirectoryPath = getMetaDirectoryPath(
+ path,
+ PlatformIO.getDirSeparator()
+ );
const metaDirectoryProperties = await PlatformIO.getPropertiesPromise(
metaDirectoryPath
);
@@ -476,7 +494,10 @@ export async function saveMetaDataPromise(
await PlatformIO.createDirectoryPromise(metaDirectoryPath);
}
- metaFilePath = getMetaFileLocationForDir(path);
+ metaFilePath = getMetaFileLocationForDir(
+ path,
+ PlatformIO.getDirSeparator()
+ );
newFsEntryMeta = {
...metaData,
appName: versionMeta.name,
diff --git a/app/services/webdav-io.ts b/app/services/webdav-io.ts
index 85c482d06..d35b32623 100644
--- a/app/services/webdav-io.ts
+++ b/app/services/webdav-io.ts
@@ -261,7 +261,10 @@ export default class WebDAVIO {
if (!lite) {
if (isDir) {
// Read tsm.json from subfolders
- const pathMetaFile = getMetaFileLocationForDir(eentry.path);
+ const pathMetaFile = getMetaFileLocationForDir(
+ eentry.path,
+ '/'
+ );
metaPromises.push(this.getEntryMeta(eentry, pathMetaFile));
} else {
const metaFileAvailable = metaContent.find(
@@ -620,7 +623,7 @@ export default class WebDAVIO {
newDirectoryPath: string
): Promise<Object> => {
const newDirPath =
- extractParentDirectoryPath(dirPath) + '/' + newDirectoryPath;
+ extractParentDirectoryPath(dirPath, '/') + '/' + newDirectoryPath;
console.log('Renaming directory: ' + dirPath + ' to ' + newDirPath);
return new Promise((resolve, reject) => {
if (dirPath === newDirPath) {
diff --git a/app/utils/paths.ts b/app/utils/paths.ts
index eae7f3c6e..84bf1218f 100644
--- a/app/utils/paths.ts
+++ b/app/utils/paths.ts
@@ -19,16 +19,22 @@
import AppConfig from '../config';
import { Tag } from '../reducers/taglibrary';
-export function baseName(dirPath: string) {
+export function baseName(
+ dirPath: string,
+ dirSeparator: string // = AppConfig.dirSeparator
+) {
const fileName = dirPath.substring(
- dirPath.lastIndexOf(AppConfig.dirSeparator) + 1,
+ dirPath.lastIndexOf(dirSeparator) + 1,
dirPath.length
);
return fileName || dirPath;
}
-export function extractFileExtension(filePath: string) {
- const lastindexDirSeparator = filePath.lastIndexOf(AppConfig.dirSeparator);
+export function extractFileExtension(
+ filePath: string,
+ dirSeparator: string // = AppConfig.dirSeparator
+) {
+ const lastindexDirSeparator = filePath.lastIndexOf(dirSeparator);
const lastIndexEndTagContainer = filePath.lastIndexOf(
AppConfig.endTagContainer
);
@@ -54,15 +60,11 @@ export function extractFileExtension(filePath: string) {
extension = extension.substring(0, lastindexQuestionMark);
}
return extension;
-
- /* alternative implementation
- const ext = fileURL.split('.').pop();
- return (ext === fileURL) ? '' : ext; */
}
export function getMetaDirectoryPath(
directoryPath: string,
- dirSeparator: string = AppConfig.dirSeparator
+ dirSeparator: string // = AppConfig.dirSeparator
) {
return (
(directoryPath ? normalizePath(directoryPath) + dirSeparator : '') +
@@ -72,7 +74,7 @@ export function getMetaDirectoryPath(
export function getMetaFileLocationForFile(
entryPath: string,
- dirSeparator: string = AppConfig.dirSeparator
+ dirSeparator: string // = AppConfig.dirSeparator
) {
const containingFolder = extractContainingDirectoryPath(
entryPath,
@@ -89,7 +91,7 @@ export function getMetaFileLocationForFile(
export function getThumbFileLocationForFile(
entryPath: string,
- dirSeparator: string = AppConfig.dirSeparator
+ dirSeparator: string // = AppConfig.dirSeparator
) {
const containingFolder = extractContainingDirectoryPath(
entryPath,
@@ -106,7 +108,7 @@ export function getThumbFileLocationForFile(
export function getThumbFileLocationForDirectory(
entryPath: string,
- dirSeparator: string = AppConfig.dirSeparator
+ dirSeparator: string // = AppConfig.dirSeparator
) {
return (
entryPath +
@@ -119,15 +121,15 @@ export function getThumbFileLocationForDirectory(
export function getMetaFileLocationForDir(
entryPath: string,
- dirSeparator: string = AppConfig.dirSeparator
+ dirSeparator: string // = AppConfig.dirSeparator
) {
- const metaFolder = getMetaDirectoryPath(entryPath);
+ const metaFolder = getMetaDirectoryPath(entryPath, dirSeparator);
return metaFolder + dirSeparator + AppConfig.metaFolderFile;
}
export function extractFileName(
filePath: string,
- dirSeparator: string = AppConfig.dirSeparator
+ dirSeparator: string // = AppConfig.dirSeparator
): string {
return filePath
? filePath.substring(
@@ -162,7 +164,7 @@ export function normalizePath(path: string): string {
export function extractFileNameWithoutExt(
filePath: string,
- dirSeparator: string = AppConfig.dirSeparator
+ dirSeparator: string // = AppConfig.dirSeparator
): string {
const fileName = extractFileName(filePath, dirSeparator);
const indexOfDot = fileName.lastIndexOf('.');
@@ -192,14 +194,14 @@ export function extractFileNameWithoutExt(
export function extractContainingDirectoryPath(
filePath: string,
- dirSeparator: string = AppConfig.dirSeparator
+ dirSeparator: string // = AppConfig.dirSeparator
) {
return filePath.substring(0, filePath.lastIndexOf(dirSeparator));
}
export function extractParentDirectoryPath(
dirPath: string,
- dirSeparator: string = AppConfig.dirSeparator
+ dirSeparator: string // = AppConfig.dirSeparator
) {
if (!dirPath) return;
let path = dirPath;
@@ -216,7 +218,7 @@ export function extractParentDirectoryPath(
export function extractDirectoryName(
dirPath: string,
- dirSeparator: string = AppConfig.dirSeparator
+ dirSeparator: string // = AppConfig.dirSeparator
): string {
if (!dirPath) return '';
let directoryName = dirPath;
@@ -240,7 +242,7 @@ export function extractDirectoryName(
export function extractShortDirectoryName(
dirPath: string,
- dirSeparator: string = AppConfig.dirSeparator
+ dirSeparator: string // = AppConfig.dirSeparator
) {
let shortDirName: string = extractDirectoryName(dirPath, dirSeparator);
if (shortDirName.length > 20) {
@@ -249,15 +251,12 @@ export function extractShortDirectoryName(
return shortDirName;
}
-export function extractContainingDirectoryName(filePath: string) {
- const tmpStr = filePath.substring(
- 0,
- filePath.lastIndexOf(AppConfig.dirSeparator)
- );
- return tmpStr.substring(
- tmpStr.lastIndexOf(AppConfig.dirSeparator) + 1,
- tmpStr.length
- );
+export function extractContainingDirectoryName(
+ filePath: string,
+ dirSeparator: string
+) {
+ const tmpStr = filePath.substring(0, filePath.lastIndexOf(dirSeparator));
+ return tmpStr.substring(tmpStr.lastIndexOf(dirSeparator) + 1, tmpStr.length);
}
export function extractTitle(
@@ -306,9 +305,10 @@ export function extractTitle(
export function extractTagsAsObjects(
filePath: string,
- tagDelimiter: string = AppConfig.tagDelimiter
+ tagDelimiter: string = AppConfig.tagDelimiter,
+ dirSeparator: string // = AppConfig.dirSeparator
): Array<Tag> {
- const tagsInFileName = extractTags(filePath, tagDelimiter);
+ const tagsInFileName = extractTags(filePath, tagDelimiter, dirSeparator);
const tagArray = [];
tagsInFileName.map(tag => {
tagArray.push({
@@ -322,10 +322,11 @@ export function extractTagsAsObjects(
export function extractTags(
filePath: string,
- tagDelimiter: string = AppConfig.tagDelimiter
+ tagDelimiter: string = AppConfig.tagDelimiter,
+ dirSeparator: string // = AppConfig.dirSeparator
) {
// console.log('Extracting tags from: ' + filePath);
- const fileName = extractFileName(filePath);
+ const fileName = extractFileName(filePath, dirSeparator);
// WithoutExt
let tags = [];
const beginTagContainer = fileName.indexOf(AppConfig.beginTagContainer);