Change default folder in dacpac and schema compare extensions (#5215)

* change default folder in dacpac and schema compare extensions

* move getting rootpath to a method

* change method name
This commit is contained in:
kisantia
2019-04-27 04:27:03 +12:00
committed by GitHub
parent 23f4931a1d
commit 64377000c6
8 changed files with 23 additions and 14 deletions

View File

@@ -6,6 +6,7 @@
import * as azdata from 'azdata';
import * as nls from 'vscode-nls';
import * as vscode from 'vscode';
import * as os from 'os';
import * as path from 'path';
import { DataTierApplicationWizard } from '../dataTierApplicationWizard';
@@ -101,7 +102,7 @@ export abstract class DacFxConfigPage extends BasePage {
// Handle database changes
this.databaseDropdown.onValueChanged(async () => {
this.model.database = (<azdata.CategoryValue>this.databaseDropdown.value).name;
this.fileTextBox.value = this.generateFilePath();
this.fileTextBox.value = this.generateFilePathFromDatabaseAndTimestamp();
this.model.filePath = this.fileTextBox.value;
});
@@ -124,7 +125,7 @@ export abstract class DacFxConfigPage extends BasePage {
let values = await this.getDatabaseValues();
this.model.database = values[0].name;
this.model.filePath = this.generateFilePath();
this.model.filePath = this.generateFilePathFromDatabaseAndTimestamp();
this.fileTextBox.value = this.model.filePath;
this.databaseDropdown.updateProperties({
@@ -145,10 +146,18 @@ export abstract class DacFxConfigPage extends BasePage {
}).component();
}
protected generateFilePath(): string {
protected generateFilePathFromDatabaseAndTimestamp(): string {
return path.join(this.getRootPath(), this.model.database + '-' + this.getDateTime() + this.fileExtension);
}
protected getDateTime(): string {
let now = new Date();
let datetime = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate() + '-' + now.getHours() + '-' + now.getMinutes();
return path.join(os.homedir(), this.model.database + '-' + datetime + this.fileExtension);
return now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate() + '-' + now.getHours() + '-' + now.getMinutes();
}
protected getRootPath(): string {
// return rootpath of opened folder in file explorer if one is open, otherwise default to user home directory
return vscode.workspace.rootPath ? vscode.workspace.rootPath : os.homedir();
}
}