1// Aseprite
2// Copyright (C) 2018 David Capello
3//
4// This program is distributed under the terms of
5// the End-User License Agreement for Aseprite.
6
7#ifdef HAVE_CONFIG_H
8#include "config.h"
9#endif
10
11#ifndef ENABLE_SCRIPTING
12 #error ENABLE_SCRIPTING must be defined
13#endif
14
15#include "app/app.h"
16#include "app/commands/command.h"
17#include "app/ini_file.h"
18#include "app/launcher.h"
19#include "base/fs.h"
20#include "base/fstream_path.h"
21
22#include <fstream>
23
24namespace app {
25
26using namespace ui;
27
28class OpenScriptFolderCommand : public Command {
29public:
30 OpenScriptFolderCommand();
31protected:
32 void onExecute(Context* context);
33};
34
35OpenScriptFolderCommand::OpenScriptFolderCommand()
36 : Command(CommandId::OpenScriptFolder(), CmdUIOnlyFlag)
37{
38}
39
40void OpenScriptFolderCommand::onExecute(Context* context)
41{
42 std::string path = app::main_config_filename();
43 path = base::get_file_path(path);
44 path = base::join_path(path, "scripts");
45 if (!base::is_directory(path)) {
46 // Create "scripts" folder for first time
47 base::make_directory(path);
48 // Create README.txt file
49 std::ofstream os(FSTREAM_PATH(base::join_path(path, "README.txt")));
50 os << "Put your scripts here and restart Aseprite to see them in File > Scripts\n"
51 << "\n"
52 << "Scripts are .lua files, you can find more information here:\n"
53 << "\n"
54 << " https://github.com/aseprite/api\n"
55 << "\n";
56 }
57 app::launcher::open_folder(path);
58}
59
60Command* CommandFactory::createOpenScriptFolderCommand()
61{
62 return new OpenScriptFolderCommand;
63}
64
65} // namespace app
66